Interactive Data Language (IDL)
Interactive Data Language (IDL). This PPT includes some materials downloaded from Internet, please don’t circulate it out of the LAB. What is IDL?. Interactive Data Language (IDL) is a programming language that is a popular data analysis language among scientists.
Interactive Data Language (IDL)
E N D
Presentation Transcript
Interactive Data Language (IDL) This PPT includes some materials downloaded from Internet, please don’t circulate it out of the LAB
What is IDL? Interactive Data Language (IDL) is a programming language that is a popular data analysis language among scientists. IDL is the trusted scientific programming language used across disciplines to create meaningful visualizations out of complex numerical data (ITT). • 1970 – IDL’s predecessor, Laboratory for Atmospheric and Space Physics, CO • Used by • NASA • Lockheed-Martin • Medical Imaging Fields • Remote sensing
What is IDL??? A More Powerful MATLAB, also more expensive. A great tool for hyperspectral imaging! A fast tool for processing large images!! A great GREAT tool for ENVI programming!!!
Overview of IDL • A high-level interpreted programming language with vector and array primitives • Modern programming language • Flow control • Data structures • Objects • All operators and most functions work on scalar, vector or array data of any data type. • Data visualization tool, advanced built-in graphics • 2-D plots • Contour plots • Surface plots • Shaded surfaces • Gray scale/color images • Volume rendering, … • Multi-platform support • Unix: Sun, Hewlett Packard, Silicon Graphics, IBM • Linux, Microsoft Windows, Mac
How to Learn • Online Help • Google • http://www.idlcoyote.com/ • Practice & Practice
Basic Variable Types • Integers - 1 byte – byte data type (0..256) IDL> a=bindgen(1) - 2 bytes – integers data type (0..2562-1) IDL> b=indgen(1) & print,5/3 1 - 4 bytes – long integers (0..2564-1) IDL> c=lindgen(1) - 8 bytes – 64-bit long integers (0..2568-1) • Floating data types - 4 bytes – floats (exponent from-38 to 38) IDL>print,5./3. & y=float(3)/float(2) 1.66667 IDL> a=1.23456789 IDL> print,a,format=‘(f20.10)’ - 8 bytes – double-precision IDL> print,5d/3d 1.6666667 IDL> a=1.23456789d0 & print,a,format=‘(f20.10)’ IDL> xyouts,xloc,yloc,string(a,format=‘f(20.10)’) • Strings (Text) IDL>x=‘Hi there!!!’
Assignment Statements A = B + 1 • A has the same structure as B, with a data type equal to that of the most precise operand in the expression on the right hand side. In this case it could be any type except string. • If B is a vector or array then 1 is added to each element. A = 0 ; A is a 16 bit integer A = A * 0.5 ; A is now a 32 bit float B = A(*,3) ; B is equal to the 4th row of A A(*,3) = 0 ; Set all elements in 4th row of A equal to 0 • Examples: image = fltarr(512, 512) ; zero filled array b = image(0:127, 0:127) ; b is 128x128 array image(*,100) = findgen(512) ; replace row 100 plot, image(*,100) ; plot row 121 ; Display the power spectrum as an image tvscl, alog(abs(fft(image, 1)))
Naming Variables • Assign ‘readable’ variable names that make sense • Variable names must start with a letter - NO: 6a=“gamma” OK: a6=“gamma” • Variable names may not have spaces in them - NO: A 6=5 OK: A_6=5 • Some characters are illegal or have special meanings - NO: a@=5, a.b=5 (used for structures), A+=5, A#=5
Organizational structures • Scalars IDL> x=3. • Vectors IDL> a=[0,1,2,3] & print,a[1] 1 • Arrays (see IDL help for matrices) (index from zero) intarr(), fltarr(), dblarr(), strarr().indgen() IDL> q=intarr(2,2) 0 0 0 0 IDL> m=indgen(2,2) 0 1 2 3 IDL> print,m(0,1) 2 IDL> a=findgen(100,100) IDL> print,a[1,0] 1.00000 IDL> b=a[23:25,67:69] IDL> indx=where(a gt 10.) IDL> jndx=where(a[indx] le 100.) IDL> b=a[indx[ jndx]]
Array operations • Simple math operations (* by scalar, +, -); A 3-column by 2-row array: IDL> A = [ [0, 1, 2],[3, 4, 5] ,[5,6,7]] IDL>B=2*A 0 2 4 IDL>print, B 6 8 10 10 12 14 • More complex math • #, Multiply an array by another IDL> C=A#B • N_elements: Total number of elements in array IDL> n=n_elements(A) • Total(array): computes a sum of all elements • Min(array): outputs the min value; also Max • Minmax(array): outputs the min then max • Rebin: Resize array IDL> C=Rebin(A,6,6) • Eigenvec: finds eigenvectors
Basic Programming • IF-THEN BLOCK • IF (logical-statement) THEN something • IF (logical-statement) THEN BEGIN • Something • Other thing • ENDIF • IF (logical-statement) THEN BEGIN • Something • Other thing • ENDIF ELSE some-other-thing
Basic Programming • CASE • CASE name OF • Match_1: do-something • Match_2: do-other thing • ELSE: do-things not-matched • ENDCASE
Basic Programming • DO-loop • FOR n=0, number DO a[n] = fix(n) • FOR n=0, number DO BEGIN • a[n] = fix(n) • B[n] = 2.0*a[n]^2 + 4.0*a[n] + 6.0 $ • + 8.0*a[n]^(-2.5) • ENDFOR • NOTE: $ is for continuation.
Files and Input/Output Write data to a file, formatted OPENW, 1, ‘original.dat’ OPENW, 2, ‘noisy.dat’ PRINTF, 1, original PRINTF, 2, noisy CLOSE, 1 CLOSE, 2
Plot and Processing • Making a New Dataset noisy = ((RANDOMU(SEED, 200) - .5) / 2) original = SIN((FINDGEN(200)/35)^2.5) • Plot PLOT, noisy • Plot them together PLOT, original, THICK = 3, XTITLE = "Time", YTITLE ="Amplitude“ OPLOT, original+noisy
IDL Examples IDL> a = sin(findgen(100)/99. * 2 * !pi) IDL> help, a IDL> plot, a IDL> a = shift(alog(abs(fft(dist(256),1))),128,128) IDL> isurface, a