Menu

[r2194]: / trunk / toolkits / basemap / examples / polarmaps.py  Maximize  Restore  History

Download this file

111 lines (101 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
# make plots of etopo bathymetry/topography data on
# various map projections, drawing coastlines, state and
# country boundaries, filling continents and drawing
# parallels/meridians
# illustrates special-case polar-centric projections.
from matplotlib.toolkits.basemap import Basemap, shiftgrid
from pylab import *
# read in topo data (on a regular lat/lon grid)
# longitudes go from 20 to 380.
topodatin = array(load('etopo20data.gz'),'d')
lonsin = array(load('etopo20lons.gz'),'d')
latsin = array(load('etopo20lats.gz'),'d')
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topodatin,lonsin,start=False)
lats = latsin
print 'min/max etopo20 data:'
print min(ravel(topoin)),max(ravel(topoin))
boundinglat = 20.
projs = ['laea','stere','aeqd']
projnames = ['Lambert Azimuthal Equal Area','Stereographic','Azimuthal Equidistant']
for proj,projname in zip(projs,projnames):
# setup stereographic map projection (Southern Hemisphere).
# centered on Australia
lon_0 = 130.
m = Basemap(boundinglat=-boundinglat,lon_0=lon_0,\
resolution='c',area_thresh=10000.,projection='sp'+proj)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# setup figure with same aspect ratio as map.
fig = figure(figsize=(10,6))
ax = fig.add_subplot(121)
# plot image over map.
im = m.imshow(topodat,cm.jet)
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
parallels = arange(-80.,90,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,60.)
m.drawmeridians(meridians)
title('South Polar '+projname,y=1.075)
# setup of basemap ('ortho' = orthographic projection)
m = Basemap(projection='ortho',
resolution='c',area_thresh=10000.,lat_0=-90,lon_0=lon_0-180.)
ax = fig.add_subplot(122)
x,y = m(*meshgrid(lonsin,latsin))
cs = m.contourf(x,y,topodatin,20,cmap=cm.jet)
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
parallels = arange(-80.,90,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,60.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
title('South Polar Orthographic',y=1.075)
show()
# setup stereographic map projection (Northern Hemisphere).
# centered on US
lon_0 = -90.
m = Basemap(boundinglat=boundinglat,lon_0=lon_0,\
resolution='c',area_thresh=10000.,projection='np'+proj)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
# setup figure with same aspect ratio as map.
fig = figure(figsize=(10,6))
ax = fig.add_subplot(121)
# plot image over map.
im = m.imshow(topodat,cm.jet)
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
parallels = arange(-80.,90,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,60.)
m.drawmeridians(meridians)
title('North Polar '+projname,y=1.075)
# setup of basemap ('ortho' = orthographic projection)
m = Basemap(projection='ortho',
resolution='c',area_thresh=10000.,lat_0=90,lon_0=lon_0)
ax = fig.add_subplot(122)
x,y = m(*meshgrid(lonsin,latsin))
cs = m.contourf(x,y,topodatin,20,cmap=cm.jet)
# draw coastlines and political boundaries.
m.drawcoastlines()
# draw parallels and meridians (labelling is
# not implemented for orthographic).
parallels = arange(-80.,90,20.)
m.drawparallels(parallels)
meridians = arange(0.,360.,60.)
m.drawmeridians(meridians)
# draw boundary around map region.
m.drawmapboundary()
title('North Polar Orthographic',y=1.075)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.