GMTB Workflow Documentation
The Graphics Component
python-logo.png

The graphics component is a simple object oriented graphics library designed to make it very easy for programmers to experiment with computer graphics in an object oriented fashion. It is written by NOAA/ESRL/GSD and NCAR/DTC/GMTB staffs for use with the GMTB Rocoto Workflow. The most recent version of the library is built in the GMTB Rocoto Workflow. This document is a reference to the functionality provided in the library.
In this package, the following scripts use Python to extract and visualize the meteorological fields in NEMS using the GMTB workflow GRiB2 files:

Modules Required

  • pygrib : a Python module for reading and writing GRIB (editions 1 and 2) files. GRIB is the World Meterological Organization standard for distributing gridded data.
  • matpotlib : a Python 2D plotting library which produces publication quality figures in variety of hardcopy formats and interative environments across platforms.
  • basemap : a library for plotting 2D data on maps in Python. It is similar in functionality to the matlab mapping toolbox, the IDL mapping facilities, GrADS, or the Generic Mapping Tools. Basemap is geared toward the needs of earth scientists, particular meteorologists and oceanographers. It provides the facilities to transform coordinates to one of 25 different map projections (using the PROJ.4 (http://trac.osgeo.org/proj/) C library). Matplotlib is then used to plot contours, images, vectors, lines or points in the transformed coordinates. Shoreline, river and political boundary datasets (from Generic Mapping Tools) are provided, along with methods for plotting them.

Running GMTB graphics

GMTB_graphics.py can be run either with or without a Rocoto workflow. If running without a Rocoto workflow:

  1. Export required environment variables via sourcing a config_local file.
    source config_local
#
### an example of config_local file ###
#
# START_TIME is the analysis time
# FORECAST_TIME is the forecast time in 3 digit format
# GRID_VX_LIST controls the grids that are provided. Possible values are glob, G104, G218, G3.
#
# Input file will be regridded to the NCEP Predefined grid if the item has a leading "G".
# NCEP Grids must be defined in regrib.py
# New map projections are defined in basemaps in make_basemap.def_bm
# Available values includes:
# glob -- plots the input file directly
# G104 -- NCEP G104: NPS CONUS
# G218 -- NCEP G218: CONUS 12km Lambert
# G3 -- NCEP G3: Global 1 deg lat/lon
# nh_mill -- Original grid, NH
# sh_mill -- Original grid, SH
# trop_mill -- Original grid, Trop
# nps -- Original grid, full NPS projection
# sps -- Original grid, full SPS projection
setenv MOAD_DATAROOT /scratch4/BMC/gmtb/Man.Zhang/gmtbtier3/refcst
setenv START_TIME 2016011500
setenv FCST_TIME 024
setenv GRID_VX_LIST 'glob'
setenv ROTDIR /scratch4/BMC/gmtb/refcst/2016011500
  1. Load the anaconda python module on Theia:
    module use -a /contrib/modulefiles
    module load anaconda
  2. Submit the GMTB_graphics.py using the following command:
    python GMTB_graphics.py

How to add a graphic

  • To add a graphic, edit the GMTB_graphics.py dictionary, map_confs, and potentially the maps.py dictionary, params in the set_fig_params method.
  • map_confs: sets the desired output figures that will be produced.
  • params: controls the settings of the figures such as shading intervals and scaling for desired levels.
  • If your variables do not exist in params, you must add them there. All values are not required, but some information about contours are required. To find the exact values, you should go into the dictionaries that can be found by opening up and instance of Python and looking at the key, value pairs for the grib records.
    • Open python
      python
    • Load the pygrib package
      import pygrib
    • Open the grib file
      filename='myfile.grb'
      grbs = pygrib.open(filename)
    • Look at the key value pairs
      grb = grbs[##] !> ## is the grib record number
      for i in grb.keys(): print i, grb[i]