| |
- Basemap
class Basemap |
|
Set up a basemap with one of 17 supported map projections
(cylindrical equidistant, mercator, polyconic, oblique mercator,
transverse mercator, miller cylindrical, lambert conformal conic,
azimuthal equidistant, equidistant conic, lambert azimuthal equal area,
albers equal area conic, gnomonic, orthographic, mollweide,
robinson, cassini-soldner or stereographic).
Doesn't actually draw anything, but sets up the map projection class and
creates the coastline and political boundary polygons in native map
projection coordinates. Requires matplotlib and numarray.
Uses a pyrex interface to C-code from proj.4 (http://proj.maptools.org).
Useful instance variables:
projection - map projection ('cyl','merc','mill','lcc','eqdc','aea','aeqd',
'laea', 'tmerc', 'omerc', 'cass', 'gnom', 'poly', 'ortho', 'robin',
'moll' or 'stere')
aspect - map aspect ratio (size of y dimension / size of x dimension).
llcrnrlon - longitude of lower left hand corner of the desired map domain.
llcrnrlon - latitude of lower left hand corner of the desired map domain.
urcrnrlon - longitude of upper right hand corner of the desired map domain.
urcrnrlon - latitude of upper right hand corner of the desired map domain.
llcrnrx,llcrnry,urcrnrx,urcrnry - corners of map domain in projection coordinates.
rmajor,rminor - equatorial and polar radii of ellipsoid used (in meters).
Example Usage:
(this example plus others can be found in the examples directory of
the source distribution)
>>> from matplotlib.toolkits.basemap import Basemap
>>> import cPickle
>>> from pylab import *
>>> # read in topo data from pickle (on a regular lat/lon grid)
>>> topodict = cPickle.load(open('etopo20.pickle','rb'))
>>> etopo = topodict['data']; lons = topodict['lons']; lats = topodict['lats']
>>> # create Basemap instance for Robinson projection.
>>> m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]))
>>> # compute native map projection coordinates for lat/lon grid.
>>> x, y = m(*meshgrid(lons,lats))
>>> # create figure with same aspect ratio as map.
>>> figure(figsize=(10,m.aspect*10)).add_axes([0.1,0.1,0.8,0.8],frameon=False)
>>> # make filled contour plot.
>>> levels, colls = m.contourf(x,y,etopo,30,cmap=cm.jet,colors=None)
>>> m.drawcoastlines() # draw coastlines
>>> m.drawmapboundary() # draw a line around the map region
>>> m.drawparallels(arange(-90.,120.,30.),labels=[1,0,0,0]) # draw parallels
>>> m.drawmeridians(arange(0.,420.,60.),labels=[0,0,0,1]) # draw meridians
>>> title('Robinson Projection') # add a title
>>> show()
Version: 0.5 (20050602)
Contact: Jeff Whitaker <jeffrey.s.whitaker@noaa.gov> |
|
Methods defined here:
- __call__(self, x, y, inverse=False)
- Calling a Basemap class instance with the arguments lon, lat will
convert lon/lat (in degrees) to x/y native map projection
coordinates (in meters). If optional keyword 'inverse' is
True (default is False), the inverse transformation from x/y
to lon/lat is performed.
For cylindrical equidistant projection ('cyl'), this
does nothing (i.e. x,y == lon,lat).
lon,lat can be either scalar floats or N arrays.
- __init__(self, llcrnrlon=-180.0, llcrnrlat=-90.0, urcrnrlon=180.0, urcrnrlat=90.0, projection='cyl', resolution='c', area_thresh=10000.0, rsphere=6370997, lat_ts=None, lat_1=None, lat_2=None, lat_0=None, lon_0=None, lon_1=None, lon_2=None, suppress_ticks=True)
- create a Basemap instance.
arguments:
projection - map projection. 'cyl' - cylindrical equidistant, 'merc' -
mercator, 'lcc' - lambert conformal conic, 'stere' - stereographic,
'aea' - albers equal area conic, 'tmerc' - transverse mercator,
'aeqd' - azimuthal equidistant, 'mill' - miller cylindrical,
'eqdc' - equidistant conic, 'laea' - lambert azimuthal equal area,
'cass' - cassini-soldner (transverse cylindrical equidistant),
'poly' - polyconic, 'omerc' - oblique mercator, 'ortho' - orthographic,
'moll' - mollweide, 'robin' - robinson,
and 'gnom' - gnomonic are currently available. Default 'cyl'.
llcrnrlon - longitude of lower left hand corner of the desired map domain
(Default -180).
llcrnrlat - latitude of lower left hand corner of the desired map domain
(Default -90).
urcrnrlon - longitude of upper right hand corner of the desired map domain
(Default 180).
urcrnrlat - latitude of upper right hand corner of the desired map domain
(Default 90).
If the orthographic, mollweide or robinson projection is chosen
the values of llcrnrlon,llcrnrlat,urcrnrlon and urcrnrlat are ignored,
and the entire projection domain will be always be plotted.
resolution - resolution of coastline database to use. Can be 'c' (crude),
'l' (low), or 'i' (intermediate). Resolution drops off by roughly 80%
between datasets. Higher res datasets are much slower to draw.
Default 'c'. Coastline data is from the GSHHS
(http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html).
area_thresh - coastline with an area smaller than area_thresh in km^2
will not be plotted. Default 10,000.
rsphere - radius of the sphere used to define map projection (default
6370997 meters, close to the arithmetic mean radius of the earth). If
given as a sequence, the first two elements are interpreted as
the the radii of the major and minor axes of an ellipsoid. Note: sometimes
an ellipsoid is specified by the major axis and an 'inverse flattening
parameter' (if). The minor axis (b) can be computed from the major axis (a)
and the inverse flattening parameter using the formula if = a/(a-b).
suppress_ticks - suppress automatic drawing of axis ticks and labels
in map projection coordinates. Default False, so parallels and meridians
can be labelled instead. If parallel or meridian labelling is requested
(using drawparallels and drawmeridians methods), automatic tick labelling
will be supressed even is suppress_ticks=False. Typically, you will
only want to override the default if you want to label the axes in meters
using native map projection coordinates.
The following parameters are map projection parameters which all default to
None. Not all parameters are used by all projections, some are ignored.
lat_ts - latitude of natural origin (used for mercator and stereographic
projections).
lat_1 - first standard parallel for lambert conformal, albers
equal area projection and equidistant conic projections. Latitude of one
of the two points on the projection centerline for oblique mercator.
lat_2 - second standard parallel for lambert conformal, albers
equal area projection and equidistant conic projections. Latitude of one
of the two points on the projection centerline for oblique mercator.
lon_1 - Longitude of one of the two points on the projection centerline
for oblique mercator.
lon_2 - Longitude of one of the two points on the projection centerline
for oblique mercator.
lat_0 - central latitude (y-axis origin) - used by stereographic, polyconic,
transverse mercator, miller cylindrical, cassini-soldner, oblique mercator,
gnomonic, equidistant conic, orthographic and lambert azimuthal projections).
lon_0 - central meridian (x-axis origin) - used by stereographic, polyconic,
transverse mercator, miller cylindrical, cassini-soldner, mollweide, robinson,
gnomonic, equidistant conic, orthographic and lambert azimuthal projections).
- contour(self, x, y, data, *args, **kwargs)
- Make a contour plot over the map (see pylab contour documentation).
- contourf(self, x, y, data, *args, **kwargs)
- Make a filled contour plot over the map (see pylab documentation).
- drawcoastlines(self, linewidth=1.0, color='k', antialiased=1)
- Draw coastlines.
linewidth - coastline width (default 1.)
color - coastline color (default black)
antialiased - antialiasing switch for coastlines (default True).
- drawcountries(self, linewidth=0.5, color='k', antialiased=1)
- Draw country boundaries.
linewidth - country boundary line width (default 0.5)
color - country boundary line color (default black)
antialiased - antialiasing switch for country boundaries (default True).
- drawgreatcircle(self, lon1, lat1, lon2, lat2, dtheta=0.02, **kwargs)
- draw a great circle on the map.
lon1,lat1 - longitude,latitude of one endpoint of the great circle.
lon2,lat2 - longitude,latitude of the other endpoint of the great circle.
dtheta - points on great circle computed every dtheta radians (default 0.02).
Other keyword arguments (**kwargs) control plotting of great circle line,
see pylab plot documentation for details.
Note: cannot handle situations in which the great circle intersects
the edge of the map projection domain, and then re-enters the domain.
- drawmapboundary(self, color='k', linewidth=1.0)
- draw boundary around map projection region
- drawmeridians(self, meridians, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1], labels=[0, 0, 0, 0], font='rm', fontsize=12, xoffset=None, yoffset=None)
- draw meridians (longitude lines).
meridians - list containing longitude values to draw (in degrees).
color - color to draw meridians (default black).
linewidth - line width for meridians (default 1.)
linestyle - line style for meridians (default '--', i.e. dashed).
dashes - dash pattern for meridians (default [1,1], i.e. 1 pixel on,
1 pixel off).
labels - list of 4 values (default [0,0,0,0]) that control whether
meridians are labelled where they intersect the left, right, top or
bottom of the plot. For example labels=[1,0,0,1] will cause meridians
to be labelled where they intersect the left and bottom of the plot,
but not the right and top. Labels are drawn using mathtext.
font - mathtext font used for labels ('rm','tt','it' or 'cal', default 'rm').
fontsize - font size in points for labels (default 12).
xoffset - label offset from edge of map in x-direction
(default is 0.01 times width of map in map projection coordinates).
yoffset - label offset from edge of map in y-direction
(default is 0.01 times height of map in map projection coordinates).
- drawparallels(self, circles, color='k', linewidth=1.0, linestyle='--', dashes=[1, 1], labels=[0, 0, 0, 0], font='rm', fontsize=12, xoffset=None, yoffset=None)
- draw parallels (latitude lines).
circles - list containing latitude values to draw (in degrees).
color - color to draw parallels (default black).
linewidth - line width for parallels (default 1.)
linestyle - line style for parallels (default '--', i.e. dashed).
dashes - dash pattern for parallels (default [1,1], i.e. 1 pixel on,
1 pixel off).
labels - list of 4 values (default [0,0,0,0]) that control whether
parallels are labelled where they intersect the left, right, top or
bottom of the plot. For example labels=[1,0,0,1] will cause parallels
to be labelled where they intersect the left and bottom of the plot,
but not the right and top. Labels are drawn using mathtext.
font - mathtext font used for labels ('rm','tt','it' or 'cal', default 'rm').
fontsize - font size in points for labels (default 12).
xoffset - label offset from edge of map in x-direction
(default is 0.01 times width of map in map projection coordinates).
yoffset - label offset from edge of map in y-direction
(default is 0.01 times height of map in map projection coordinates).
- drawstates(self, linewidth=0.5, color='k', antialiased=1)
- Draw state boundaries in Americas.
linewidth - state boundary line width (default 0.5)
color - state boundary line color (default black)
antialiased - antialiasing switch for state boundaries (default True).
- fillcontinents(self, color=0.80000000000000004)
- Fill continents.
color - color to fill continents (default gray).
After filling continents, lakes are re-filled with axis background color.
- gcpoints(self, lon1, lat1, lon2, lat2, npoints)
- compute npoints points along a great circle with endpoints
(lon1,lat1) and (lon2,lat2). Returns numarrays x,y
with map projection coordinates.
- imshow(self, *args, **kwargs)
- Display an image over the map (see pylab imshow documentation).
extent and origin keywords set automatically so image will be drawn
over map region.
- makegrid(self, nx, ny, returnxy=False)
- return arrays of shape (ny,nx) containing lon,lat coordinates of
an equally spaced native projection grid.
if returnxy = True, the x,y values of the grid are returned also.
- pcolor(self, x, y, data, **kwargs)
- Make a pseudo-color plot over the map.
see pylab pcolor documentation for definition of **kwargs
- plot(self, *args, **kwargs)
- Draw lines and/or markers on the map (see pylab plot documentation).
- quiver(self, x, y, u, v, scale=None, **kwargs)
- Make a vector plot (u, v) with arrows on the map projection grid (x,y)
If scale is specified, it is used to scale the vectors. If scale=None
(default) arrows are scaled to longest one is equal to the maximum
distance between grid points.
Extra keyword arguments (**kwargs) passed to pylab.quiver (see pylab
quiver documentation for details).
- rotate_vector(self, uin, vin, lons, lats, returnxy=False)
- rotate a vector field (uin,vin) on a rectilinear lat/lon grid
with longitudes = lons and latitudes = lats from geographical into map
projection coordinates.
Differs from transform_vector in that no interpolation is done,
the vector is returned on the same lat/lon grid, but rotated into
x,y coordinates.
lons, lats must be rank-2 arrays containing longitudes and latitudes
(in degrees) of grid.
if returnxy=True, the x and y values of the lat/lon grid
are also returned (default False).
The input vector field is defined in spherical coordinates (it
has eastward and northward components) while the output
vector field is rotated to map projection coordinates (relative
to x and y). The magnitude of the vector is preserved.
- scatter(self, *args, **kwargs)
- Plot points with markers on the map (see pylab scatter documentation).
- set_axes_limits(self)
- Set axis limits for map domain using current axes instance.
- transform_scalar(self, datin, lons, lats, nx, ny, returnxy=False, **kwargs)
- interpolate a scalar field (datin) from a lat/lon grid with longitudes =
lons and latitudes = lats to a (ny,nx) native map projection grid.
lons, lats must be rank-1 arrays containing longitudes and latitudes
(in degrees) of datin grid in increasing order
(i.e. from Greenwich meridian eastward, and South Pole northward).
if returnxy=True, the x and y values of the native map projection grid
are also returned.
See interp documentation for meaning of extra keyword arguments (**kwargs).
data on a lat/lon grid must be transformed to map projection coordinates
before it can be plotted on the map with imshow.
- transform_vector(self, uin, vin, lons, lats, nx, ny, returnxy=False, **kwargs)
- rotate and interpolate a vector field (uin,vin) from a lat/lon grid
with longitudes = lons and latitudes = lats to a
(ny,nx) native map projection grid.
lons, lats must be rank-1 arrays containing longitudes and latitudes
(in degrees) of datin grid in increasing order
(i.e. from Greenwich meridian eastward, and South Pole northward).
The input vector field is defined in spherical coordinates (it
has eastward and northward components) while the output
vector field is rotated to map projection coordinates (relative
to x and y). The magnitude of the vector is preserved.
if returnxy=True, the x and y values of the native map projection grid
are also returned (default False).
See interp documentation for meaning of extra keyword arguments (**kwargs).
| |