IDL 语言在天文学中的应用 王凤飞 中科院国家天文台

28
IDL 语语语语语语语语语语 语语语 语语语语语语语语 nese Virtual Observatory

description

Chinese Virtual Observatory. IDL 语言在天文学中的应用 王凤飞 中科院国家天文台. IDL 语言的特点,优势,局限性 IDL 语言与其他开发语言的比较 IDL 在天文学中的应用 IDL 的图像处理举例. IDL 语言的特点. IDL ( Interactive Data Language )是进行 数据分析 、 可视化表达 与 跨平台 应用开发的理想工具。可用于 数值计算、三维图形建模、科学数据读取等。 IDL 用户涵盖 NASA 、 ESA 、 NOAA 、 Siemens 、 GEMedical 等 - PowerPoint PPT Presentation

Transcript of IDL 语言在天文学中的应用 王凤飞 中科院国家天文台

Page 1: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

IDL 语言在天文学中的应用

王凤飞 中科院国家天文台

Chinese Virtual Observatory

Page 2: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 2

• IDL 语言的特点,优势,局限性• IDL 语言与其他开发语言的比较• IDL在天文学中的应用• IDL的图像处理举例

Page 3: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 3

IDL 语言的特点• IDL( Interactive Data Language)是进行数据分析、可视化表达与跨平台应用开发的理想工具。可用于数值计算、三维图形建模、科学数据读取等。• IDL用户涵盖 NASA、 ESA、 NOAA、 Siemens、GEMedical等

• 科学家利用 IDL对“勇气号”和“机遇号”的数据进行数据分析和图像处理。 • SDSS一维、二维光谱处理软件也是 IDL编写的。

Page 4: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 4

IDL 语言的特点• 1 、 IDL= VC  菜单的定制、消息的传递、类的定义与继承• 2 、 IDL= VB  可视化界面的设计、语言的通俗易懂、编程的入门 • 3 、 IDL= JAVA 从跨平台的移植来说• 4 、 IDL= FORTRAN  从函数、子程序的调用、数据传递、语言风格、语言组织等来说• 5 、 IDL= MATLAB  提供了大量封装和参数化了的数学函数• 6 、 IDL= OPENGL   IDL的提供了丰富的二维、三维图形图像类   此外,应用 IDL可以快速的开发出功能强大的三维图形图像处理软件和三维 GIS应用系统。

Page 5: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 5

IDL 语言的特点• 擅长于处理矢量或数组数据 有大量的 IDL 命令用于创建不同数据类型的矢量和数组。特别是,有许多创建各类数据类型的数组的函数,该数组的每个元素的初始值为零,而且还有许多创建各类数据类型的数组的函数,该数组的每个元素的初始值为其在数组中的索引位置。• 动态改变变量的属性 IDL 最强大的功能之一是大多数过程或函数都能在任何数据类型或组织结构上生效。这是因为 IDL 在运行时能改变变量的数据类型和组织结构(像世界上其他强大的事物一样,这种动态改变变量的属性的能力也有潜在的巨大危险!必须小心,确信知道正在使用哪种数据)。

Page 6: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 6

天文中为什么使用 IDL ?• 节省时间,把更多的时间用在科学研究上 -- 采用 IDL 我们在三年项目进展中减少了超过一年的工作量。 —— Paul Scowen NASA 哈勃望远镜修正小组成员 • 分享你的工作成果 -- 和使用 IDL 的你的同行分享代码 .• 功能强大的天文库 --IDL Astronomy Users Library

Page 7: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 7

IDL 语言的局限性• 它是一个商业软件。 ( IRAF, CIAO, AIPS++ is free !)• IDL 更像一个解释器,而不是一个编译器。 大型的 idl 程序在运行时比编译好的 C 、 FORTRAN程序慢一些。• 一次性处理数据 500M 以下效果好。 批处理大量数据时 C、 FORTRAN 可能效果更好。• 有些仪器的数据处理包无法使用: (e.g. CCD mosaic imagery, multi-object

spectrographs, echelle spectra, etc.).

Page 8: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 8

IDL 与其他语言的比较• FORTRAN,C,or C++ 不能满足交互式的数据分析要求(没有标准的交互环境)• IRAF, STSDAS, CIAO, and AIPS 是交互性的,但需要预编译;不方便改进和定制; 难以维护• SUPERMONGO, PGPLOT 画图 IDL 集成了编程计算、数据操作和显示。

Page 9: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 9

IDL 与其他语言的比较• Mathematica, Matlab, Maple 强大的数学计算能力 + 可视化 ; 支持数学符号运算和方程求解 ;

• IDL 交互式地查看结果,有更强大的图像处理能力,更灵活的文件 I/O (天文: Fits )

