basic idl commands

61
Rolando V. Raqueño Monday, June 27, 202 2 1 1 Basic IDL Commands SIMG 726

Upload: belita

Post on 11-Jan-2016

56 views

Category:

Documents


0 download

DESCRIPTION

Basic IDL Commands. SIMG 726. Objective. Quick Tour of IDL Writing IDL Programs. Before we start. % source ~rvrpci/.simg726.rc % typescript % set history=100 AT THE END OF THE UNIX SESSION, DON’T FORGET TO TYPE % ^D. Before we END. AT THE END OF THE UNIX SESSION, DON’T FORGET TO TYPE - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202311

Basic IDL Commands

SIMG 726

Page 2: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202322

Objective

• Quick Tour of IDL

• Writing IDL Programs

Page 3: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202333

Before we start

% source ~rvrpci/.simg726.rc

% typescript% set history=100

AT THE END OF THE UNIX SESSION,DON’T FORGET TO TYPE

% ^D

Page 4: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202344

Before we END

AT THE END OF THE UNIX SESSION,DON’T FORGET TO TYPE

% ^D

You now have file called typescript which contains a log of your UNIX session

Page 5: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202355

Starting IDL in UNIX

• To start command line interface IDL environment% idl

• To start graphical interface IDL environment% idlde

Page 6: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202366

IDL Help

• MOST IMPORTANT IDL COMMAND OF ALL

IDL> ?

Page 7: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202377

IDL Help Window

Page 8: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202388

Other IDL Help Facilities

IDL> doc_library,’moment’

• Allows specially formatted code comments to be viewed without having to view the source code

Page 9: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 202399

General IDL Information

• N.B. Platform specific limitation – UNIX

• File name conflict between lower and upper case characters

– e.g. addnum.pro vs. AddNum.pro

• Recommend use of strictly lowercase file names

Page 10: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231010

IDL Character Set• IDL is not case sensitive• Commands and arguments are delimited by

comas.– e.g. IDL> print, a

• Comments are started by a semicolon (;)– e.g. IDL> ; This is a comment

• Command options are set using a backslash (/)– e.g. IDL> tv, a, /order

Page 11: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231111

Other IDL Characters

• System variables are started with an exclamation point (!)e.g. IDL> print, !PIe.g. IDL> y = sin( x*!DTOR )

• Command line continuation with $e.g. IDL> print, 180 / $

!PI

Page 12: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231212

Other IDL Characters

• Multiple IDL commands can be separated by the & symbol– e.g. IDL> a=0.0 & b=1.0

• UNIX Command execution– e.g. IDL> $ls -la

Page 13: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231313

Journal Facility of IDL

• The journal command allows you to record all IDL activity during a particular session

IDL> journal, ‘sequence.pro’

IDL> print, 3*5

IDL> journal

Page 14: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231414

sequence.pro

; IDL Version 3.6.1a (MacOS Macintosh); Journal File for Rolando Raqueño@green; Working directory: Raqueño's Hard Drive:Applications:ENVI:; Date: Tue Sep 17 00:56:18 1996 print,3*5

; 15

Page 15: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231515

Sample Commands

• Some sample commandIDL> print,3*5

IDL> print,SysTime()

IDL> num = 5*12

IDL> help,numNUM INT = 60

IDL> print,num60

Page 16: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231616

Creating an Array

• Some sample commandIDL> num = fltarr(40)

IDL> help,numNUM FLOAT = Array(40)

IDL> print,num 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000

0.00000 0.00000 0.00000 0.00000 0.00000

Page 17: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231717

Creating an “Indexed Array”

• Some sample commandIDL> for i=0,39 do num(i)=i

IDL> help,numNUM FLOAT = Array(40)

IDL> print,num 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000

7.00000 8.00000 9.00000 10.0000 11.0000 12.0000 13.0000

14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000

21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 27.0000

28.0000 29.0000 30.0000 31.0000 32.0000 33.0000 34.0000

35.0000 36.0000 37.0000 38.0000 39.0000

Page 18: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231818

Shortcut Creating Indexed Array

• Some sample commandIDL> num = findgen(40)

IDL> help,numNUM FLOAT = Array(40)

IDL> print,num 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000

7.00000 8.00000 9.00000 10.0000 11.0000 12.0000 13.0000

14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000

21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 27.0000

28.0000 29.0000 30.0000 31.0000 32.0000 33.0000 34.0000

35.0000 36.0000 37.0000 38.0000 39.0000

Page 19: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20231919

Indexed Array Example

• Some sample commandIDL> num = findgen(40)*10

IDL> print,num 0.00000 10.0000 20.0000 30.0000 40.0000 50.0000 60.0000

70.0000 80.0000 90.0000 100.000 110.000 120.000 130.000

