GrADS Tutorial on TCC

* What is it ?

This document presents a brief tutorial for Brian Doty's Grid Analysis and Display System (GrADS). The following sample session will give you a feeling for how to use the basic capabilities of GrADS. This sample session takes about 30 minutes to run through.

This document is based on original GrADS Tutorial on GrADS Home Page.

* Before you start

Before you start, you need download One-month Prediction GPV data file from here, and convert that file into GrADS file. ( See "To convert a GRIB2 format file at TCC into GrADS format" for Linux    for windows )

* Lesson 1 : start up GrADS / open file / draw a picture

To start up GrADS, enter:

grads 

If grads is not in your current directory, or if it is not in your PATH somewhere, you may need to enter the full pathname, ie:

/usr/homes/smith/grads/grads 

GrADS will prompt you with a landscape vs. portrait question; just press enter. At this point a graphics output window should open on your console. You may wish to move or resize this window. Keep in mind that you will be entering GrADS commands from the window where you first started GrADS -- this window will need to be made the 'active' window and you will not want to entirely cover that window with the graphics output window.


In the text window (where you started grads from), you should now see a prompt: ga-> You will enter GrADS commands at this prompt and see the results displayed in the graphics output window.

The first command you will enter is:

open mg1w.ctl

You may want to see what is in this file, so enter:

query file

One of the available variable is called ps, for sea-level pressure. We can display this variable by entering:

d psea
d is short for display. You will note that by default, GrADS will display an X, Y plot at the first time and at the lowest level in the data set.

* Lesson 2 : change dimension environment

[2-1]
Now you will enter commands to alter the dimension environment. The display command (and implicitly, the access, operation, and output of the data) will do things with respect to the current dimension environment. You control the dimension environment with the set command:
clear           clears the display
set lon 90      sets longitude to 90 degrees East
set lat 40      sets latitude to 40 degrees North
set lev 1       sets level to 1 (* just one level is available now. )
set t 1         sets time to first time step
d z500          displays the variable 'z500'
In the above sequence of commands, we have set all four GrADS dimensions to a single value. When we set a dimension to a single value, we say that dimension is "fixed". Since all the dimensions are fixed, when we display a variable we get a single value, in this case the value at the location 90E, 40N, (lev=1), and the 1st time in the data set. See "Result value = ???"

[2-2]
If we now enter:
clear
set lon 0 180     X is now a varying dimension
d z500
We have set the X dimension, or longitude, to vary. We have done this by entering two values on the set command. We now have one varying dimension (the other dimensions are still fixed), and when we display a variable we get a line graph, in this case a graph of 500mb Heights at 40N.

[2-3]
Now enter:
clear
set lat 0 90
d z500
We now have two varying dimensions, so by default we get a contour plot.

[2-4]
If we have 3 varying dimensions:
c
set t 1 4
d z500
we get an animation sequence, in this case through time.
Press enter to continue.

[2-5]
Now enter:
clear
set lon 0 360
set lat 0 90
set t 1
d psea
d z500
In this case we have also displayed two variables, which simply overlay each other. You may display as many items as you desire overlaid before you enter the clear command.

[2-6]
In this case we have set the X (longitude) and T (time) dimensions to vary, so we get a Hovmoller plot.
c
set lon 0 360
set lat 40
set t 1 4
d z500

* Lesson 3 : use operators and functions

[3-0]
Now that you know how to select the portion of the data set to view, we will move on to the topic of operations on the data. First, set the dimension environment to an Z, Y varying one:
clear
set lon 0 180
set lat 0 90
set lev 1
set t 1

[3-1]
Now lets say that we want to see the 850hPa temperature in Fahrenheit instead of Kelvin. We can do the conversion by entering:
display (t850-273.16)*9/5+32

[3-2]
Any expression may be entered that involves the standard operators of +, -, *, and /, and which involves operands which may be constants, variables, or functions. An example involving functions:
clear
d sqrt(u850*u850+v850*v850)
to calculate the magnitude of the wind. A function is provided to do this calculation directly:
d mag(u850,v850)

[3-3]
Another built in function is the averaging function:
clear
d ave(z500,t=1,t=4)
In this case we calculate the 4 week mean.

We can also remove the mean from the current field:

clear
d z500 - ave(z500,t=1,t=4)

We can also take means over longitude to remove the zonal mean:

clear 
d z500-ave(z500,x=1,x=144)

[3-3]
We can also perform time differencing:
clear
d z500(t=2)-z500(t=1)
This computes the change between the two fields over 1 week. We could have also done this calculation using an offset from the current time:
clear
d z500(t+1) - z500

[3-4]
Another built in function calculates horizontal relative vorticity via finite differencing:
clear
d hcurl(u850,v850)

* Lesson 4 : controll the graphics output

[4-1]
Now we will move on to the topic of controlling the graphics output. So far, we have allowed GrADS to chose a default contour interval. We can override this by:
clear
set cint 30
d z500

[4-2]
We can also control the contour color by:
clear
set ccolor 3
d z500

[4-3]
We can select alternate ways of displaying the data:
clear
set gxout shaded
d hcurl(u850,v850)

This is not very smooth; we can apply a cubic smoother by entering:

clear
set csmooth on
d hcurl(u850,v850)
Can you make sense the difference ? :-)

[4-4]
We can overlay different graphics types:
set gxout contour
set ccolor 0
set cint 30
d z500

[4-5]
and we can annotate:
draw title 500hPa Height and 850hPa Vorticity

[4-6]
We can view wind vectors:
clear
set gxout vector
d u850;v850

[4-7]
Here we are displaying two expressions, the first for the U component of the vector; the 2nd the V component of the vector. We can also colorize the vectors by specifying a 3rd field:
clear
d u850;v850;rain

or maybe:

clear
d u850;v850;hcurl(u850,v850)

[4-8]
You may display pseudo vectors by displaying any field you want:
clear
d mag(u850,v850) ; rain*0.1
Here the U component is the wind speed; the V component is precipitation.

[4-9]
We can also view streamlines (and colorize them):
clear
set gxout stream
d u850;v850;hcurl(u850,v850)

[4-10]
Or we can display actual grid point values:
clear
set gxout grid
d u850

[4-11]
We may wish to alter the area size:
clear
set lon 70 110
set lat 30 45
set digsize 0.2
d u850

[4-12]
To alter the projection:
clear
set lon 40 140
set lat 15 80 
set mproj nps
set gxout contour
set cint 30
d z500

[4-13]
Generate an image file using "printim" command:
printim fig01.gif x800 y600 black 
In this case, the "printim" command produces a GIF formatted image file on the current contents displayed on the screen, which has a resolution of 800x600 using black background.

You can make a PNG formatted image file and change background and resolution if you want.

printim fig02.png x400 y300 white 

* Conclusion

This concludes the sample session. At this point, you may wish to examine the data set further, or you may want to go through the GrADS documentation and try out the other options described there.


updated : Jun.30, 2004 [ back ]