Page 10: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 10

Matlab vs. IDL

• IDL 程序有四种形式: 批处理文件、子程序、函数、主程序。 IDL 的函数可以有多个输入,但只能有一个输出。输入参数的值在函数中可以改变。子程序不返回值。• Matlab 程序可以是 M-scripe file 或者是一个函数。 Matlab 函数可以有多个输入和输出。

Page 11: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 11

IDL 在天文学中的应用• 早期由 Goddard Space Flight Center 编写的 IDL 包,用于哈勃望远镜的 GHRS和 STIS项目的二维光谱的分析

Page 12: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 12

获取 IDL 天文包和学习 IDL• IDL Astronomy User's Library• http://idlastro.gsfc.nasa.gov/homepage.html• http://idlastro.gsfc.nasa.gov/ftp/astron.tar.gz• FITS http://idlastro.gsfc.nasa.gov/fitsio.html• Solar Software• http://lmsal.com/solarsoft/sswdoc/index_menu.html• ftp://sohoftp.nascom.nasa.gov/solarsoft/offline/swmaint/tar/• ssw_ssw_gen.tar.Z• Coyote’s Guide to IDL Programming• http://www.dfanning.com• ftp://ftp.dfanning.com/pub/dfanning/outgoing/coyote2nd/ • IDL Newsgroup (comp.lang.idl-pvwave)• http://groups.google.com/group/comp.lang.idl-pvwave• Markwardt IDL Library (Fitting)• http://cow.physics.wisc.edu/~craigm/idl/idl.html• JHUAPL IDL Library• http://fermi.jhuapl.edu/s1r/idl/s1rlib/local_idl.html• IDL + EMACS http://www.idlwave.org/• http://idlwave.org/download/idlwave-help.tar.bz2

Page 13: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 13

