IDL笔记

 

一、参考

1、IDL Reference

Coyote's Guide to IDL Programming

https://www.harrisgeospatial.com/docs/routines-1.html

https://ips.ucsd.edu/help/smei/SMEI_list.html (Fortran)
https://ips.ucsd.edu/help/ssw/SSW_list.html (IDL)

https://www.cnblogs.com/alex-bn-lee/category/725300.html?page=1

IDL控制语句:https://blog.csdn.net/weixin_43955546/article/details/105661962

2、Formatting IDL Graphics Symbols and Lines

https://www.harrisgeospatial.com/docs/formattingsymsandlines.html#Color

clip=[0,255]:最暗到最亮 loadct: 0~31  cgloadct: 0~40  /brewer:颜色内外相反 /reverse, /brewer的情况下,cgloadct: 0~31

plot和oplot绘图是,用16进位颜色顺序是'蓝绿红',color='0000ff'xL(red);color='0050ff'xL(orange);color='00ffff'xL(yellow);color='00ff00'xL(green);color='00ff00'xL(blue);color='ffff00'xL(cyan);color='ff00ff'xL(pink)……当然,可以用数字或字母使得颜色亮度逐渐增加,比如:'0000ff'xL为全红最亮,'000099'xL为红色较暗,'000050'xL为红色更暗,'0000ff'xL为全黑了;'505050'xL到'707070'xL到'909090'xL则为灰色越来越亮;'004050'xL到'007000'xL到'009000'xL则为深绿越来越亮。

FORTRAN-Style Format Codes

https://www.l3harrisgeospatial.com/docs/format_codes_fortran.html

fortran格式代码的语法如下:
[n] C[+][-][width]
n:格式的重复数(n≥1)。若不指定n,则为1。
C:格式代码。
+:可选,指定输出的正数应该带有“+”前缀。“+”标志仅对数字格式代码有效。通常,只有负数输出带有符号前缀。非十进制数字代码(B、O和Z)允许“+”标志,但忽略它。
-:可选,指定字符串或数字值在输出时应左对齐。通常,输出是右对齐的。
width:宽度规范(可选)。宽度规范和默认值是特定于格式代码的。

3、PLOT
https://www.harrisgeospatial.com/docs/PLOT_Procedure.html

Over-plot data points with accompanying X or Y error bars.
oploterror, [ x,] y, [xerr], yerr, [ /NOHAT, HATLENGTH= , ERRTHICK =, ERRSTYLE=, ERRCOLOR =, /LOBAR, /HIBAR, NSKIP = , NSUM = , /ADDCMD, ... OPLOT keywords ]
https://www.l3harrisgeospatial.com/docs/oploterror.html

4、PLOTHIST
https://www.harrisgeospatial.com/docs/plothist.html

5、cgContour

http://www.idlcoyote.com/idldoc/cg/cgcontour.html

6、WHERE

Result = WHERE( Array_Expression [, Count] [, COMPLEMENT=variable] [, /L64] [, NCOMPLEMENT=variable] )

这里Count为符合条件的数量;COMPLEMENT为不符合条件的脚码;NCOMPLEMENT为不符合条件的数量;/L64在默认条件下返回的是32位整数,加了/L64则返回64位整数。

可以简写,比如简写为:result=where(array, c, com=a, ncom=b),或简写为:result=where(array, c, co=a, nc=b)

https://www.l3harrisgeospatial.com/docs/WHERE.html

https://northstar-www.dartmouth.edu/doc/idl/html_6.2/WHERE.html

7、REBIN——重新调整数组或向量的尺寸,注意:调整后的维数必须为原数组维数的整数倍

Result = REBIN( Array, D1 [, ..., D8] [, /SAMPLE] )

IDL> a=[1.,2.,3.,4.]
IDL> b=rebin(a,12)
IDL> print,b
1.00000 1.33333 1.66667 2.00000 2.33333 2.66667
3.00000 3.33333 3.66667 4.00000 4.00000 4.00000
IDL> b=rebin(a,8)
IDL> print,b
1.00000 1.50000 2.00000 2.50000 3.00000 3.50000
4.00000 4.00000
IDL> c=rebin(b,4)
IDL> print,c
1.25000 2.25000 3.25000 4.00000

