![]() | ![]() | Home | ![]() | My BADC | ![]() | Data | ![]() | Search | ![]() | Community | ![]() | Help | ![]() |
![]() | Guided Tour | Getting data | Formats | Software | 10 FAQ | ![]() |
Below are some key features of CDAT:
Figure 1. VCDAT and example output.
CDAT writes output to NetCDF. ASCII files can also be written using the standard python function for writing output to a file (f=open('output.txt','w')).
This tutorial uses CDAT at the command line. You can also open the file using VCDAT (just type vcdat at the command line to start the GUI). Plotting and saving is then straightforward. Note that when running VCDAT you can view the underlying CDAT (Python) commands by going to the 'Tools' menu and choosing the 'View Teaching Commands' or 'View Recorded Commands' options.
This tutorial requires that you have a sample NetCDF file. You can download the sample file here (84KB). The file (called 'wind_comps.nc') is a NetCDF file containing u-wind and v-wind data over the globe at a 2.5° resolution at the 1000hPA level. Save the NetCDF in the directory you are working in before you start the tutorial.
The following commands should allow you to calculate the wind-speed ('wspd') from the u-wind ('u') and v-wind ('v'), plot the resulting variable and write it to an output NetCDF file.
The command to type is shown in bold and the output in plain type. The commands are annotated in normal font in the right-hand column. The tutorial follows:
| > cdat | This starts the CDAT shell, identical to the Python shell. |
| Executing /usr/local/cdat/bin/python
Python 2.2.2 (#1, Jul 15 2003, 15:31:17) [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)] on linux2 Type "help", "copyright", "credits" or "license" for more information. |
|
| > 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'. |
| AttributeDict ({'_grid_': None, '_shared_mask': 0, 'name': 'u', 'parent': None
, 'title': '** U-velocity m s**-1', '_mask': None, 'id': 'u', 'standard_name': 'eastward_wind', '_TransientVariable__domain': [ ( id: time
( id: level
( id: latitude
( id: longitude
, 0, 144, 144)], '_data': array (1,1,73,144) , type = f, has 10512 elements, '
|
|
| > 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. |
| <Variable: wspd, file: output.nc, shape: (1, 1, 73, 144)> |
|
| > fout.close() | Close the output file. |
| > CTRL^D | Press Control and D to close CDAT. |
If you have problems with the tutorial please contact BADC Support.
![]() | Home | Contact | Disclaimer | Last Modified:
| ![]() |