Sunday, February 16, 2014

Tutorial: An introduction to using surface station data in GrADS

In addition to plotting gridded data, GrADS can also be used to plot station data; that is data formatted with information specified at specific latitude/longitude coordinate rather than data gridded in a mesh that spans a region. This tutorial will show you how to use some of the functions in GrADS to work with surface data from both the mesonet and METAR inventories to generate surface maps with and without contoured data. At the end of the tutorial, you will know how to make the images shown below using station data. 


Surface map with METAR data.

Surface data and Contoured Sea level Pressure From METAR data

Surface data and Contoured Sea level Pressure From METAR data


First things first: Getting the station data.  Getting the station data and, more importantly, getting it into the right format is the trickiest part of using station data with GrADS.  To get the data into the right format, you must have knowledge of coding in another language (Fortran, C, Python, etc,.).  The scope of this tutorial is to focus on using the station data in GrADS, and not showing you how to get the data into the right format.  So if you are looking to learn how to format station data such that it can be read into GrADS, this tutorial is not for you. 

Some good information regarding how to format station data can be found here and here.  The basic idea is that you need to take the station data, write out a binary file with a header including information such as station id, latitude and longitude, and then the actual data for each station.  Afterwords you need to write out a control file to tell GrADS how to interpret your binary file.

Since I am not going to show you how to grid station data, I have prepared a few files for you to use with this tutorial.  They can be found here:

Mesonet Data (for temperature map)

 METAR Data (For station and SLP maps)

Once you have downloaded these files and placed them in your GrADS directory (note: Mine is c:/OpenGrADS/, you may need to change the 'dset' variable in the .ctl files to match your GrADS directory).  Now before you can open the file, you need to use the 'stnmap' utility to help map out the data.  This is easy enough to do.  Before you open GrADS, open up a console (windows command prompt) and type the following command to make your station map.

    'stnmap -i mesotest.ctl'     ---> For the mesonet data.
    'stnmap -i metartest.ctl'    ---> For the METAR data.

This makes your station data accessible in GrADS.  For more information on the station map utility you can read more here.

Now you are ready to open up GrADS!  We'll focus on the station data only first.  To do this start by opening up metertest.ctl, and do a 'q file' to see whats in the data.

    ''open metartest.ctl'
    'q file'

This will tell you what variables are in the file.  In the data file provided, cld and wxsym are dummy variables and contain no relevant information;  they are just place holders.  What we are going to do is plot out station plots with temperature and dew point.  This is very simple, all that is needed is to first 'set gxout model' and then display the data.  To commands below will reproduce the first image seen (without the title).

    'set display color white'
    'set mpdset hires'
    'clear'
    'set lat 30.52 40.24'
    'set lon -100.39 -90.11'
    'set gxout model'
    'd u;v;ts;td'

The 'd u;v;ts;td' tells GrADS to plot a station model with wind components u and v, along with the surface temperature and dew point.  Note: without u;v components nothing will plot when the graphics is set to 'model'.  To add more, you simply increase the number of variables in the chain (in proper order).  For example to add SLP the command would be: 'd u;v;ts;td;slp'.  Missing variables are represented by a 0.0.  The expected order of variables is well described here.

Now lets say we want to do a similar station plot, only now with the contoured sea-level pressure.  To do this, you need to fit your station data to a preexisting grid.  In this tutorial, we will use the RAP model as our base grid.  It doesn't matter which data set you use, but it is recommended you pick something that is of similar grid spacing to your station plot (e.g., it wouldn't be good to use grid METAR data to 2km grid spacing).  Since we are using METAR data, the commands will be almost the same as the ones above with the only difference being a domain change.

    ''open metartest.ctl'
    'set display color white'
    'set mpdset hires'
    'clear'
    'set lat 36 49'
    'set lon -84 -65'
    'set gxout model'
    'd u;v;ts;td'

Once this is done, we need to open up the RAP model data using the 'sdfopen' command.

   'sdfopen http://nomads.ncep.noaa.gov:9090/dods/rap/rap20140216/rap32_12z'

This file is now open as file 2.  From here it is simple, we just use the oacres function to fit the data to the grid.  Now here, it does not matter which variable from the RAP you use, since it is just a dummy variable to get the grid to which the station data will be interpolated too using the Cressman objective analysis on. 

First some formatting...

    'set cthick 6'
    'set clevs 990 994 998 1002 1006 1010 1014 1018 1022 1026 1030'
    
Then we can use the oacres function to interpolate the station data.

    'd oacres(rh2m.2,slp.1,45,30,20,10,5)*33.86'

And voila, you have your station SLP contoured on your map.  To break down what exactly is going on in the above command:

The first argument (rh2m.2) is the variable from the RAP model, essentially the grid you are projecting your data onto.  The suffix .2 is simply there to specify that you want the variable from file number 2 (if you are unfamiliar with how to handle multiple files in GrADS, check out this tutorial).  The second argument (slp.1) is the station variable you want interpolated to the grid, in this case Sea Level Pressure.  The arguments after that specify different radii of influence that you are using to interpolate the station data with.  This will take a little experimentation on your part to get right, but the selection used above seemed to work fairly well with this data set.  I am personally not 100% familiar with the exact math behind the Cressman OA, so if you want to know more on that, you are on your own.  The factor of 33.86 is to convert the station SLP reported in inHg to mb.

The final lesson in this tutorial is very similar to the 2nd lesson except now, we are using mesonet data, which has a higher density than METAR data.  So again we will start by opening the file (in this case the mesotest.ctl).

    'open mesotest.ctl'
    'set mpdset hires'
    'clear'
    'set lat 36 49'
    'set lon -84 -65'

Instead of displaying the data as a station model, we are doing a shaded contour underneath the station data.  So we need to do the Cressman OA first, which means we need to open the RAP file and set up our formatting.  In this example, I used color.gs and xcbar.gs to set the color scale and color bar, but you can do that however you would like.

  'sdfopen http://nomads.ncep.noaa.gov:9090/dods/rap/rap20140216/rap32_12z'
  'color -20 100 2 -kind fuchsia->darkblue->lime->yellow->red'
  'set gxout shaded'
  'd oacres(rh2m.2,ts.1,45,30,20,10,5)'
  'xcbar 10.10 10.20 0.5 8.0 -fs 5 -line on'

This will draw your shaded station temperature data fit to the RAP grid.  Once again, you may have to play with the radii numbers to get it exactly to your liking.  Same goes for your color location and your color scale.  Once this is done, simply use the 'set gxout value' command and display your temperature data.

  'set gxout value'
  'd ts'

And that about does it for your temperature plot, and for that matter, this tutorial!  I hope you enjoyed it and found it interesting.  The script below has the examples described here and is set for you to use and experiment with.  

As a final note:  The station ids were not plotted with the data in the examples in this tutorial.  However, this can be toggled in GrADS by using the 'set stnid' command.  For example, to turn on the plotting of the station ids: 'set stnid on' .   

Thanks again for reading!






1 comment:

  1. When doing oacres command, shall we use the same date on both data?

    ReplyDelete