MRG Interactive Developments

Mesoscale Research Group, McGill University


A Python Interface for GEMPAK Applications




GEMPAK Introduction

The GEneral Meterological PAcKage is a widely-used library and set of applications performing primarily atmospheric diagnosis and display functions maintained and freely distributed by Unidata. The basic form of the user interface is text-based although some graphical components are provided with the package and others (such as ActiveGEM) are freely available. Scripting for the automated generation of diagnostics and graphical output is usually accomplished using a UNIX shell, although other more advanced programming languages can be used and greatly increase the power, portability and readability of GEMPAK scripts. For more local information on GEMPAK from MRG Interactive (and for information on the new GEMPAK speedPatch optimization) go here.

Python Introduction

Python is a widely-used interpreted, interactive, object oriented programming language that has been under development since the mid 1990's. It combines high-level functionality with exceedingly readable syntax to produce powerful, maintainable, portable code. Python is increasingly becoming the scripting language of choice in many labs and universities, largely because of these important attributes. There are many excellent Python resources on the web, including:

Interface Description

The Python GEMPAK interface is
available here as a Python module. To install this module, simply download the file gempak.py to the /python/install/path/lib/pythonX.X/site-packages directory. This makes the interface immediately avaialble to any Python program or interactive job through the import gempak command. The primary advantages of this streamlined interface are that looping through lists of selections is accomplished internally and superposition of fields is handled within the interface. The constructor for the interface object is the app method and numerous other methods are available to assist the user in setting options (called macros internally), determining the current state of the object, and obtaining information about the selected GEMPAK application. Note that all GEMPAK applications and options are supported by the interface.

gempak Constants

The constants defined in this module are:

gempak Methods

The GEMPAK interface is implemented using the following methods

gempak Examples

Here are a few simple examples for how to use the gempak class.

This example creates a new GEMPAK file for station data using sfcfil: $> import gempak
$> gem = gempak.app('sfcfil')
$> gem.set('sfoutf','outFile.gem')
$> gem.set('shipfl','no')
$> gem.set('timstn','1500/10000')
$> gem.run()

This example concatenates a pair of datafiles into the newly-created station file: $> import gempak
$> gem = gempak.app('sfmod')
$> gem.set('sffile',['input1.gem','input2.gem']
$> gem.set('sfoutf','combined.gem')
$> gem.set('dattim','all')
$> gem.set('sfparm','')
$> gem.list() $> gem.run()

Note that this example takes advantage of the internal looping of the interface by providing the sffile macro with a list rather than a string. This triggers loop generation within the interface and can be applied to as many of the setting macros as required. This example also lists the settings before running the GEMPAK application.

This example generates a series of postscript plots for dates valid within a set of files. $> import gempak
$> gem = gempak.app('sfmap',clean=0,hardcopy=1)
$> gem.set('device','PS|surfaceMap.ps|;|C')
$> ## First Layer
$> gem.set('sffile','input1.gem')
$> gem.set('dattim',['030924/0000',030924/1200'])
$> gem.set('sfparm','skyc:.5:1;tmpc:.5:1')
$> gem.set('filter',1.)
$> ## Second Layer
$> gem.nextLayer()
$> gem.set('sffile','input2.gem')
$> gem.set('filter',0.7)
$> ## Create Maps
$> gem.run()
Note that this example makes use of internal looping and of multiple layers. Two PostScript images will be produced by this script (named surfaceMap-030924_0000.ps and surfaceMap-030924_1200.ps), each containing two layers as specified in the example.

MRG Interactive is a supporter of open source initiatives and,

SourceForge.net Logo

Questions or Comments? Contact our WebMaster.