https://northstar-www.dartmouth.edu/doc/idl/html_6.2/REBIN.html

8、LINTERP——从一个网格线性插值一维数据到一个新的网格。LINTERP的结果在数值上与IDL内禀结果是等价的!

LINTERP, Xtab, Ytab, Xint, Yint, [MISSING =, /NoInterp ]

IDL>y1=fltarr(10)
IDL>x=[0,1.45,2.37,3.56,4.28,5.10,6.89,7.31,8.55,9.61]
IDL>y=x^2
IDL>x1=findgen(10)
IDL>linterp,x,y,x1,y1
IDL>print,x1,y1
0.00000 1.00000 2.00000 3.00000 4.00000 5.00000
6.00000 7.00000 8.00000 9.00000
0.00000 1.45000 4.20350 9.35280 16.1232 25.0720
36.8010 49.0341 64.3795 81.2745

https://www.l3harrisgeospatial.com/docs/linterp.html

9、波长数组和取log后的对应数组

λ1、λ2、λ3、……、λn (波长间隔为1Å)

y1、y2、y3、……、yn (对应的取log后的值)

y2 = y1+lgλ2-lgλ1

y3 = y2+lgλ3-lgλ2 = y1+lgλ2-lgλ1+lgλ3-lgλ2=y1+lgλ3-lgλ1

y4 = y3+lgλ4-lgλ3 = y1+lgλ3-lgλ1+lgλ4-lgλ3=y1+lgλ4-lgλ1

…………

yn =y1+lgλn-lgλ1

例如λ从3400Å到8500Å,求其取log后对应的波长

wave = alog10(3400) + dindgen(4001) * (alog10(8500) - alog10(3400))/4d3

flux = dindgen(4001) * 0.

10、添加lts_fits的几个PRO:

http://www-astro.physics.ox.ac.uk/~mxc/software/#lts

https://pypi.org/project/ltsfit/

解压后文件夹放在/usr/local/idl71/lib/lts_fits,然后在IDL_PATH中添加lts_fits路径目录,IDL_PATH=/usr/local/idl71/lib:/usr/local/idl71/lib/astro/pro:/usr/local/idl71/lib/lts_fits

然后IDL> print, file_which('lts_linefit.pro')就找到了lts_linefit.pro所在的路径:

/usr/local/idl71/lib/lts_fits/lts_linefit.pro

简单地:IDL>which('lts_linefit.pro')即可

CALLING SEQUENCE:
lts_linefit, x, y, sigx, sigy, par, sig_par, chi_sq, PLOT=plot, RMS=rms, BAD=bad, /BAYES, CLIP=clip, EPSY=epsy, FRAC=frac, GOOD=good, OVERPLOT=overplot, PIVOT=pivot, TEXT=text

"LTS_LINEFIT program described in Cappellari et al. (2013, MNRAS, 432, 1709), which combines the Least Trimmed Squares robust technique of Rousseeuw & van Driessen (2006) into a least-squares fitting algorithm which allows for errors in both variables and intrinsic scatter."

11、计算光度距离——lumdist(z),单位:Mpc

result = lumdist(z, [H0 = 70 , k = 0, Omega_M = 0.3, Lambda0 = 0.7, q0 = -0.55, /SILENT])

方括号中为默认值,如果lumdist(z),则其它参数默认为上面的值 ,光度距离结果以Mpc为单位。
http://www.harrisgeospatial.com/docs/lumdist.html

https://idlastro.gsfc.nasa.gov/ftp/pro/astro/lumdist.pro

如:计算SDSS目标光度

L = Flux·4πD2 = F×10-17 erg/cm2/s ×4π×(lumdist(z)×106×3.26×365×24×3600×3×1010)2 cm2

= F×10-17 erg/cm2/s ×4π×(lumdist(z)×3.086×1024)2 cm2 =···erg/s = ···×10-7 J/s = ···W/(3.828×1026 W) = ···L⊙

