Friday, May 3, 2013

Tutorial: How to make a basemap using GrADS

Note: This tutorial was updated October 2019 to reflect the fact that the Grads Data Server has been discontinued, so the online access of the terrain data through monsoondata.org is no longer available.

This tutorial was first published in 2013, with a tutorial on how to create a basemap of the United States.  In updating the tutorial for 2019, I have decided to alter the tutorial to focus on a different region of the globe, Europe to be specific.  Functionally, the concepts are the same (see images below).

Introduction:
Basemaps are a great way to add some color and vibrance to your weather maps.  GrADS allows you to output data onto a pre-generated .png image (i.e., a basemap) instead of redrawing the map everytime you want to make a figure.  This can be a big time saver if you're making several images in sequence.  This tutorial will show you how to make a basemap in GrADS using the 'basemap.gs' script and accompanying polygon files to mask the ocean..  You will learn how to:
  1. Download and open netCDF topography data from NOAA 
  2. Use the and the "basemap" script from the GMU GrADS Script Library to mask out oceans. 
It is recommend that you check out the basemap overlay tutorial if you are unfamiliar with GrADS basemaps.
Finished Basemap: 2013 TutorialFinished Basemap: 2019 Tutorial

So, for this tutorial you must download the following files from the GMU GrADS Script Library.
  • basemap.gs
  • lpoly_lowres.asc
  • opoly_lowres.asc
  • lpoly_mres.asc
  • opoly_mres.asc
  • lpoly_hires.asc
  • opoly_hires.asc
In addition to these scripts, it is recommended that you have the color.gs and/or the colormaps script your personal script folder so you can use the same color settings as this tutorial.

Where to get the data:
While the GDS has been discontinued, you can still access high resolution (1min) topography datasets in netCDF format from NOAA.  Simply access this link and download either the full ETOPO1 (netcdf) file, or use the NCEI "Grid Extract Tool" to subset the data to a geographic region of your choice.  If you're using the Grid Extract Tool it will look similar to the screen shot below.

Screen shot of grid extract tool.

Once you have the netCDF (etopo1.nc) file locally, move it to your own data folder: (e.g., home/grads_data/terrain/).

How to make the basemap:
Basemaps are fairly easy to make, and can essentially be boiled down to three simple steps.
  1. Load the topography data and set a domain.
  2. Define a topography color scale (this is why we need color.gs)
  3. Fill in the water areas using the ".asc" files

Step 1: Load the topography data and 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).  I strongly recommend that you write down your lat/lon boundaries, your page area coordinates,and your x and y pixel size for saving the image so that you know how to match data on top of the map.

    'set display color white'
    'set mpdset hires'
    'clear'
    path = 'home/grads_data/terrain/' ; *or whatever your path to the etopo1.nc file is.
    'sdfopen 'path'etopo1.nc'

You can run a "qfile" on the data to look at the metadata if you would like, but it's not necessary for this tutorial.

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 30 60'
  'set lon -16 35'

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 color.gs script, all you need to do is pick out a range of colors.  For the old US map, we used the color.gs script to make a color scale that transitioned from light green to brown, that fit the range of topography in the US (0 to ~4000 meters).

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

For the 2019 update, I chose to use the colormaps script to define the "terrain2" color scale as follows:

  'colormaps_v2 -map terrain2 -levels 0 3500 100'

Choosing a color scale is entirely, up to you, but the above options look nice to me.  Once the color scale is set, simply display the variable.


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 basemap.gs.

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

    'basemap O 11 1 M'

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 M stands for medium resolution, so this will use the file opoly_mres.asc to fill in the ocean.  The reason to use mres instead of hires, is because the hires oceans only cover the oceans around North America, so since this tutorial looks over at Europe, you need to use mres.

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.

Note: This example script is for the 2013 tutorial with the broken GDS link.

Download Example script


15 comments:

  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 !

    ReplyDelete
  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: http://www.iges.org/grads/gadoc/library.html. I am almost certain this is your problem.

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

    ReplyDelete
  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.

    ReplyDelete
  5. Hi...I am facing a problem while using sdfopen command in Opengrads. I get the following error:
    Error: nc_open failed to open http://monsoondata.org:9090/dods/topo/rose/etopo05
    NetCDF : I/O Failure
    Kindly do the needful. I am using OpenGrads version 2.0.1

    ReplyDelete
    Replies
    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!

      Delete
  6. Hi, I´m trying to do a basemap for a small area in south america but the link doesn´t work (might have expired?). Can you please help? I got to download ETOPO5.dat from NCEP website but still can´t figure it out.
    also tried with shapefile but I don´t know how to use it.
    Thanks in advance!

    ReplyDelete
  7. Hi!, im trying to fill the water areas using the basemap.gs, but it says "sh: bash: command not found. error in reading opoly_mres.asc.", i have already downloaded the opoly_mres.asc file and put it in the same folder as basemap.gs script, but it still didnt work, can you please help ? thanks in advance!

    ReplyDelete
  8. Hi, thanks so much for your blog. It is so great.
    I am actually working on correlate an observation data (.ctl file 1 variable) with a 10 days forecasts data (.ctl file 10 variable per day). I am so confuse about how to make that kind of correlation.
    Thanks

    ReplyDelete
  9. Hi. NetCDF:File not found. What seems to be the problem?

    ReplyDelete
  10. Hi

    I am trying to generate the basemap for South West Pacific region but have problems in installing basemap file
    can someone share the link to basemap files related files

    thanks

    ReplyDelete
  11. Hi
    can anyone help me in basemap installation
    i am having difficulties

    thanks

    ReplyDelete
  12. Unfortunately, funding for the Grads Data Server where the topography data was available (i.e., http://monsoondata.org:9090/dods/topo/rose/etopo05) has been discontinued due to a lack of funding. I will update this blog post to reflect that, and if possible add a new source shortly.

    ReplyDelete
  13. when i use it for Nicobar Island. it only cover a small area , which is not cover all island. Suggest any site from where i can download the shapefile with label of Asian country like India. Waiting for reply.

    Thank

    ReplyDelete
  14. Hello

    What a way do you recommend to export the animation created by GrADS to
    a form that can be shown with some commonly used software under Windows?

    ReplyDelete