Making friends with IDL interactive data language interactive

  • Slides: 13
Download presentation
Making friends with IDL = interactive data language interactive environment immediate access to all

Making friends with IDL = interactive data language interactive environment immediate access to all variables excellent for visualizing, analyzing, editing, and displaying numerical data sets optimized array operations versatile built-in plotting and graphics routines data structures possible interface with C and Fortran routines on line help (? ) IDL LIMITATIONS: IDL is an interpreted rather than a compiled language. This means that large IDL programs can execute less rapidly than equivalent compiled programs written in FORTRAN or C. IDL is a proprietary system (need licence)

Making friends with IDL create variables > name = ‘Maxwell’ > z = 1.

Making friends with IDL create variables > name = ‘Maxwell’ > z = 1. 0 e-8 > testdata = fltarr(512, 512) > a = [1, 2, 3] > a = [a, 4] creates a string creates a scalar creates a 512 x 512 2 -D array with zero entries creates a vector expands a vector Warning: If you redefine a variables during your work, you lose the previous values Avoid operation with different variables types. For example using float and integer these could be different > print, 3. 456 * 1.

Variables Variable names can have letters, numbers and underscores in them. They are NOT

Variables Variable names can have letters, numbers and underscores in them. They are NOT case-sensitive: aaa, Aaa and AAA are all the same variable. IDL> a=[3, 5, 6, 2. 5, 100, 27. 7] IDL> a= [[ 2, 3, 4], [10, 20, 30]] IDL> a=float(b) IDL> a=fltarr(n_elements(b), 4, 2) One dimension array of 6 elements = Array[6] Array index START FROM 0!!!! Array of 2 rows and 3 columns = Array[3, 2]

Array manipulations > a = [1, 2, 3] > b = [4, 5] >

Array manipulations > a = [1, 2, 3] > b = [4, 5] > print, a#b > print, b#a > print, a##b > print, a*b > print, a+1 > print, b*2 > print, a+b Warning!!! (a b c)# (g h) = (ag+dh bg+ch cg+fh) (d e f) (i j) (ai+dj bi+ej ci+fj) (k l) (cg+fh ci+fj ck+fl) (a b c)## (g h) = (ag+bi+ck ah+bj+cl) (d e f) (i j) (dg+ei+fk dh+ej+fl) (k l) INVERT - Computes the inverse of a square array. MAX - Returns the value of the largest element of Array. MEDIAN - Returns the median value of Array or applies a median filter. MEAN – Return the mean value (also first element of MOMENT). MIN - Returns the value of the smallest element of an array. MOMENT – compute the first 4 moments (mean, variance…) REFORM - Changes array dimensions without changing the total number of elements. REVERSE- Reverses the order of one dimension of an array. SIZE- Returns array size and type information. TOTAL - Sums of the elements of an array. TRANSPOSE - Transposes an array. WHERE- Returns subscripts of nonzero array elements. Try to avoid loops t=0 for i=0, n_elements(a)-1 do t=t+a(i) t=total(a)

looking for help ? name print help Open a help on line windows and

looking for help ? name print help Open a help on line windows and search for ‘name’ print, max(a); print, min(a); print, max(a); print, mean(a); print, variance(a); print, median(a); print, moment(a): print various statistical properties of image array. (moment prints first four moments. ) l help, variable : print variable informations. l help, A, /str : print structure info l help, /rou : prints list for all compiled procedures. Lists procedure and functions separately. l help, /sy : prints current values of all "system variables", which are special variables known to all routines. Names of these begin with a "!", e. g. !dir, !path, etc. l help, /rec : prints contents of command recall buffer in reverse order l help, /dev : prints parameter settings for current graphics device l help, /mem : lists current memory usage

Saving data (and time!) Safety idea: save your data!!! Be prepared: 99% of time

Saving data (and time!) Safety idea: save your data!!! Be prepared: 99% of time you will have to redo plots. Usual sequence: 1) Make plot 2) Save data (and exit from idl) 3) Meeting 4) Restore data 5) Redo plot make a routine! It will help also have your code saved in a routines. save > save, variable 1, variable 2, variable 3, filename=‘~elisa/idl/data. sav’ Keyword: ALL => save all common block, system variable and local variable from the current IDL session. > save, /all, filename=‘datatemp. sav’’ restore Ø restore, filename=‘~elisa/idl/data. sav’ > restore, filename=‘datatmp. sav’

IDL routines (. pro) As you type, each line is interpreted and immediately executed

