## Re: [Matplotlib-users] Basemap interp

 Re: [Matplotlib-users] Basemap interp From: Friedrich Romstedt - 2010-02-26 07:28:16 ```2010/2/26 Andrew Charles : > Aye, now that I read the docstring with a rested pair of eyes it's > clear that xout and yout are meshgrids (rank 2 arrays). Thanks, > problem solved. For convenience, I recently heard about numpy.meshgrid, which does the job for you. See its __doc__, but it's fairly easy: numpy.meshgrid(x, y). Friedrich ```

 [Matplotlib-users] Basemap interp From: Andrew Charles - 2010-02-25 06:21:08 ```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? ------------------------- Andrew Charles ```
 Re: [Matplotlib-users] Basemap interp From: Friedrich Romstedt - 2010-02-25 08:27:12 ```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 : > 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). Friedrich ```
 Re: [Matplotlib-users] Basemap interp From: Andrew Charles - 2010-02-26 01:09:55 ```On Thu, Feb 25, 2010 at 7:26 PM, Friedrich Romstedt wrote: > 2010/2/25 Andrew Charles : >> 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 Aye, now that I read the docstring with a rested pair of eyes it's clear that xout and yout are meshgrids (rank 2 arrays). Thanks, problem solved. ------------------------- Andrew Charles ```
 Re: [Matplotlib-users] Basemap interp From: Friedrich Romstedt - 2010-02-26 07:28:16 ```2010/2/26 Andrew Charles : > Aye, now that I read the docstring with a rested pair of eyes it's > clear that xout and yout are meshgrids (rank 2 arrays). Thanks, > problem solved. For convenience, I recently heard about numpy.meshgrid, which does the job for you. See its __doc__, but it's fairly easy: numpy.meshgrid(x, y). Friedrich ```