Sunday, August 18, 2013

Display Gridded Gauged Rainfall data using Grads



Download GRIdded Binary (Grib) data from source. In my case, I am interested in hourly gauged rainfall from NCAR EOL, which is available in gridded binary format.

Step 2: In order to display grib data using grads, we need to create a control file (.ctl) and an gribmap index file (either .gmp or .idx). Control file can be created using grib2ctl perl script.

Create ctl file using grib2ctl perl script.
grib2ctl.pl file_name.grb >file_name.ctl. 
Make sure the grib2ctl.pl is executable and is in searchable location (I had copied it to /usr/local/bin).

Once the file_name.ctl file is created, create index file using gribmap (inbuilt with grads software). 
gribmap -i file_name.ctl -0 (if the gridded file is for one time step).
Now that file_name.ctl and file_name.idx file are created, we can display the variable using grads. For hourly gridded gauged rainfall data, the name of the variable is apcpsfc. You can get this information using wgrib
wgrib -V file_name.Grb
The following lines of code plots gridded gauged rainfall data (hourly):
Open a terminal and cd to the location where the .grb, .ctl and .idx files are saved.
Type grads in command prompt. This will start a new grads session. Choose landscape or portrait mode.
open file_name.ctl (grads will open the control file)
query file (list details of the file such as variable name, domain etc)
set lon -125 -67 (sets lon range)
set lat 25 49 (sets lat range)
d apcpsfc (displays contour map of gridded gauged rainfall data)
If you do not like the default line contour display, you can display using shaded contour.
clear (clear existing plots)
set gxout shaded (this will set contour type as shaded)
set csmooth on (if you want to have a smooth contour, set this option on)
d apcpsfc (displays shaded contour of gridded gauged rainfall data).
Finally, if you want to save the display image, type the following.
printim image_filename.jpg (saves image in jpg format. other options are png and gif).