Mars Data Analysis Using IDL GG7101 Lecture 2 - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Mars Data Analysis Using IDL GG7101 Lecture 2

Description:

Write the commands to assign a value to a variable and display it on the screen ... ceil: Rounds up. round: Rounds to the nearest ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 40
Provided by: fscotta
Category:
Tags: idl | analysis | ceil | data | gg7101 | lecture | mars | using

less

Transcript and Presenter's Notes

Title: Mars Data Analysis Using IDL GG7101 Lecture 2


1
Mars Data Analysis Using IDLGG710-1Lecture 2
  • F. Scott Anderson
  • Office POST 526B
  • Phone 956-6887
  • Email anderson_at_higp.hawaii.edu

2
Today
  • Questions from last time
  • Help Can use ctrl-H (keyboard shortcuts)
  • .compile and .run synonymous
  • Quiz
  • Review of last week
  • Variables
  • Arrays
  • Operators
  • Structures
  • Final Project
  • Review of today's class

3
Quiz From 8/25 notes (5 min)
  • Name a method to obtain help in IDL
  • Write the commands to assign a value to a
    variable and display it on the screen
  • Does capitalization matter for IDL commands
    (print versus Print)?
  • Name 2 strengths of IDL
  • Why use structured programming?

4
Review
  • Overview of the class
  • What, why, grading, syllabus, accounts
  • Strengths of IDL
  • IDLDE versus Unix interface
  • Starting IDL, examples, and help
  • Runtime scripts versus compiled programs
  • Structured programming

5
Special Characters
  • Comments are denoted by a semicolon
  • pro test
  • shello world
  • Print the variable s
  • print, s
  • end
  • To continue a command on the next line
  • pro test
  • shello world
  • t Surfing Rocks
  • print, s,
  • t
  • end

6
Variables
  • Variables are
  • a symbol (like x or y) that is used in
    mathematical or logical expressions to represent
    a variable quantity
  • They can be created at any time in IDL
  • They are NOT case sensitive
  • They can hold different types of information
  • Strings my_varThe quick brown fox
  • Numbers my_var3434557.23423
  • The type can be redefined at any time
  • Distinct from a constant
  • x3 x is a variable, 3 is a constant

7
Numeric Variable Data Types
8
Numeric Variable Data Types
  • Byte data can represent a number (0-255) or a
    single ASCII character, depending on how it is
    printed
  • xbyte("aAbB")
  • print, x
  • print, string(97B, 65B, 98B, 66B)
  • Note type conversion and array - will come back
    to this later!

9
ASCII Character Codes
10
Numeric Variable Data Types
  • Integers are whole numbers
  • The range of an integer is 2n, n is the of bits
  • Can be signed or unsigned
  • Example 00 0 01 1 10 2 11 3
  • 2 bits range of 4
  • 3rd bit could be used to indicate sign, or
    increase range

11
Numeric Variable Data Types
  • Floats/Doubles are used to represent fractions
  • Use entirely different method to record a number
  • For a floating point number (32 bits)
  • 6 bits used to record the exponent
  • Range for float 1038
  • e.g. 25 bits 32, 26 bits 64
  • 25 bits used for the mantissa
  • 225 3.3 M, or 6 significant figures
  • 1 bit for sign
  • Floats guarantee 6.7 significant digits
  • Doubles guarantee 13.2 significant digits
  • All additional digits may be noise!
  • Leads to "Round-off Error"

12
String Variable Data Types
  • String variables hold text
  • Structures hold a group of other variables
  • Others will be discussed later
  • Help command/variable window can monitor variable
    types
  • help, x

13
Type Conversion
  • Default type for an integer is int
  • x3 gt 16 bit int
  • Default type for fractional number is float
  • x3.1415 gt 32 bit float
  • In an expression, type follows precedence type
    from Table 2.1

14
In Precedence Order
15
Precedence Example
  • To manually convert (and guarantee type) use type
    conversion operators
  • Can write a constant to indicate type
  • 190B
  • 1.0D
  • Use the function to convert

16
Type Conversion Examples
  • Example
  • ydouble(6.02e23)
  • x(3.1415y)7 gt double
  • y6.02D23
  • x(3.1415y)7 gt double
  • x34UL7 gt unsigned long
  • Quiz
  • x3/4 ?

17
What About Down Conversion?
  • If converting against precedence, data will be
    truncated (lost)
  • print, long(4.72) 4
  • To control the conversion of float to int
  • floor Rounds down
  • ceil Rounds up
  • round Rounds to the nearest
  • Conversion of text to numbers will provide any
    leading values
  • Conversion of numbers to text provides the
    numbers as a string

18
Wait! What about Variables!
  • Variables can be off any data type
  • Must begin with a letter
  • 128 characters or less
  • Case ignored
  • OK a-z, 0-9, _
  • Cannot use names already used by IDL
  • Reserved words
  • Existing IDL functions
  • User created functions

19
Reserved Words
20
IDL/User Functions
  • Use the help command to determine a conflict
  • ? intarr
  • Use .compile command to test for an existing user
    function
  • Most variables names you create will be OK
  • Especially if you use _ or numbers
  • x_max or myintarr27

21
Array Variable
  • Any variable can also hold an array of values
  • What is an array?
  • Group of equally spaced items in rows and columns
  • A list of numbers is an array
  • Often called a vector (IDL does not distinguish)
  • An image is a two dimensional array
  • An array can be up to 8 dimensions
  • Can even have an array with a single value
  • Each dimension has a direction

