![]() ![]()
|
MRG Interactive DevelopmentsMesoscale Research Group, McGill University |
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 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:
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.
GEMEXE - Sets the path of the GEMPAK executable (application) directory. This
value is automatically set to the environment variable $GEMPAK at import time, but can be modified
by the user.
class gempak.app(application[,clean=1][,hardcopy=0]) -
the constructor takes one mandatory argument (the name of the desired GEMPAK application) and
two optional arguments. The a boolean true value in the clean argument (default)
ensures that the gpend IPC buffer cleaning utility is run following the completion of
the GEMPAK application. This value should not be changed without good reason. The hardcopy
option (default 0) allows the user to specify whether the gpend utility is to be run at the end
of each iteration of the application (rather than just at then end) and is useful for generating
hardcopy output.set(macro,value) - set the macro (GEMPAK variable) to the value
given by value.get(macro) - get the current value of the macro macro.clear([macro]) - clear the value of macro if given. Otherwise,
clear all values from the current instance.list() - Print a list of the current application and macro settings to STDOUT.info() - Print an informational listing about the current application and its
associated macro options.help([macro]) - Print help information on the requested macro or revert to
the info() method if no macro name is provided.nextLayer([clear=0]) - Increment the layer counter to its next value and
move to the next layer. This method is particularly useful when displaying or plotting output
as it provides the simplest way to overlay multiple fields on a single chart. If clear
is set to boolean false (default) then the settings from the previous layer are copied directly
to the new layer for modification. If clear is boolean false, then the new layer
starts without any macro definitions.run() - Run the requested application using the macro settings provided by the
user for each layer and throughout each internally-implemented iteration.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
Note that this example makes use of internal looping and of multiple layers. Two
PostScript images will be produced by this script (named
$> 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()
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,
Questions or Comments? Contact our WebMaster.