其中:L⊙ = 3.828×1026 W

12、半峰全宽(FWHM,Full Width at Half Maximum)

FWHM≈2.3548σ

参考:https://mathworld.wolfram.com/GaussianFunction.html

 

13、等值宽度(Equivalent Width,EW)

等值宽度,即与吸收(或发射)谱线轮廓和连续谱之间所包围的面积相当的高度为1的矩形的宽度。

参考:https://astronomy.swin.edu.au/cosmos/E/Equivalent+Width

14、关于赤道坐标系转换

(1)RADEC——To convert RA and Dec from decimal to sexagesimal units.
radec, ra, dec, ihr, imin, xsec, ideg, imn, xsc, [/HOURS}
ra - Right ascension, scalar or vector, in DEGREES unless the /HOURS keyword is set
dec - declination in decimal DEGREES, scalar or vector, same number of elements as RA
/HOURS - if set, then the input righ ascension should be specified in hours instead of degrees.
https://www.l3harrisgeospatial.com/docs/radec.html


(2) JPRECESS——Precess astronomical coordinates from B1950 to J2000
jprecess, ra, dec, ra_2000, dec_2000, [ MU_RADEC = , PARALLAX = RAD_VEL =, EPOCH = ]
Example:
RA(1950) = 13h 39m 44.526s Dec(1950) = 8d 38' 28.63'' Mu(RA) = -.0259 s/yr Mu(Dec) = -.093 ''/yr
IDL> mu_radec = 100D* [ -15D*.0259, -0.093 ]
IDL> ra = ten(13,39,44.526)*15.D
IDL> dec = ten(8,38,28.63)
IDL> jprecess, ra, dec, ra2000, dec2000, mu_radec = mu_radec
IDL> print, adstring(ra2000, dec2000,2)
===> 13h 42m 12.740s +08d 23' 17.69"
https://www.l3harrisgeospatial.com/docs/jprecess.html

15、K-correction

If you want to convert apparent magnitudes in band R to absolute magnitudes in band Q, you need to calculate the K-correction, which is defined by the equation:
mR = MQ + DM(z) + KQR(z),
where mR is the apparent magnitude, MQ is the absolute magnitude, DM(z) is the distance modulus, accounting for the angular diameter distance and cosmological surface-brightness dimming, and KQR(z) is the K-correction. By absolute magnitude we mean: the apparent magnitude in band Q the object would have if it were observed at rest, 10 pc away, using an aperture that contains its total flux. The distance modulus accounts for the difference between an object's actual distance and 10 pc. The K-correction accounts for the fact that you observed a redshifted galaxy in band R but the absolute magnitude requires a rest-frame observation in band Q. Obviously the difference between the fluxes observed in different bandpasses is fully determined by the galaxy SED and the description of the bandpasses.

https://arxiv.org/pdf/astro-ph/0210394.pdf

http://kcorrect.org/

二、拟合

1、linfit线性拟合(适应于只有X、Y,但没有误差值的两组数据):

; 有一对n个元素的向量:
X = [-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, 2.95, 2.18, 3.72, 5.26]
Y = [-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, -0.78, -2.61, 0.31, 1.74]
; 定义其中一个向量的泊松测量误差为:
measure_errors = SQRT(ABS(Y))
; 计算模型参数A和B,并输出结果为:
result = LINFIT(X, Y, MEASURE_ERRORS=error, sigma=sig, yfit=yfit, chisq=chi2, prob=prob)
PRINT, result
IDL prints:
-3.16574    0.829856

IDL> print, sig
0.282226   0.0991508

y = (a±σa) + (b±σb)x = (res[0]±sig[0]) + (res[1]±sig[1])x

https://www.harrisgeospatial.com/docs/LINFIT.html

2、fitexy线性拟合(适应于包含x、y的误差 的数据):

Linear Least-squares approximation in one-dimension (y = a + b*x), when both x and y data have errors
FITEXY, x, y, A, B, X_SIG=xerr, Y_SIG=yerr, [sigma_A_B, chi_sq, q, TOL=]

