Wednesday, June 2, 2004

cdms quick tutorial

> cdat This starts the CDAT shell, identical to the Python shell.
> import cdms Imports the CDMS module.
> f=cdms.open('wind_comps.nc') Opens the NetCDF file and assigns the file object to variable 'f'.
> f.listvariables() Shows the variable names in the file.
['u', 'v']
> u_wind=f('u') Reads the variable 'u' and assigns it to the Python variable 'u_wind'.
> u_wind.attributes Displays all the attributes pertaining to the variable 'u_wind'.
> v_wind=f('v') Reads the variable 'v' and assigns it to the Python variable 'v_wind'.
> wspd=(u_wind**2+v_wind**2)**0.5
Calculates the combined wind speed and assigns it to the Python variable 'wspd'.
> wspd.id='wspd' Sets the 'id' attribute on the 'wspd' variable.
> wspd.long_name='Wind speed' Sets the 'long_name' attribute on the 'wspd' variable.
> wspd.units='m s**-1' Sets the 'units' attribute on the 'wspd' variable.
> import vcs Imports the VCS (Visualisation Control System) module.
> p=vcs.init() Initialise a VCS canvas and assign Python variable 'p' to it.
> p.plot(wspd) Plot the wind speed variable on canvas 'p'.
> fout=cdms.open('output.nc', 'w') Open a file to write out the wind speed variable to.
> fout.write(wspd) Write the wind speed variable to the output file.

> fout.close() Close the output file.
> CTRL^D Press Control and D to close CDAT.

No comments:

Contributors

google