GrADS Tutorial
(with scripting)

pix
Go back to home page

This page provides an introduction to the GrADS plotting utility and scripting language. GrADS is applied mainly to the GRIB files of the NCAR/NCEP Reanalysis Data. Using Python for data processsing, as an alternative to GrADS scripting, is also presented.

This page is obsolete.

The latest page is at itmetr.net.

last modified: 05:06 PM MDT, Sun 15 Jun 2008

Your first stop should perhaps be at the official GrADS Home Page. GrADS is GRIB-friendly, and Gentry has access to about 40 Gigabytes of reanalysis data in GRIB format, from the NCEP/NCAR Global Reanalysis Project. Currently we have years 1953-2001. Here is the datalist and filelist, showing the data we have.

For a sample of what GrADS plot looks like, you may want to check my rather limited GrADS-powered online reanalysis plotter.

Fortunately, you can use the data fairly easily without becoming an expert on GRIB. This succinct introduction to GRIB, GrADS, and wgrib has a plug for GrADS. Recall the wgrib utility can be used to extract and convert GRIB data to familiar text and binary forms. Using wgrib with GRIB files was introduced in Faster Python with Numeric. Using wgrib to extract a times series was done with a modified version, wgrib_hacked.c, in Statistical Analysis of Norman Temperature. GrADS can open and read GRIB files with simple commands. You might be able to get your work done, without a need for either Python or wgrib. That should be the true for the task here, but a Python alternative to the GrADS scripting is also demonstrated. For my own purposes, I don't really need GrADS anymore. I would prefer to use wgrib to extract the data, Python to process the data, and the basemap toolkit (within matplotlib) to plot the result. Plotting with basemap was demonstrated in my NetCDF tutorial. But your boss may want you to use GrADS. Also, you may appreciate Python more after you try GrADS. The task here is pure GrADS.


Using GrADS

The GrADS software is installed on Gentry.

In the main "readme" file distributed with the CDROMS, (which is how we got our data), we are given the following instructions (which I have shortened and modified for our Linux installation with the data on the local file system):


	One goal in the design of this CD-ROM was to make it fast
	to use.  Suppose you happen to be interested in the weather
	on February 2, 1972.  You should be able to take the CD-ROM
	for 1972, put it into your computer, and be looking at the
	500 mb heights in half a minute.


  1) type "grads", a "ga>" prompt should appear. (4 seconds)


  2) Open a control file  (5 seconds)

       in SOM: ga>  open /REANALYSIS/1972/ctl/at00z12z/hgt.prs

      Note: to check the contents of the file, type
            ga> query file

  3) Display a plot  (5 seconds)

      example:
               ga>  set time 2feb72
               ga>  set lev 500
               ga>  d hgt