为了避免X和Y由于数量级差别太大带来的问题,通常需要对不同数量级的数据进行归一化处理后再进行拟合。(参考Press和Teukolsky的"Numerical Recipes"一书中的"Numerical Recipes"一栏)
归一化过程如下:
xx = (x - xm) / xs, sigx = x_sigma / xs,式中:xm = mean(x), xs = stddev(x)
yy = (y - ym) / ys, sigy = y_sigma / ys,式中:ym = mean(y), ys = stddev(y)

https://www.l3harrisgeospatial.com/docs/fitexy.html

3、ladfit最小绝对偏差拟合:

; 有一对n个元素的向量:
X = [-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, 2.95, 2.18, 3.72, 5.26]
Y = [-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, -0.78, -2.61, 0.31, 1.74]
; 将X值进行升序排序,并对Y值也进行升序排序以匹配X中元素的新顺序:
XX = X[SORT(X)]
YY = Y[SORT(X)]
; 计算模型参数A和B:
PRINT, LADFIT(XX, YY)

IDL prints:
-3.15301    0.930440

https://www.harrisgeospatial.com/docs/LADFIT.html

4、poly_fit线性拟合:

; Define an 11-element vector of independent variable data:
X = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
; Define an 11-element vector of dependent variable data:
Y = [0.25, 0.16, 0.09, 0.04, 0.01, 0.00, 0.01, 0.04, 0.09, 0.16, 0.25]
; Define a vector of measurement errors:
measure_errors = REPLICATE(0.01, 11)
; Compute the second degree polynomial fit to the data:
result = POLY_FIT(X, Y, 2, MEASURE_ERRORS=measure_errors, $
SIGMA=sigma)
; Print the coefficients:
PRINT, 'Coefficients: ', result
PRINT, 'Standard errors: ', sigma

IDL prints:
Coefficients: 0.250000 -1.00000 1.00000
Standard errors: 0.00761853 0.0354459 0.0341395

https://www.harrisgeospatial.com/docs/POLY_FIT.html

 

5、高斯拟合:

(1)Gauss1——计算给出x值、平均值(中心值μ)、σ、面积的高斯曲线y值

形式:yvals = gauss1(xvals, [mean, sigma, area], skew=skew)

举例:

p = [2.2D, 1.4D, 3000.D]
x = dindgen(200)*0.1 - 10.
y = gauss1(x, p)

计算等间距(间距为0.1)情况下高斯函数的值。高斯函数的中心值为2.2,标准差为1.4,总面积为3000。

http://www.harrisgeospatial.com/docs/gauss1.html
(2)Gauss1p——计算给出x值、平均值(中心值μ)、σ、面积的高斯曲线y值

形式:gauss1, xvals, [mean, sigma, area], yvals, skew=skew

举例:

p = [2.2D, 1.4D, 3000.D]
x = dindgen(200)*0.1 - 10.
gauss1p, x, p, y

http://www.harrisgeospatial.com/docs/gauss1p.html

(3)mpfitfun——对IDL函数执行Levenberg-Marquardt最小二乘拟合
形式:parms = mpfitfun(myfunct, x, y, err, start_params, ...)
用户自定义函数应按如下方式:
function myfunct, x, p
; The independent variable is x
; Parameter values are passed in "p"
ymod = ... computed model values at X ...
return, ymod
END
举例:
; First, generate some synthetic data
npts = 200
x = dindgen(npts) * 0.1 - 10. ; Independent variable
yi = gauss1(x, [2.2D, 1.4, 3000.]) ; "Ideal" Y variable
y = yi + randomn(seed, npts) * sqrt(1000. + yi); Measured, w/ noise
sy = sqrt(1000.D + y) ; Poisson errors
; Now fit a Gaussian to see how well we can recover
p0 = [1.D, 1., 1000.] ; Initial guess (cent, width, area)
p = mpfitfun('GAUSS1', x, y, sy, p0) ; Fit a function
print, p
生成具有高斯峰和泊松统计不确定度的数据集合,然后将相同的函数拟合到数据(具有不同的初始参数),以视得到的数据接近程度。

