Modifying a Variable's Metadata
This tutorial describes how to modify the metadata of an iovar object.
1. Changing the time axis
Let say you wanted to change the dates of your variable so that you could use the same data in a simulation over a different time period:
## Make a clone of the variable
o3_tmp1 = o3.IOclone()
## Get first date in cdtime format for comparison
o3_tmp1.getTime().asComponentTime()[0]
##
1996-6-24 6:0:0.0
##
## Change the date range to
## 1999-08-01 8:00 - 1999-08-02 7:00
o3_tmp1.IOchangeDate("1999-08-01 8:00")
## Get new first date in cdtime format
o3_tmp1.getTime().asComponentTime()[0]
##
1999-8-1 8:0:0.0
##
2. Modifying general iovar metadata
Here, we want to convert o3 from ppm to ppb:
## Convert data values from ppm -> ppb
o3_tmp2 = o3 * 1000.
## Show that the metadata hasn't changed:
o3_tmp2.units
##
'ppmV '
##
## Change metadata
o3_tmp2.IOmodVar(vunits="ppb",desc="Variable O3 -- in ppb")
## Print out IOAPI metadata
print o3_tmp2.ioM
##
iometa object:
gridName: M_12_IL
...
nvars: 1
variable name list: ['O3']
variable unit list: ['ppb']
variable desc list: ['Variable O3 -- in ppb']
...
##
The IOmodVar method helps change the ioavar's name, units,
and/or long name/ variable description. These metadata attributes
exist in multiple places in the variable, so I recommend that you use
the predefined method rather than modifying the attributes
directly. If you do want to change another metadata
attribute, double check that your final IOAPI or CF netCDF file has
recorded the metadata correctly.
A simple example of directly modifying the metadata is the grid
name. This name is used in the GRIDDESC file in a CMAQ run to
differentiate spatial domains and projections:
## Change grid name
o3_tmp2.ioM.gridName = "M_12_test"
| Contents | Previous | Next |