22
Array Directionality
Array C 5,7
1,0
0,0
2,0
3,0
4,0
Array A7 or A7,1
0,1
1,1
2,1
3,1
4,1
0,2
1,2
2,2
3,2
4,2
Array B1,7
  • IDL column major
  • Position indices start at 0
  • Trailing array dimensions of 1 can be dropped
  • To get value in yellow square of Array C
  • xc3,4

4,6
23
Array Creation
  • Horizontal vector array
  • y0,1,2,3,4 gt INT Array5
  • Vertical vector array
  • x0,1,2,3,4 gt INT Array1,5
  • xtranspose(y) gt INT Array1,5
  • Matrix
  • x0,1,2,3,4,0,1,2,3,4 gt INT Array5,2
  • xy,y gt INT Array5,2

24
Array Creation Functions
25
More Array Creation Functions
  • xreplicate(3.3, 3, 2)
  • x 3.3, 3.3, 3.3
  • 3.3, 3.3, 3.3
  • xmake_array(3,2,/byte)
  • x 0,0,0
  • 0,0,0
  • bytarr(3,2)
  • make_array(3,2,/byte,/index) bindgen(3,2)
  • make_array(3,2,/byte,/index, value5)

26
Array Creation Examples
  • xintarr(5) gt x0,0,0,0,0
  • xindgen(5) gt x0,1,2,3,4
  • xfltarr(3,2) gt x 0.0,0.0,0.0
  • 0.0,0.0,0.0
  • xfindgen(3,2) gt x 0.0,1.0,2.0
  • 3.0,4.0,5.0
  • xindgen(3)10 gt x 0,10,20

27
Array Indexing
  • 0 lt array index lt elements
  • index cannot be fractional
  • arrayindex1, index2, index3
  • zfindgen(3,3)
  • print, z1,2 gt 7.0
  • arrayval1val2, val3val4
  • print, z01, 12
  • 3.0, 4.0
  • 6.0, 7.0

28
Array Indexing
  • Can refer to all elements with
  • xfltarr(4) 0.0, 0.0, 0.0, 0.0
  • x1.0 1.0, 1.0, 1.0, 1.0
  • x1 1.0, 1.0, 1.0, 1.0
  • xfltarr(4,2)
  • x,12.0 0.0, 0.0, 0.0, 0.0
  • 2.0, 2.0, 2.0, 2.0
  • print, x,0 0.0, 0.0, 0.0, 0.0
  • print, x0, 0.0
  • 2.0

29
Array Indexing
  • Can use variables as index
  • p3
  • print, xp,1 gt 2.0
  • Can use arrays as indices
  • x 2, 7, 4
  • yindgen(10)5
  • print, yx gt 10 35 20
  • If array indices out of range will clip to min or
    max
  • x1000, -1
  • print, yx gt 45 0

30
Array Indexing
  • Rarely used form of indexing for applying an
    operation and then indexing
  • (array expression) index
  • n5
  • xindgen(n)
  • index0,2,4
  • print, (x10)index gt 0 20 40
  • Efficient way to apply multiple indexes in a
    single statement
  • Example on page 33-34 of book

31
Operators in IDL
  • Many mathematical operators in IDL
  • Follow typical rules for precedence in operations
  • 5 10/5 7 not 3!
  • (510)/5 3 not 7!
  • 5102/5 25
  • What are the rules of precedence?

32
Operators Precedence
33
Operator Notes
  • Addition subtraction operate on arrays normally
  • Operations on arrays of different sizes results
    in an array with the smallest dimension from each
    array
  • Normal mathematical array multiplication uses
  • Inverse of an array is NOT calculated using
    division (like in MATLAB)

34
Min, max, mod operators
  • Min and max operators
  • print, 4lt5, 5lt5, 6lt5
  • 4 5 5
  • arr 3,4,5
  • print, arr gt 4
  • 4 4 5
  • mod operator gives remainder
  • print, 9 mod 5 gt 4

35
Relational Operators
  • Typically used for true false testing in
    conditional statements
  • if
  • while
  • Can be used in commands however
  • a10
  • b20
  • ca gt b c 0
  • da lt b d 1

36
Boolean Operators
  • AND, OR, NOT
  • Typically used in conditional statements
  • Especially NOT Will come back to this later
  • Can be used at the command line
  • xfindgen(5) 0.5
  • print, ((x gt 2) and (x lt 3))
  • 0 0 1 0 0
  • print, ((x lt 2) or (x gt 3))
  • 1 0 1 1
  • Little used XOR operator little used, see 49
  • Byte masking also little used, see book 51-52

37
Ternary Operator
  • A short hand for conditional if statement
  • if x is lt y then
  • z a
  • else
  • zb
  • Written
  • z(x lt y) ? a b
  • More on conditional statements shortly!

38
Final Project
  • Class Discussion of Ideas

39
Today
  • Questions from last time
  • Help Can use ctrl-H (keyboard shortcuts)
  • .compile and .run synonymous
  • Quiz
  • Review of last week
  • Variables
  • Operators
  • Arrays
  • Pointers
  • Structures
  • Final Project
  • Review of this class
Write a Comment
User Comments (0)
About PowerShow.com