Andrew, I sent this to you personally, unintentionally, and want it to
be on the list too. So you have it doubled now, sorry.
2010/2/25 Andrew Charles <ac1201@...287...>:
I'm trying to interpolate from one grid to another using Basemap's
interp function. It seems to want the lat and lon axis of the new grid
to have the same shape:
3524 if xout.shape != yout.shape:
3535 raise ValueError, 'xout and yout must have same shape!'
The grid I'm interpolating to is 144 by 72
I'm calling it as interp(x,lon,lat,plon,plat)
where lon and plon are numpy arrays with shape (144,) lat has shape
(73,) plat has shape(72,) and x has shape (72, 144)
Does interp() really only work if the target grid is square?
I guess it wants a meshgrid, use e.g.:
lats = len(lat)
lons = len(lon)
lat = lat[:, numpy.newaxis].repeat(lons, axis = 1)
lon = lon[numpy.newaxis, :].repeat(lats, axis = 0)
- or the other way round -
lat = lat[numpy.newaxis, :].repeat(lons, axis = 0)
lon = lat[:, numpy.newaxis].repeat(lats, axis = 1)
depending on what axis lat and lon should respectively be associated with.
A meshgrid is a sequence of coordinate grids. For each point KEY, the
coordinates are MESHGRID[:, KEY]. Thus you can via meshgrids specifiy
also distorted grids to interpolate to (e.g. a wavy rectangular grid
or something). (I guess this is actually needed when doing Mercator
to Postels or similar).