IDL routines (. pro) As you type, each line is interpreted and immediately executed OR main routine for (loop), if, case. . pro file requirement How to call it . . . end >. r filename without . procedures or subroutines parameters and keywords optional and can be in any order functions pro NAME, VARIABLES. . . end > name, variables NAME, input 1, input 2. . . output 1, output 2. . . keyword 1=value 1, $ keyword 2=value 2, /Keyword 3. . function NAME, VARIABLES. . . return, VALUE end > a = name (variables) One of the best ways to learn how to write and use IDL programs is to look the existing IDL programs

Program execution (and other) Values of keywords are usually determined by assignment statements: PROCEDURE_NAME,

Program execution (and other) Values of keywords are usually determined by assignment statements: PROCEDURE_NAME, parm 1, parm 2. . . KEYWORD 1=100. , KEYWORD 2='dumbo', . . . in the case of switches, keywords can be set to a value of 1 by using the following syntax: NAME, parm 1, parm 2. . . /KEYWORD 1, . . . all IDL procedures/functions are assumed to be in files with the explicit extension '. pro'. Run from IDL prompt >. r or . run [name] compiles the IDL procedure(s) or function(s) in the file [name]. pro. If this is a main program, also executes it. WARNING!!!! IDL will locate the first file with this name in the IDL path or current directory Inside a file. pro @file_name stop ; comment > retall Compile the file_name. pro Useful if the file mane is different from the procedure name for debugging!!. . . print. . . plot. . . to continue >. c or. con Don’t forget the comments!!! Comments begin with ‘; ’ if you wont to come back to the first level

Structures A structure can be thought of as a user-defined data type or groups

Structures A structure can be thought of as a user-defined data type or groups of different data IDL allows you to put lots of variables into a single ‘structure’ For example satellite data can be load as a structure containing: Instrument name, data and time, pixels radiances, coordinates and observing angles of the pixels A structure (e. g. dsat) is an ensamble of other, Define a structure: previously defined, variables (and structures) dsat={aod 550: aot, $ stdaod 550: sigma, $ n: num, $ latc: latitude, $ lonc: longitude} > help, dsat, /str AOD 550 STDAOD 550 N LATC LONC DOUBLE LONG DOUBLE ; mean AOD ; standard deviation ; number of points ; central lat of the boxes ; central longitude of the boxes Array[720, 360] Array[720] To access the variables of a structure Use: mone_str. nome_var > print, dsat. aod 550(good) Routine that read satellite data usually load a structure for any image/orbit keep related variables together pass/return a lot of variables with only one name

Basic plots x=findgen(10) IDL> print, x 0. 000 1. 000 2. 000 3. 000

Basic plots x=findgen(10) IDL> print, x 0. 000 1. 000 2. 000 3. 000 4. 000 5. 000 6. 000 7. 000 8. 000 9. 000 x 2=2*!PI/100*findgen(100) IDL> plot, sin(x 2) window, 0, xsize=300, ysize=200 seed=1 l n=32 x=randomu(seed, n) y 2=randomu(seed, n) plot, x, y, psym=1, title='Random XY Points' oplot, x, y 2, psym=2, colour=2

Others useful things cut of data where Logical operator good = where (time eq

Others useful things cut of data where Logical operator good = where (time eq 1000. , count) if (count eq 1 ) then begin. . . and ; and. . . or ; or gt ; greater than (similarly lt) ge ; gt or equal to (similarly le) eq ; equal to ne ; not equal to If (count gt 1) then begin plot, x(good), y(good) endif print on postscript. ps file save a window like. jpg a = tvrd(true=3) write_jpeg, 'namefile. jpg', a, true=3 set_plot, 'ps' device, filename='filename. ps‘ … close, /device set_plot, 'x' plotting commands Smaller file, good to make presentations and movies, NOT good for reports and papers !!! ‘comp_map_'+sat 1+'_vsall. jpg’ png?

routines at AOPP ASK!!! /home/crun/eodg/idl/ Linear fit when both x and y have errors

routines at AOPP ASK!!! /home/crun/eodg/idl/ Linear fit when both x and y have errors (y = A + B x) fitexy, px, py, A, B, X_SIG=X_SIG, Y_SIG=Y_SIG Plots data points, with defined latitudes and longitudes mappoints, data, lat, lon, centre=[0, 0], /nogrey, nlevels=100 Interpolate data (with the associated lat, lon) onto a regular lat lon grid, and plot the imagepoints, data, lat, lon Using the same some fast regridding code (RAL) avgrid, lat, lon, aod Load txt file in columns loadxyz Set colour bar colour_ps tvdata + several routine to load different type of data ncol=4 nrow=4 !P. MULTI= [0, ncol, nrow, 0, 0] mappoints, dayav. AOD 550, lat, lon, centre=[0, 0], /nogrey, $ Nlevels=100, range=range, symsize=0. 6, $ title='AOD all daset average '+strcompress(i+1)+' March 2006'