NASA Astronomy Library (http://idlastro.gsfc.nasa.gov/homepage.html)

• best way to read FITS data• Hundreds of useful, and well-tested routines for

math, statistics, and astronomical utilities• Should already be on your path• The Astronomy Links page is the source of IDL

software used for astronomy

Page 14: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 14

Contents of the IDL Astronomy Users Library

Astronomical Utilities DAOPHOT-Type Photometry Procedures Database Procedures Disk I/O (MIDAS, IRAF files) FITS Astrometry and Calibration STSDAS Image manipulation FITS ASCII & Binary Table I/O FITS Binary Table Extensions I/O FITS I/O Image Manipulation Math and Statistics Plotting Procedures Robust Statistics Procedures IDL Structure procedures STSDAS (Binary) Table I/O Web Socket Procedures TV Display Procedures Miscellaneous (Non-Astronomy) Procedures

Page 15: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 15

Astronomy utilities • The subdirectory astro includes about 80

mostly self-contained astronomy utilities. A_b Compute B band interstellar extinction according to the RC2.

ADSTRING Return RA and Dec as character string(s) in sexigesimal format.

AIRTOVAC Convert air wavelengths to vacuum wavelengths

AITOFF Convert longitude, latitude to X,Y using an AITOFF projection.

AITOFF_GRID Produce an overlay of latitude and longitude lines over a plot or image

ARCBAR Draw an arc bar on an image showing the astronomical plate scale

ARROWS To display "weathervane" directional arrows on an astronomical image

ASTDISP Print astronomical and pixel coordinates in a standard format

ASTRO Interactive utility for precession and coordinate conversion.

Page 16: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 16

FITS I/O in the IDL Astronomy Library

• MRDFITS()/MWRFITS :read any type of FITS ; Mapping an entire FITS table can incur extra CPU and virtual memory overhead ( SDSS )

• READFITS()/WRITEFITS :read Unix and bzip2 compressed files; cannot be used to read variable length binary tables

• FX* Procedures :most complete and well-tested ;do not handle ASCII tables; use more loops,so slower.

• FITS_* and FTAB_* Procedures :most efficient ;only to recognize the STScI Inheritance and Implicit Image Conventions; FITS files cannot be read from a Unix pipe or an internet socket.

Page 17: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 17

Disk IO (IRAF, MIDAS, and WFPC2 data)

• IDL procedures to read popular disk formats in astronomy :

1. IRAF image (.imh) files (read and write) 2. MIDAS ( .BDF and .TBL ) image and table files (read and

update) 3. WFPC2 images (FITS or STSDAS)

几个子程序:MID_RD_IMAGE ... image (.BDF) read, MID_UP_IMAGE ... image (.BDF) update, MID_RD_TABLE ... table (.TBL) read, MID_UP_TABLE ... table (.TBL) update.

Page 18: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 18

Plotting Procedures

• The procedures in this directory are useful additions to the intrinsic IDL plotting capabilities. CLEANPLOT Reset all plotting system variables to their default (X) values

LEGEND Create an annotation legend for a plot LEGENDTEST Demo program demonstrating the capabilities of LEGEND LINEID_PLOT Annotate the identified lines in a spectrum MULTIPLOT Create multiple plots with shared axes OPLOTERROR Overplot Y vs. X with optional X and Y error bars PLOTERROR Plot Y vs. X with optional X and Y error bars PLOTHIST Plot the histogram of an array PLOTSYM Define useful plotting symbols not in the standard PSYM definition PARTVELVEC Plot the velocity vectors of a set of particles RDPLOT Like intrinsic CURSOR procedure but with a full-screen cursor SUNSYMBOL() Return the character string to plot a subscripted Sun symbol VSYM Create "Mongo"-like rotationally symmetric polygon plotting symbols

Page 19: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 19

Math and Statistics• This directory contains IDL mathematics and

statistics procedures thought to be of interest in astronomy. Fifteen of the procedures, are adapted from algorithms in "Numerical Recipes 2nd Edition"

• PCA Perform a principal component analysis (Karhunen-Loeve expansion)

• GAUSSIAN() Evaluate a 1-d Gaussian and optionally its derivative

Page 20: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 20

IDL 的图像处理举例 • 创建曲面图• 在 IDL 程序中,任何二维的数组都可以用 Surface命令生成一个曲面图• 创建阴影曲面图同样很简单:• IDL>Shade_Surf, peak

Page 21: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 21

消除图像噪声 -Median

• Median 命令计算相邻像素的中间值 ,而不是平均值。这就有两个重要作用。第一,它能删除图像中的极端值。第二,它不使那些尺寸比邻域范围大的图像边缘或特征变模糊。

•IDL>TV, Median(noisy, 3), 340, 0

Page 22: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 22

直方图均衡化 - Histogram Equalization

• 正常图像具有狭窄的像素值分布。这里的像素值集中在 50-10之间

• 一幅直方图均衡化后的图像。象素分布扩展到了整个颜色范围

Page 23: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 23

平滑图像 Smooth 、 Convol• 通过将每个像素值与它周围相邻像素值进行平均来平滑图像。• 用称为卷积的过程来平滑图像。这种技术中,一个方形滤波核和图像一起参与卷积计算。例如,可以创建如下的一个核心:• 1 2 1 • 2 8 2 • 1 2 1

• 图像平滑被应用在一种称作晕光蒙片的图像处理技术中。• 通过 Convol 命令用上述滤波核对图像进行卷积处理,键入:• IDL>kernel=[[1,2,1], [2,8,2], [1,2,1]]• IDL>TV, image, 0, 0• IDL>TV, Smooth(image, 3, /Edge_Truncate), 192, 0• IDL>TV, Convol(image, kernel, Total(kernel), $• /Edge_Truncate), 2*192, 0

Page 24: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 24

增强图像边缘 -Roberts和 Sobel ,拉普拉斯算子 • 一幅图像可以通过锐化或微分来增强图像边缘。 IDL提供了两个做好的边缘增强函数: Roberts和 Sobel 。还有一些其他方法也可用来增强图像边缘。例如,可以用拉普拉斯算子来对图像做卷积:• 1 1 1• 1 -7 1• 1 1 1

IDL>TV, Sobel(image), 0IDL>TV, Roberts(image), 1IDL>kernel=[[1,1,1], [1,-7,1], [1,1,1]]IDL>TV, Convol(image, kernel), 2

三种增强图像边缘的方式。左边用的是 Sobel方法。中间用的是 Roberts方法。右边是用拉普拉斯算子对图像做卷积 .

Page 25: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 25

FFT: removing corrugated effect

Page 26: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 26

IDL 的成就• 目前应用 IDL 语言,已经开发出了

ENVI、 IMAGIS、 RiverTools 、医学等成熟产品。具体的应用实例也非常多,如在 2000年澳大利亚悉尼奥运会综合预报系统、美国国家环境卫星数据和信息服务中心的厄尔尼诺现象分析等工作中得到了成功的应用。• 天文中 NASA, SDSS 。。。

Page 27: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 27

LAMOST光谱数据

预处理模块

红移测量和分类模块

谱线测量模块恒星物理参数测量模块

构造模板模块

数据获取模块

测量结果存储模块

图2-4 LAMOST光谱自动测量软件模块表述图

SDSS光谱数据处理系统模块( IDL)

Page 28: IDL 语言在天文学中的应用 王凤飞   中科院国家天文台

11.20-11.21,2007China-VO, Guangzhou 28

Thanks for your attention!