[SciPy-user] Help interpolating equally spaced 2D gridded data to a different grid.

Lorenzo Bolla lbolla at gmail.com
Sat Jul 19 12:06:41 EDT 2008


something like this should work (adjust the dimensions as you wish):

----------------------------------------
import numpy
from scipy.interpolate import interp2d

x = numpy.linspace(0, 1, 27)
y = numpy.linspace(0, 1, 34)

lat_old, lon_old = numpy.meshgrid(y, x)
precip_old = numpy.sin(lat_old + lon_old)

print lat_old.shape
print lon_old.shape
print precip_old.shape

x_new = numpy.linspace(0, 1, 20)
y_new = numpy.linspace(0, 1, 16)

lat, lon = numpy.meshgrid(y_new, x_new)
precip_interp = interp2d(lat_old, lon_old, precip_old)
precip = precip_interp(y_new, x_new)

print lat.shape
print lon.shape
print precip.shape
----------------------------------------

hth,
L.



On Fri, Jul 18, 2008 at 02:05:34PM -0500, Dharhas Pothina wrote:
> Hi,
> 
> I have a regular grid of data :
> 
> lat_old.shape = (277, 349)
> lon_old.shape = (277, 349)
> precip_old.shape = (8, 277, 349) # the first axis is time 
> 
> I need to interpolate precip_old to a new regular grid (lat,lon) where 
> 
> lat.shape = (204, 160)
> lon.shape = (204, 160)
> 
> Basically I need to calculate  precip_new where precip_new.shape = (8, 204, 160)
> 
> I've had a look at the cookbook page for 'N-D interpolation for equally-spaced data' and also some of the documentation for interp2D etc but am having trouble understanding what I need to do.
> 
> Any help is appreciated.
> 
> thanks
> 
> - dharhas
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list