[SciPy-User] 2D Interpolation

Bruce Ford bruce@clearscienceinc....
Thu Jan 7 18:43:21 CST 2010


I'm endeavoring to interpolate global 2.5 degree data (73x144) onto a
1 degree grid (181x360).  I'm not sure if I'm barking up the right
tree for a cubic spline interpolation.

Below is my code based on an example I found at:

The process is hanging at the line "tck = interpolate.bisplrep(x,y,z,s=0)".

I'm unsure if this is a bug or is there an error in my code (which is below)?

Secondly, has anyone done a similar interpolation (from a lower
resolution regular 2D grid to a higher regular 2D grid) that would
share a little code?  All my efforts have been fruitless!

Thanks in advance!


(code follows...)
import matplotlib
import matplotlib.pyplot as pyplot #used to build contour and wind barbs plots
import matplotlib.colors as pycolors #used to build color schemes for plots
import numpy.ma as M #matrix manipulation functions
import numpy as np #used to perform simple math functions on data
from numpy import *
import cgi #used to easily parse form variables
from sys import exit as die #used to kill the python script early
from netCDF4 import Dataset  #interprets NetCDF files
import Nio
from scipy import interpolate

filepath = "/media/BACKUP1/reanal-2/6hr/pgb/pgb.197901"
grb_file = Nio.open_file(filepath, mode='r', options=None, history='',

z = grb_file.variables["HGT_2_ISBL_10"][1,1,:,:]
print z.shape

x,y = np.mgrid[90:-90:73j,0:357.5:144j]

print x.shape  #(73,144)
print y.shape  #(73,144)
print z.shape #(73,144)

xnew,ynew = np.mgrid[-90:90:180j,0:359:360j]
print xnew.shape #(180,360)
tck = interpolate.bisplrep(x,y,z,s=0)
#python freezes on the above line
znew = interpolate.bisplev(xnew[:,0],ynew[0,:],tck)

Bruce W. Ford
Clear Science, Inc.
8241 Parkridge Circle N.
Jacksonville, FL  32211
Skype:  bruce.w.ford
Google Talk: fordbw@gmail.com

More information about the SciPy-User mailing list