from http://matplotlib.github.com/basemap/users/examples.html:
···
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
read in etopo5 topography/bathymetry.
etopodata =
Dataset(‘http://ferret.pmel.noaa.gov/thredds/dodsC/data/PMEL/etopo5.nc’)
topoin = etopodata.variables[‘ROSE’][:]
lons = etopodata.variables[‘ETOPO05_X’][:]
lats = etopodata.variables[‘ETOPO05_Y’][:]
shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topoin,lons,start=False)
plot topography/bathymetry as an image.
create the figure and axes instances.
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8])
setup of basemap (‘lcc’ = lambert conformal conic).
use major and minor sphere radii from WGS84 ellipsoid.
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,
rsphere=(6378137.00,6356752.3142),
resolution=‘l’,area_thresh=1000.,projection=‘lcc’,
lat_1=50.,lon_0=-107.,ax=ax)
transform to nx x ny regularly spaced 5km native projection grid
nx = int((m.xmax-m.xmin)/5000.)+1; ny = int((m.ymax-m.ymin)/5000.)+1
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
…
Line (last but one):
nx = int((m.xmax-m.xmin)/5000.)+1; ny = int((m.ymax-m.ymin)/5000.)+1
(m.xmax-m.xmin) and (m.ymax-m.ymin) are very small compared to their divider 5000, so nx and ny are always 1
Provided link for “etopo5.nc” is desperately slow (~20 Kb/s) so I can’t test the code, but I tried with other dataset (ETOPO2) and I can’t get what “topodat” varable should be. It’s not clear to me from provided documentation.
Thanks in advance for any help