NAOJ/ADC IDL(2016 Aug)

IDL

IDL
ASIAA
1

• IDL
RSI(->ITT->Exelis Visual Information
Solutions -> Harris Geospatial Solutions)• IDLIDL–IDL• IDL–•ADC

IDL–ADCIDL

ADC2• Practical IDL programming– By L. E. Gumley (MORGAN Kaufmann–¥12641 at Amazon (¥8103–)• On-line IDL references– http://www.harrisgeospatial.com/docs/using_idl_home.html• IDL Routines or IDL Language– Linux– Google‘idlhelp’•

Harris• Coyote s Guide to IDL programming– By David Fanning– http://www.idlcoyote.com/ (– Web)tips

•

• IDL

―― (KS–3)()

3

4

IDL
• IDL
• IDL
•
–– Interactive Data Language– Data Visualization Tools

5

IDL

•
––

•– IDL• FITSjpeg• FITS table ascii table–••–•– C -> file output on disk -> gnuplot• Python+NumPy+Matplotlib

6

IDL• Procedure/Function

ascii file–or(.exe)

–••

–

•
–
•

– C.f. IRAF

file I/O(disk7

IDL vs. IRAF
• IDL
• IRAF• IDL• IRAF––• IRAF• IDL–• IRAF• IDL–(NOAO:)(RSI->ITT->Exelis…:)
8IDL vs. C ()•IDL = 100 X C–C–C*&•• Printf•

IDL = 100 X C––•

IDL = 1/10 X C– IDL–IDLC•– SDSS9IDL••10•––String•

110•– IDL– IRAF
– DS9

[0,0]
[1,1]
SKYCAT[1,1]• For loop
–0n_elements(x)-112,•, :;:$&argument•–•array index

; :––

•

: : arrayindex– Image[1:10,10:20] --x=1~10, y=10~20•

image array$ :–•& :–13[]()• [ ]: array– x[0]: x array– y[0,10]: y array– image[*,*,1]:x=0, y=10–

• ( ):(function, procedure)

argument•–Y f x•

index

IDL()

arrayx(0,10)

–•

14

&&

AND, ||

•

OR, ~

NOT

&&, ||, ~
•

– IF
•

AB

•

AND, OR, NOT–• 000 AND 111 = 000• 000 OR 111 = 111– Where
• A

•

B

where–– where&&15EQ=, GT<• EQ, GT– IF• IF A GT B then…

• =– A=B(AB• <, >– A = (B < 5)••BB310A=B=3
A=5– Index• A_cut=A[b > 0:c < (x_max-1)]–bcA arrayindex
16•string–•string– IDL> print,'0a'0a– IDL> print,"0a"print,"0a"^% Syntax error.
– IDL> print,'aa'aa– IDL> print,"aa"
aa

•
17

variable•–C–define•– Variable– A=1 -> Ainteger– A=1.0 -> Afloat
– A=fltarr(10) -> Afloat
– A= 1.0 -> Astringarray (size=10)• Variable– A=1.0•

A= 1.0Astring18

variable• A– UndefinedIF– Procedure/function• IDL–variable19•– +-*/^– alog10(), sqrt(), sin(radian)– A^2.,10^-3– 3*(1+2)=9•

->
–A
•
•

sqrt(A)
AA+BA B–•20

•–– IDL• Print,1/0• 1• % Program caused arithmetic error: Integer divide by 0
• Print,1*!values.f_nan,1*!values.f_infinity• NAN INF
• % Program caused arithmetic error: Floating illegal
operand–• Warning•–arithmetic error
21• Total• Median,mean,stddev,variance– Moment• Sin/cos• Max,Min• Finite– Argument•

Not A Number (NAN)–• Mask– 1 or 0 mask

1 or NaN mask

22• Strcmp, strtrim, strlen– IDL
file I/O–23

Array••••A=[1,2,3] --- 3
B=[[1,2,3],[1,2,3]] --- 3X2 arraya[1:2], b[0:1,1:2], c[*,2:5], d[2:*]– E=[1,2,3,4,5] & f=[0,1,2] & print,E[f]–E0• Help– IDL> help,a,a[1:2]– AINT= Array[3]– <Expression> INT= Array[2]• (A+B)[0:2]– C=A+B• AB

C[0:2]
24

Where•Index– For loop

array

IFFor x=0,99 do begin
For y=0,99 do begin
If image[x,y] LT -100 then image[x,y]=!values.f_nan
Endfor
Endfor– IDL

2

bad_index=where(image LT -100)
Image[bad_index]=!values.f_nan•
where• Where25

IDL•• Procedure/function– Fltarr, intarr, …
– Findgen, indgen, …

– Keyword_set••– Where– Size, n_elements– help– Message– .reset•– print– Plot (oplot)– (Atv <-)26

function/procedure• IDLASTRO (http://idlastro.gsfc.nasa.gov)––IDL• FITS read/write; ASCII table read/write• Others– Atv 2or ds9 for IDL.

• http://www.physics.uci.edu/~barth/atv/ by Aaron Barth•->•– Loadcolors•– Saveimage, pson (psoff)• PS/PNG/JPEG dump of plot window
•

•27

IDL
•
– IF– Case•
– For– Break, continue•– Goto•28

FOR, IFFor x=0,xmax-1 do begin
y=func(x)Endfor• or
For x=0,xmax-1 do y=func(x)If A GT B then begin
a=gunc(b)Endif• orIf A GT B then a=gunc(b)••if/for•If then begin … endif else begin … endelse

begin… end(for/if)
29

IDL
•

IDL•

30

• Idlde– IDL–(developing environment)••• Idlon––+Emacs + IDLWAVE• IDLWAVE: http://www.idlwave.org/– IDLWAVE is an add-on mode for GNU Emacs and XEmacs whichenables feature-rich development and interaction with IDL…

•– Vi–

OK.

gedit (Linux@ ADC)
31

IDL
• IDL
• .cshrc ((t)cshell:)–IDL– Source .cshrc• Terminal––•path

Idl or idldeidl••••

IDL_PATH

idl

IDL

castor:/asiaa/home/ohyama% idl
IDL Version 8.3 (linux x86_64 m64).
…
IDL>
unix
IDL

Windowgraphic–X11OK.

•• bash32

•procedure/function
idlhelp

Unix shell• http://www.harrisgeospatial.com/docs/using_idl_home.html–Using IDL -> IDL routines–indexsearch– Example– See also… ()•procedure/function–33

function;+; NAME:; MRDFITS;; PURPOSE:; Read all standard FITS data types into arrays or structures.
; CALLING SEQUENCE:;
Result = MRDFITS( Filename/FileUnit,[Exten_no/Exten_name, Header], /FPACK, STATUS=status); INPUTS:;
Filename = String containing the name of the file to be read or…
; OUTPUTS:;
Result = FITS data array or structure constructed from the designated extension…
; OPTIONAL OUTPUT:;
Header = String array containing the header from the FITS extension.
; OPTIONAL INPUT KEYWORDS:;/FSCALE - If present and non-zero then scale data to float numbers for arrays…
; OPTIONAL OUTPUT KEYWORDS:;STATUS - A integer status indicating success or failure of the request.
; EXAMPLES:;(1) Read a FITS primary array:;a = mrdfits('TEST.FITS') or;a = mrdfits('TEST.FITS', 0, header);
IDL

Calling sequence•([]:vs.

IDL)
vs(A/B: A<-B34)

IDL• No GUI• No iTOOL• No Object programming• Etc…
• GUI–GUI35

• idlIDLidlde–“IDL>”•or– IDL–1••– IDL> @mymemo.txt; @Mymemo.txt• IDL– Mymemo.txt•.proend– .run mymemo• .run

IDL36

•–•–
•

If, for––1syntax error•

if, for
IDL > .run[- for i=0,10 do begin- print,i- endfor- end[IDL
IDL > []

4]]

•–
•37

• IDL–IDL38

IDL
•
–
•–
••

•
–
•

–

ArrayIDL
•

39

•
––
••

–
•

xxx.proprocedure/function–• IDL–••^
40

Error1

•
•••
•
••
•

% Syntax error.
At: /home/ohyama/xxx.pro, Line 10% Compiled module: xxx.
% Attempt to call undefined procedure/function: xxx'.
% Execution halted at: yyy 61 /home/ohyama/yyy.pro%$MAIN$
IDL> help,/trace% At yyy 61 /home/ohyama/yyy.pro•YYY (XXX.pro•) 61
10XXXXXXsyntax error
YYY6141

Error2••••••••••% Attempt to subscript A with <LONG (-1)> is out of range.
% Execution halted at: xxx
185 /home/ohyama/xxx.pro%yyy
18 /home/ohyama/yyy.pro%zzz 61 /home/ohyama/zzz.pro%$MAIN$
IDL> help,/trace% At xxx
185 /home/ohyama/xxx.pro% yyy
18 /home/ohyama/yyy.pro% zzz
61 /home/ohyama/zzz.pro% $MAIN$•ZZZXXX-> YYY185-> XXX (42IDL•••–••••–•–43• Print• .cont–––• Message–• Help– Variable– Help,/trace• Return or return,0–• .reset
–IDL
•

IDL

• .comp––.reset44

• IDL–Window•

X11– Color•

device,decomposed=0,retain=2• Procedure/Function undefined• % Attempt to call undefined procedure/function: xxx'.

–• IDL path
– Print,!path– unix shellpath
IDL_PATHIDL•– .comp xxx.pro•typo (xxx.proxxy.pro)• Variable undefined• Variable is undefined: xxx.

–array• Array–orvariable

help

or typo45• Subscript out of range–array– % Attempt to subscript xxx with <LONG (-1)> is out of range.
– % Subscript range values of the form low:high must be >= 0, < size, withlow <= high:•• Wherefor loop
-1

– Subscript– Wherehelp
Match count• Function/procedure– % xxx: Incorrect number of arguments.
–
y=func(x,a)
2argument–typofunc(x,a,b)

346

•

size=1– Id– Id–array
A

Array[id]array[id]BCCA•–arrayA•BCC–A, Bhelp• IF,where– AND–
• String–a• Print&&, ORIF_a||helpa_( _Help47• Singed/unsigned Integer/long integer
IDL> help,32767S<Expression> INT = 32767 (<= 2^15-1)
IDL> help,32767S+1S<Expression> INT = -32768 (<= 2^15-1) bit•integer– *2*2.0• Function/procedure– Argument

undefined•– Argument

•

help

procedure/function•–– IDL_PATH– findpro(IDLASTRO)(unixwhere)

48

IDL

•
–
• IDL–• FORIF–

IDL built-in•– Array•

WhereArray– For loop
– A[0,0]->A[1,0]; A[0,1]•–array••array– A=0–49

QL
• IDL

Interactive Data
Quick Look

• Help• Print• Print,moment• Plot (oplot)• ATV50QL•–• HELP:IDL

help– Variable
dimension,undefined• Print:– […] ()

array

• Print,moment():–51

QL• Plot,Oplot:– Plot,xarray,yarray,xrange=[x1,x2],yrange=[y1,y2],/xlog,/yog,psym=3,color=1– Oplot,xarray,yarray2,psym=4,color=2–
plot
Plot,yarray–[…]• Plot,image[*,0] ->x• ATV:– Atv,image2d,/block•GUI• /block–[…]• image[*,*,0] -> z=052

••– Function• Output=function(argument,/keyword)– Procedure• Procedure,input_arg,output_arg,/keyword

•
–––53

•
• Variable–variable–•–––

keyword• Stacked_image=mystack(image,/median)• Stacked_image=mystack(image,/clip_sigma,sigma=3.)• Mystack.proIF
keyword54

Argumentkeyword• Argument, keyword–––

argument
Ctype•

stringfloat array

float array•

IDL• Keyword– /keyword– Keyword•

1 or 0 true or false
keyword=1– Undefined

Keyword_set

undefinedsize

keyword
55

•
• Pro

I/O (argument)functionend–• Function

returnPro myprocedure,input,output
Output=myfunction(input)
End
Function myfunction,input
Output=somefunction(input)
Return,output
End•(*.pro)––•.pro56

• IDL_Path–

IDL
path

• .compile– .compile•IDL intrinsic57

•

local–global• IDL––• IDL•– Local58

1
Variable
subscript

array subscript out-of-range•– Error message

or help,/trace•– QL–variable•–• .cont(continue)

–••
•

59

2for loop

subject out-of-range•– Error message

or help,/trace

•
– QL

•
•

variable

Edit and save.
– Return (procedure) or return,0 (function)•– .compile program

•
–

••

60

2IDL
• IDL
• 2IDLFITS61••(idlastro•••••••)

Meanclip.pro
Biweight_mean.pro
Resistant_mean.pro
Robust_sigma.pro
Robust_poly_fit.pro…

IDLfunction)

procedure/–– IDL
procedure/function– IDLASTRO
google62•–¼–Hα [NII][NII]/Hα[NII]

1:3•– IDL built-in

MPFIT library• http://www.physics.wisc.edu/~craigm/idl/fitting.html
•IDL–

•IDL
function ((x_obs[*], y_obs[*])MPFIT librarydelta_a, delta_b–

MPFIT

y=ax+b)(a0, b0)a, b,63

•••

FITS
FITS

FITS–

FITS

IDL––100••r, br-b

100r-bifwhere••

name, RA, DEC, b_mag, r_mag–IDL••–mycat[0].name=‘NGC0000’ & mycat[0].ra=123.456 … mycat[n-1].r_mag=0.0
mycat
Nn•

name, RA, DEC.

b_r_color=mycat.b_mag – mycat.r_mag & print,b_r_color[0]

•64

•65

•
–
•–– IDL•–––•• Array66

• IDL––IRAF•

SplotIDL

• IDL
––––

plot
interpolation/fitting
Catalog• where•– ADC––

ADC

67