140.000 150.000 160.000 170.000 180.000 190.000 200.000

210.000 220.000 230.000 240.000 250.000 260.000 270.000

280.000 290.000 300.000 310.000 320.000 330.000 340.000

350.000 360.000 370.000 380.000 390.000

Page 20: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232020

Indexed Array Example

• Some sample commandIDL> num = findgen(40)*10-195IDL> print,num

-195.000 -185.000 -175.000 -165.000 -155.000 -145.000 -135.000 -125.000 -115.000 -105.000 -95.0000 -85.0000 -75.0000 -65.0000 -55.0000 -45.0000 -35.0000 -25.0000 -15.0000 -5.00000 5.00000 15.0000 25.0000 35.0000 45.0000 55.0000 65.0000 75.0000 85.0000 95.0000 105.000 115.000 125.000 135.000 145.000 155.000 165.000 175.000 185.000 195.000

• In general you will be using a linear formy=m*x+b

Page 21: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232121

Extracting Array Subset

• Some sample commandIDL> num1 = num(0:36)

IDL> print,num1 -195.000 -185.000 -175.000 -165.000 -155.000 -145.000 -135.000

-125.000 -115.000 -105.000 -95.0000 -85.0000 -75.0000 -65.0000

-55.0000 -45.0000 -35.0000 -25.0000 -15.0000 -5.00000 5.00000

15.0000 25.0000 35.0000 45.0000 55.0000 65.0000 75.0000

85.0000 95.0000 105.000 115.000 125.000 135.000 145.000

155.000 165.000

IDL> help,num1 NUM1 FLOAT = Array(37)

Page 22: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232222

Scalar Operation on Arrays

• Some sample commandsIDL> num = findgen(37)*10

IDL> print,num0.00000 10.0000 20.0000 30.0000 40.0000 50.0000 60.0000

70.0000 80.0000 90.0000 100.000 110.000 120.000 130.000

140.000 150.000 160.000 170.000 180.000 190.000 200.000

210.000 220.000 230.000 240.000 250.000 260.000 270.000

280.000 290.000 300.000 310.000 320.000 330.000 340.000

350.000 360.000

IDL> help,num NUM FLOAT = Array(37)

Page 23: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232323

Two-Dimensional Plotting

• Displaying Two-Dimensional GraphicsIDL> line = Sin(num * !DtoR)

IDL> plot,line

Page 24: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232424

Two-Dimensional Plotting

• Displaying Two-Dimensional GraphicsIDL> plot,line IDL> plot,num,line

Page 25: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232525

Two-Dimensional Plotting Options

IDL> plot,num,line,/Psym

Page 26: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232626

Two-Dimensional Plotting Options

IDL> plot,num,line,Psym=1

Page 27: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232727

Other Plotting OptionsIDL> plot,num,line,linestyle=1

Page 28: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232828

Labeling IDL PlotsIDL> plot,num,line,xrange=[0,360],$

ytitle='Sin(x)',Title='Sine Plot'

Page 29: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20232929

Other Plot FacilitiesIDL> plotplot,num,line,xrange=[0,360],$

ytitle='Sin(x)',Title='Sine Plot'

IDL> plots,[0,360],[0,0]

Page 30: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233030

Polygon FillingIDL> loadct, 5IDL> polyfill,num(0:18),line(0:18),color=120IDL> polyfill,num(18:36),line(18:36),color=50

Page 31: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233131

Data File Inputs

• Copy the following files from ~rvrpci/pub/IDL/training

surface.dat

ctscan.dat

Page 32: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233232

Three-Dimensional Plotting• Displaying Three-Dimensional Graphics

– To get the data into IDL, you will need to open a file and read it into an array using the following commands (N.B. this is specific for this particular data set)

IDL> file=‘surface.dat’IDL> openr,lun,file,/get_lunIDL> peak=fltarr(40,40)IDL> readf,lun,peakIDL> free_lun, lun

Page 33: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233333

Surface Plots• Displaying Three-Dimensional Graphics

IDL> print, max(peak), min(peak)

IDL> surface,peak

Page 34: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233434

Surface PlotsIDL> x = findgen(40)*2.5 & y=findgen(40)+50

IDL> surface,peak,x,y

Page 35: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233535

Color Look-up Tables– The following command lets you view the

current colors loaded into the color look-up tables

IDL> cindex

Page 36: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233636

Background/Foreground Colors– The following surface command lets you

manipulate the background and foreground colors

IDL>surface,peak,background=200,color=45,title='Surface Projection',charsize=2.0

Page 37: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233737

Shaded Surface PlottingIDL> shade_surf, peak

Page 38: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233838

Draping Data Over a Surface– We can drape a given surface over another one by the

following command (we read in the data snow the same manner as peak)

IDL>shade_surf,peak,$

shade=snow