http://www.harrisgeospatial.com/docs/mpfitfun.html

https://pages.physics.wisc.edu/~craigm/idl/mpfittut.html#download

http://www.eg.bucknell.edu/physics/ASTR201/IDLTutorial/tutorial_05.html

附:结构体http://www.weixueyuan.net/a/93.html


、鼠标:

; Activate the graphics cursor, select a point in the graphics window, and return the position of the cursor in device coordinates.:
Enter:

CURSOR, X, Y, /DEVICE
Move the cursor over the graphics window and press the mouse button. The position of the cursor in device coordinates is stored in the variables X and Y. To label the location, enter:

XYOUTS, X, Y, 'X marks the spot.', /DEVICE
The following two programs demonstrate simple applications of the interactive graphics cursor and the CURSOR procedure.

http://www.harrisgeospatial.com/docs/CURSOR_Procedure.html
http://blog.sina.com.cn/s/blog_4df4d7440100jcvj.html


四、IDL环境下对文件和文件夹的操作

切换到上一层目录:
cd, '../'

查看工作目录:
IDL> cd,current = workdir
IDL> print,workdir
返回值:/mnt/f/works/

创建新文件夹:
https://www.harrisgeospatial.com/docs/FILE_MKDIR.html
file_mkdir, 'aaa' 或file_mkdir, '/mnt/f/works/sfr/new/bbb'

复制文件夹:
https://www.harrisgeospatial.com/docs/FILE_COPY.html

复制文件夹需要设置关键字:/RECURSIVE
IDL> file_copy, '/mnt/f/works/sfr/bbb', '/mnt/f/works/bbb', /RECURSIVE

复制文件:
IDL> file_copy, '/mnt/f/works/sfr/data2.txt', '/mnt/f/works/'

剪切移动文件:
https://www.harrisgeospatial.com/docs/FILE_MOVE.html
file_move, file_name, file_newpath 如:file_move, '/mnt/f/works/sfr/new/bbb', '/mnt/f/works/sfr/bbb'

删除文件
https://www.harrisgeospatial.com/docs/FILE_MOVE.html
IDL> file_delete, '/mnt/f/works/data1.txt'
删除文件夹
IDL> file_delete,'/mnt/f/works/aaa', /RECURSIVE
不设置RECURSIVE关键字,IDL拒绝删除非空文件夹,设置之后就可以删除

文件是否存在:
https://www.harrisgeospatial.com/docs/FILE_TEST.html
IDL> file_test('/mnt/f/works/data1.txt')
返回1说明存在
IDL> file_test('/mnt/f/works/data2.txt')
返回0说明不存在

文件夹是否存在:
IDL> file_test('/mnt/f/works/aaa')
返回1说明存在
IDL> file_test('/mnt/f/works/bbb')
返回0说明不存在

查找文件或文件夹:
https://www.harrisgeospatial.com/docs/FILE_SEARCH.html
file_search()会返回相关的文件和文件夹
1. 在mnt/f/works/中查找有data字段的文件:
IDL> file_search('/mnt/f/works/','*data*')
2. 在mnt/f/works/中查找“data”字段:
IDL> file_search('/mnt/f/works/','*data*')

若IDL> print, file_search('*'),则输出当前目录下所有文件名。
3. 查找路径下所有pro文件,np为查找到的pro文件的总数
IDL> path = '/mnt/f/works/sfr/'
IDL> files = file_search(path,'*.pro',count=np)
IDL> print,np
例如返回值:16

 

五、特殊符号:

TEXTOIDL()函数
利用showtex可以看到各个字符对应的输入
使用:
mu=textoidl('\mu',font=0)
xyouts, x, y, 'wavelength ('+mu+'m)', font=0
*注意一定要加上font关键字,否则会出现乱码或其他字符

