|
Extract,
average and plot the data.
We
will be
working with the NetCDF file that can be found in CDAT
distribution and contains the data for surface air temperature:
'ts_da.nc' . ('>>>' means we are in the
python or CDAT interpreter mode).
Getting and
plotting data is extremally easy in CDAT, here are the 6 steps you need
to plot the data:
-
Import required modules:
-
vcs - needed for
visualization and ploting,
-
cdms - to access
gridded data,
-
cdutil - misc.
routines to manipulate variables
-
os - for operating
system utilities
-
sys - for
system interpreter utilities
>>>import vcs, cdms,
cdutil, os, sys
-
Get
the path to the file (use 'os' and 'sys' modules).
>>>path = os.path.join(sys.prefix,
'sample_data/ts_da.nc')
-
Open
the file (use 'cdms' module)
>>>file
= cdms.open( path
)
-
Extract 3D surface
temperature data, named 'ts'
>>>data
= file('ts')
- Initialize VCS for plotting (use
modul 'vcs')
>>>v
= vcs.init()
- Plot the data usingthe default
boxfil graphics method:
>>>v.plot(
data )
Here is the
resulting plot (by default the time dimension is the first time step of
the data):

Now
let's select
specific time step, and average over the longitude axis
resulting in a zonal mean (we will use module 'cdutil' to perform the
average):
>>>dl=cdutil.averager(data(time=7665,
squeeze=1),
axis='x')
Let's
name our new variable and give it the ID of 't_z':
>>>dl.id =
't_z'
We need to clear canvas before
plotting, otherwise we would be plotting on top of the previous plot
>>>v.clear()
And
finally, let's plot our new, derived data:
>>>v.plot(
dl )
Here
is our final, zonal mean plot:

You
can
learn more about the derived variables and plotting in CDMS
in the CDMS
getting-started tutorials.
|