Friday, May 3, 2013

Tutorial: How to make a basemap using GrADS

Basemaps are a great way to add some color and vibrance to your weather maps.  This tutorial will show you how to make a basemap in GrADS, using topography data from the GrADS Data Sever, and the basemap scripts from the Script Library.  The basemap we will make is shown below, and is the same basemap used in the basemap overlay tutorial.

Finished Basemap

So, for this tutorial you must download the following files from the script library.
  • lpoly_lowres.asc
  • opoly_lowres.asc
  • lpoly_mres.asc
  • opoly_mres.asc
  • lpoly_hires.asc
  • opoly_hires.asc
In addition to these scripts you must also have the script in your script folder.  Once you have all these scripts, you are ready to begin!

Now, basemaps are fairly easy to make, and can essentially be boiled down to three simple steps.
  1. Set a domain.
  2. Define a topography color scale (this is why we need
  3. Fill in the water areas using the ".asc" files

Step 1: Set a Domain.
This is probably the most important step in making a basemap.  In order to use the basemap later for your weather maps, you must know a) The lat/lon boundaries, b) the size of the image in pixels, and c) the GrADS page area of the map (set using the 'parea' command).   But before we do anything, we want to open the data file.  We'll be using topography data to make a basemap with terrain.  So we will access the topography data from the GrADS data server.  To access this data, we will start with the 'sdfopen' command


Now that our file is open, we will type in a couple of generic commands, so to set the background color to white and print a high resolution map when we display our variable.

    'set display color white'
    'set mpdset hires'

Now to set the actual domain.  So, to make the image above, we will set the domain for the United States.  We will do this using the 'set lat' and 'set lon' commands.

    'set lat 22 51'
    'set lon -128 -65'

At this point, we have our file open and our domain set.  So the last thing we need to do before moving on to step 2, is define our page area.  Remember this is important, so you know how to scale your weather maps in GrADS to fit on this image.  We do this using the 'set parea' command.  For the above image, the page area is set by:

   'set parea 0.5 10.0 0.5 7.5'

Now that we have our area, we can move on to step two.

Step 2: Define a Topography Color Scale

This is very easy with the script, all you need to do is pick out a range of colors.  For this map, we are going to use a transition from light green to brown, and our scale will fit the range of topography in the US (0 to ~4000 meters).  More information on the script (including a list of colors) can be found at their website listed above, so if you want for information you can find it there.  Anyway, the commands for the color scale used on the above image is set by this:

    int=(4100-200)/50       ;*int sets the interval used for topography, this scale sets 50 intervals.
    'color 200 4100 'int' -kind lightgreen->tan->brown'

Once the color scale is set, simply display the variable.

    'd rose'

Now, our basemap is starting to take shape and we are set to move on to the final step.

Step 3: Fill in Water areas
This is the last step, and the only step that involves the use of

To fill in the water areas, you will need to run the script as such:

    'basemap O 11 1 H'

In this command, the O stands for Ocean, so the script will fill in bodies of water.  The two numbers correspond to the fill and outline colors respectively.  11 for medium blue and 1 for black.  Lastly, the H stands for high resolution, so this will use the file opoly_hires.asc to fill in the ocean.

Now, that you have a nice looking basemap, all thats left is to save the image using the 'printim' command.  Be sure to specify the image dimensions, so that you can match them later when you save GrADS output over your basemap.

    'printim img_name.png x800 y600 png'

And that's it, that's all there is to it! You now have a nice, elegant basemap to serve as a background for your GrADS output.  To learn more how to output GrADS data onto your basemap, check out this tutorial.

Download Example script


  1. Hi there ! I just asking .. what will I do if the command basemap says "sh: bash: command not found. error in reading opoly_mres.asc." im using grads 2.0.a9.oga.1? thanks !

  2. I think your problem is you either don't have the file "opoly_mres.asc" or you don't have it in the right folder. I would start by double checking that this file is in your GrADS directory, and if not you can get it from this link: I am almost certain this is your problem.

  3. Hi, is there anyone that has an opoly_hires.asc for africa?

  4. I don't know of any poly_hires.asc for Africa. If I were you, I would run use the opoly_mres.asc to make your basemap, and then to up the quality of the image, I would open it in paint and touch up the edges around the coastlines. I've done this before, and it works pretty well.

  5. Hi...I am facing a problem while using sdfopen command in Opengrads. I get the following error:
    Error: nc_open failed to open
    NetCDF : I/O Failure
    Kindly do the needful. I am using OpenGrads version 2.0.1

    1. I sometimes see that error, it usually has to do with internet connections. If you haven't already try again. Sorry for the delayed response!