Page 39: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20233939

Surface Plot Colored by Altitude– We can generate a simple elevation color map.

IDL> shade_surf, peak, shade=bytscl(peak)

Page 40: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234040

Simple Contour Plots– We can generate a simple contour map.

IDL> contour,peak

Page 41: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234141

Contour Plots Spacing– We can generate a simple contour map and adjust spacing.

IDL> contour, peak, nlevels=10

Page 42: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234242

Contour Plots Labelling– We can generate a simple contour map and label them

IDL> contour, peak, nlevels=10, /follow

Page 43: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234343

Contour Plots Spacing Adjustment– We can generate a simple contour map and adjust spacing

along with line styles.IDL> contour, peak, nlevels=10, c_linestyle = indgen(5)

Page 44: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234444

Colored Contour Plots– We can generate a simple contour map and adjust spacing

along with line color.IDL> contour, peak, nlevels=10, c_colors = indgen(5)*20+80

Page 45: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234545

Images Data• Displaying Image Data

– You can read in image data in a manner similar to other forms of two-dimensional data. You will need to ascertain whether the data is an ASCII file or a binary file

IDL> openr, lun,’ctscan.dat’,/get_lunIDL> scan=bytarr(256,256)IDL> readu, lun, scanIDL> free_lun, lun

Page 46: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234646

Image Data• Displaying Image Data

IDL> window, /free, xsize=256, ysize=256

IDL> tvscl, scan

Page 47: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234747

Image Data• Displaying Image Data

IDL> window, /free, xsize=256, ysize=256

IDL> tvscl, scan IDL> tvscl,hist_equal(scan)

Page 48: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234848

Image Processing• Displaying Image Data

IDL> window, /free, xsize=256, ysize=256

IDL> tvscl, scan IDL> tvscl, sobel(scan)

Page 49: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20234949

XLOADCT Routine• Displaying Image Data

IDL> xloadctIDL> tvscl, scan

Page 50: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235050

Writing IDL Programs

Page 51: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235151

General Form of an IDL Program• Parts of an IDL program

pro program_name [, arg1, arg2, ..., argn]

IDL statement #1IDL statement #2

.

.

.IDL statement #n

end

Page 52: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235252

Compiling an IDL Program

• Create a program to take celsius arguments and print out fahrenheit valuespro celsius_to_fahrenheit, celsius

print, 9/5*celsius+32

end

• To compile:IDL> .compile celsius_to_fahrenheit.pro

Page 53: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235353

Executing an IDL Program

• To use the program in scalar mode:

IDL> c = 100.0

IDL> celsius_to_fahrenheit, c

• To use the program in array mode:

IDL> c = findgen(201)/2

IDL> celsius_to_fahrenheit, c

Page 54: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235454

General Form of an IDL Function• Parts of an IDL function

function program_name [, arg1, arg2, ..., argn]

IDL statement #1IDL statement #2

.

.

.IDL statement #nreturn, answer

end

Page 55: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235555

Compiling an IDL Function• Create a function to take celsius

arguments and print out fahrenheit valuesfunction celsius_to_fahrenheit, celsius

answer=9/5*celsius+32

return, answer

end

• To compile:IDL> .compile celsius_to_fahrenheit.pro

Page 56: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235656

Executing an IDL Function

• To use the program:IDL> c = findgen(201)/2IDL> f = celsius_to_fahrenheit(c)IDL> print, fIDL> plot, c, f

• Equivalently:IDL> print, celsius_to_fahrenheit(c)IDL> plot, c, celsius_to_fahrenheit(c)

Page 57: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235757

Program Designprogram file vs. function file

• Use functions in case of mathematical functions to allow composition of functions

IDL> k=celsius_to_kelvin(fahrenheit_to_celsius(f))

• Use program file in case of process not requiring the return of data

IDL> write_to_file,’temperature.dat’,k

Page 58: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235858

Parameter Passing in IDL

• IDL passes parameters into functions and programs by reference

• This means parameters can be modified through “side effect”

pro celsius_to_fahrenheit, celsius

celsius =9/5*celsius+32

end

Page 59: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20235959

Problems with “Side Effect” Parameter Passing

IDL> a=32.0

IDL> celsius_to_fahrenheit,a

% Compiled module: CELSIUS_TO_FAHRENHEIT.

IDL> print,a

64.0000

Page 60: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20236060

A Debugging Exercise

• The IDL function and program examples celsius_to_fahrenheit all compile, but generate incorrect answers in some cases.

• This is left as a debugging exercise

Page 61: Basic IDL Commands

Rolando V. Raqueño Friday, April 21, 20236161

Hints for Statistics Problem

• Study the IDL functionsn_elements()

size()

• Try to reuse as many of the functions as possible.

• Do not be concerned with efficiency at this point.