波长“埃”符号:
xyouts, x, y, string(byte(197))
xyouts, x, y, string("305B)

太阳符号:
thisletter = "156B
sunsymbol = '!9' + string(thisletter) + '!X'
xyouts, x, y, sunsymbol

Unicode 13.0 Character Code Charts:http://www.unicode.org/charts/

!Z() 解码命令可以将括号内的十六进制数转换为对应的符号,目前发现只支持到Unicode的0080

、GANDALF: Gas AND Absorption Line Fitting

Code site: http://ascl.net/1708.012 --> https://www.star.herts.ac.uk/~sarzi/PaperV_nutshell/PaperV_nutshell.html
Ionised Gas in Early-type Galaxies with SAURON

Spectral Measurements

http://ifs.wikidot.com/da-specmeas

 

七、Ubuntu下安装deb包

在Ubuntu下安装deb包需要使用dpkg命令

Dpkg 的普通用法:
1、sudo dpkg -i <package.deb>
安装一个 Debian 软件包,比如你手动下载的文件。

2、sudo dpkg -c <package.deb>
列出 <package.deb> 的内容。

3、sudo dpkg -I <package.deb>
从 <package.deb> 中提取安装包信息。

4、sudo dpkg -r <package>
移除一个已安装的安装包。

5、sudo dpkg -P <package>
完全清除一个已安装的安装包。和 remove 不同的是,remove 只是删掉数据和可执行文件,purge 另外还删除所有的配制文件。

6、sudo dpkg -L <package>
列出 <package> 安装的所有文件清单。同时请看 dpkg -c 来检查一个 .deb 文件的内容。

7、sudo dpkg -s <package>
显示已安装安装包的信息。同时请看 apt-cache 显示 Debian 存档中的安装包信息,以及 dpkg -I 来显示从一个 .deb 文件中提取的安装包信息。

8、sudo dpkg-reconfigure <package>
重新配制一个已经安装的安装包,如果它使用的是 debconf (debconf 为安装包安装提供了一个统一的配制界面)。

如果安装过程中出现问题,可以先使用命令:sudo apt-get update
更新后再执行上面的命令。

 八Ubuntu系统中安装Java环境

步骤1:下载jdk
我选择的jdk版本文件:jdk-19_linux-x64_bin.tar.gz
https://www.oracle.com/java/technologies/
https://www.oracle.com/java/technologies/java-se-glance.html
https://www.oracle.com/java/technologies/downloads/#java19

步骤2:将下载的文件复制到/usr/local/
sudo cp .../jdk-19_linux-x64_bin.tar.gz /usr/local/
也可以建立专门的文件夹,比如/usr/local/java
那就将下载的文件复制到java目录下,当然后面的环境目录都要作相应的修改
sudo cp .../jdk-19_linux-x64_bin.tar.gz /usr/local/java

步骤3:在/usr/local/下解压缩文件
sudo tar -zxvf jdk-19_linux-x64_bin.tar.gz

步骤4:配置环境变量
sudo vi /etc/environment

souPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:$JAVA_HOME/bin"
export CLASSPATH=.:$JAVA_HOME/lib
export JAVA_HOME=/usr/local/jdk-19.0.1

注意JAVA_HOME是JDK的目录,也就是那个我们新建的路径。

保存并关闭后,使用命令 source /etc/environment 使环境变量立刻生效。

步骤5:配置所有用户的环境变量
为了预防重启后,配置的环境变量无效,配置所有用户的环境变量

sudo vi /etc/profile
在文件的最后添加以下内容:

#set Java environment

export JAVA_HOME=/usr/local/jdk-19.0.1
export CLASSPATH=.:$JAVA_HOME/bin:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH

执行 source /etc/profile 是全局设置立刻生效

步骤6:重启检验
执行命令 sudo shutdown -r now 后,输入密码重启,Ctrl+Alt+t打开命令框,输入 java -version看结果。

重启没设置成功,再次执行 source /etc/profile 是全局设置立刻生效

设置好java环境后,打开topcat命令:java -jar topcat-full.jar

参考链接:https://blog.csdn.net/qq_36288669/article/details/120346999

                    https://zhuanlan.zhihu.com/p/492149414

 



Jan. 6, 2020