Modifying a Variable's Data
This tutorial describes a series of ways to modify the data portion of an iovar variable.
1. Whole variable arithmetic
## Simply double every value in o3
o3_tmp1 = o3 * 2
## add a value (10ppb) to every value
o3_tmp2 = o3 + .010
## Do some spot checking
o3.getValue()[12,0,33]
o3_tmp1.getValue()[12,0,33]
o3_tmp2.getValue()[12,0,33]
2. Slices and individual elements
## make a copy of the variable
o3_tmp3 = o3.IOclone()
## modify a single element
o3_tmp3[12,0,33,26] = .1
## Make another copy and
## add a constant to each time slice
o3_tmp4 = o3.IOclone()
for i in xrange(24):
o3_tmp4[i] += i
## Make a copy
## modify a subset of the rows and all the columns
## for a specific time and layer
o3_tmp5 = o3.IOclone()
o3_tmp5[12,0,30:] = o3[2,0,30:] * 2
The IOclone method makes a copy of the iovar object so that
we don't modify the original values. The method copies all the
data and metadata to the new iovar object.
3. Arithmetic with Multiple variables
## extract NO from the IOAPI fileVariable arithmetic is an easy way to create new variables. For this to work, the two variables must have the same domain. The new variable, "nox", still needs to have its metadata modified (see "Modifying a Variable's Metadata")
no = f("no")
## Create an NOx variable
nox = no + no2
| Contents | Previous | Next |