Package gmt ::
Module gmt
|
|
Module gmt.gmt
Introduction
Python module for creating plots with GMT (Generic Mapping Tools).
Provides a pythonic, object-oriented interface to GMT for plotting
Numeric arrays. A subset of GMT's plotting capabilities are supported,
including:
-
Contour, boxfill or windbarb maps on various map projections
including linear, cylindrical, lambert conformal, orthographic,
lambert azimuthal equal area, mercator, north polar stereographic,
south polar stereographic, and general stereographic.
-
Drawing of symbols, text, lines, curves and polygons on
maps.
-
Overlaying plots.
-
Easy creation of multi-panel figures.
-
simple x-y line plots.
Download
Requirements
The GMT and ghostscript binaries must be in the unix
$PATH.
Example usage
-
create a class instance:
>>> x = GMT() # see below for optional keyword arguments).
-
plot a basemap:
>>> x.basemap() # see below for class attributes that can be set
>>> # to affect how the basemap is drawn.
-
create some GMT 'grdfiles' to plot:
>>> datgrd = x.wrtgrd(data,lons,lats)
>>> ugrd = x.wrtgrd(u,lons,lats) # zonal winds.
>>> vgrd = x.wrtgrd(v,lons,lats) # meridional winds.
-
plot some contours:
>>> x.contour(datgrd) # see below for relevant class attributes.
-
draw some windbarbs:
>>> x.windbarbs(ugrd,vgrd) # see below for relevant class attributes.
-
draw some symbols and text:
>>> x.drawsymbol(40,254.7,symbol='c',color=(255,0,0))
>>> xpos,ypos = x.latlontoxy(40,254.7) # convert from lat/lon to x/y.
>>> x.drawtext('Boulder',xpos,ypos,offset=0.1,justify='CB')
-
save the grd file for future usage (otherwise it will be lost
when close method called):
>>> savegrd(datgrd,'dat.grd')
-
close the class instance, cleanup temp files, save
postscript:
>>> x.close(psfilename='test.eps')
-
or, instead of saving postscript to file, save in a StringIO
instance (useful if the figure is going to be part of a multi-panel
plot - see info on PanelPlot class below):
>>> figpanel = x.close() # figpanel is a StringIO instance
Real examples
are included in the source distribution (in the examples directory).
Execute the module source code (gmt.py) as a standalone script to run a
simple test.
Version: 20041114
Author: Jeffrey Whitaker with contributions from Julien Vienne.
Contact: Jeff Whitaker
Copyright: copyright 2004 by Jeffrey Whitaker.
License: Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
Bug: contourfill doesn't work when proj = 'ortho' (use boxfill=True
instead).
Classes |
GMT |
Generic Mapping Tools (GMT) plot class. |
PanelPlot |
create multi-panel plots of same-sized figures using the PyX
module. |
Function Summary |
|
addcyclic (arrin,
lonsin)
add cyclic (wraparound) point in longitude. |
|
epstoimage (psfile,
imgfile,
xsize,
ysize,
format)
converts eps file to png, gif or jpeg. |
|
getcint (mind,
maxd,
num_lev)
returns sane contour interval given max,min and approx number of
levels. |
|
readgrd (grdname)
read attributes from a saved grd file, returns dictionary with grd
file metadata. |
|
savegrd (grd,
grdname)
save a grd file (otherwise it will be deleted when the close method of
the GMT class instance is called). |
addcyclic(arrin,
lonsin)
add cyclic (wraparound) point in longitude.
-
- Parameters:
arrin -
input rank-2 Numeric array. 1st dimension is assumed to be
latitude, 2nd dimension longitude. Data is assumed to equally
equally spaced in longitude.
lonsin -
input longitudes (corresponding to second dimension of
arrin).
- Returns:
-
arrout - rank-2 Numeric array with cyclic
wraparound point added. If input array has shape
(nlats,nlons) output array has shape
(nlats,nlons+1) . lonsout -
rank-1 Numeric array with longitudes corresponding to second
dimension of arrout . Equal to
lonsin with extra value added at end which is
identical the lonsin[0] .
|
epstoimage(psfile,
imgfile=False,
xsize=512,
ysize=512,
format='png')
converts eps file to png, gif or jpeg. Creates a nicer looking image
by increasing the resolution of the postscript by 3, then reducing the
size of the resulting image by 1/3 (with blurring). Requires ps2ppm and netpbm. If these are not available, the
routine prints and error message and returns 1. If the image is created
successfully, returns 0.
-
- Parameters:
psfile -
input postscript filename (must end in '.eps').
- Keyword Parameters:
imgfile -
output image filename. If not specified, image filename is
input filename with '.eps' replaced by '.png', '.gif', or
'.jpg'.
xsize -
width of image in pixels (default 512).
ysize -
height of image in pixels (default 512).
format -
format of image ('png', 'gif' or 'jpg', default 'png')
|
getcint(mind,
maxd,
num_lev)
returns sane contour interval given max,min and approx number of
levels.
-
- Parameters:
mind -
lowest contour level desired.
maxd -
highest contour level desired.
num_lev -
approximate number of contour levels desired.
- Returns:
-
cint - contour interval.
|
readgrd(grdname)
read attributes from a saved grd file, returns dictionary with grd
file metadata.
-
- Parameters:
grdname -
(string) grdname - name of grd file to read.
- Returns:
-
grdfile - dictionary containing grd file
metadata.
|
savegrd(grd,
grdname)
save a grd file (otherwise it will be deleted when the close method
of the GMT class instance is called).
-
- Parameters:
grd -
dictionary containing grd file metadata (returned from
previous wrtgrd or readgrd call).
grdname -
(string) copy grd file to file with this name.
|