This brings up my first annoyance with GrADS: If any part of the plot window is temporarily covered by the terminal window in which you are typing in the GrADS commands, when you bring the plot window to the foreground, the part that was covered is blank. I don't know of any other plotting software that has that problem.

  • The official, online online GrADS tutorial is recommended as a first step to learn more about GrADS. (There you also learn a little bit more about GRIB, specifically why the data file is in /1972/data/at00z12z/hgt.prs but GrADS "opens" a short control file /1972/ctl/at00z12z/hgt.prs that describes the data file.) The tutorial does not teach you how to make scripts, or to produce .ps or .png output.

  • As a user of Python, Perl, Ferret and R, let me share with you some of my reactions to GrADS and its scripting language.

    • Plotting capabilities appear to be similar to Ferret, though GrADS is most friendly with GRIB data, and Ferret is most friendly with netCDF.

    • The GrADS scripting language, like that for Ferret, is very limited as compared with Python and R.

    • You cannot do much of anything with GrADS until a file is open and something is plotted. For example, after setting a longitude and latitude window, and drawing a map backgrounds, you still cannot use w2xy, and therefore cannot plot a single hurricane position with graphic primitives, until a two-dimensional field is plotted.

    • The GrADS scripting language is NOT the same as the command line language. This make GrADS somewhat uniquely peculiar. As discussed in the manual, instructions for plotting, opening files, etc. that you want to behave like on GrADS command line must be entirely quoted or otherwise formed as a single string. New variables can be defined with the scripting language. But here is something that is peculiar:

      • From the command line:
        	y=3+1
        	display y
        	x=sqrt(y)
        	display x
        		

      • But from the scripting language,
        	y=3+1
        	say y
        	'display sqrt('y')'
        	x=subwrd(result,4)
        	say x
        		
      There is no sqrt function that can be used directly within the scripting language. Likewise, there appears to be limited string processing in GrADS; the subwrd function is useful to prepare labels for plots, but it is only found in the scripting language. Needless to say, doing any data processing within GrADS could be rather frustrating, as compared with Python, R or Ferret.

    • The implicit concatenation of strings, as in 'display sqrt('y')', is useful, but can be very difficult to edit or to understand without syntax highlighting as in this example. See my vim/gvim tuneup for a syntax file for GrADS.

    • GrADS does not tolerate indenting with tabs. Another reason to visit vim/gvim tuneup.

  • GrADS online documentation is available and free, just like the software... I particularly struggle with the index.

  • The GrADS listserv archive is not "free" anymore, meaning the casual user cannot search it. Even 24 hours after registering, I cannot view the archive (November 11, 2005). Disappointing.

  • Download and print GrADS reference card and GrADS scripting language reference card.

  • You may also eventually want to surf a group of pages about wgrib, grib2ctl, reanalysis, etc.. Essential surfing for those of you needing to immerse yourselves in the world of GRIB and GrADS.

  • There are other attempts at GrADS tutorials out there on the web. GrADS for Dummies is worth a visit.

Some Advice for Writing GrADS scripts

Grab my grads_scripts.tar.gz.
The task is within the subdirectory thermalwind.

There are several subdirectories within grads_scripts, which contain various plotting tasks. Here is a compendium of the plots.

There are Readme files to view within grads_scripts, but here are some additional comments about one of the first you should study, t2m.gs. The script t2m.gs is essentially the same GrADS script that is written by a Python CGI script behind online reanalysis plotter. There are a few comments to read in t2m.gs. I recall suffering quite a bit trying to get the darn thing to work, and desperately reading the GrADS Listserv Archive, which these days I cannot even access.

As introduced above, the scripting language has some unusual syntax: Lines that also would work interactively with GrADS must be in ' '. Lines that are part of the GrADS scripting language (which do not seem to work interactively) do not have the quotes. Similarly, the variables produced by these scripting lines, still with no ' ' around them, can be concatenated with quoted strings by simply placing them next to each other in the script line. You will need the script cbar.gs to be in the same directory as t2m.gs. Then, from the unix command line type (or from a Python or Perl script):

grads -blc "run t2m.gs"

If the grads.metafile was output by the above command, rather than from the PNG, then to convert to encapsulated postscript:

gxeps -c -i grads.metafile -o temp.eps

The online GrADS Scripting Language is your main source of information, but also be sure to read about batch processing on this page.

GrADS version 1.8 or later can use printim to make PNG files directly, without going through a metafile. See the lines to uncomment near the end of t2m.gs. gxeps is one of several commands that act on the grads metafiles. These commands work from the Unix command line, independently of grads.


Previous tasks now offered as examples

  • The use of GrADS from a CGI script is demonstrated by the GrADS-powered online reanlysis plotter. You can download gradscgi.tar and set up your own plotter and fiddle with it. Its function can obviously be expanded. Needless to say, you need to have access to the reanalysis data. from your computer ( e.g. rossby.metr.ou.edu) if this stuff is going to work. The cgi stuff is rather sparsely commented; you are expected to already be familiar with the CGI tutorial.

  • The task for 2004 was hurricanes. This was cleaned up as an example within grads_scripts, and is obsolete.


Some other GrADS scripts

(Some things here are not for GrADS, but I am keeping them here so that I do not lose them.)


Links

NCEP/NCAR Global Reanalysis Project
The Annual Reanalysis CD-ROMs
GrADS Home Page
GrADS Listserv Archive
online GrADS tutorial
wgrib, grib2ctl, reanalysis, etc.