[SciPy-User] 2D Interpolation
Bruce Ford
bruce@clearscienceinc....
Fri Jan 8 10:44:45 CST 2010
Jose and Burak, thanks for the lead. Yes. Jose, this is NCEP Renal II
data. I'm trying to interpolate it to a 1 degree grid to plot
alongside other model data that is 1 degree.
I'm not quite there yet, but close. It's possible I'm not visualizing
what this process is doing correctly. Below is a small, trimmed down
script that doesn't use external data so you can see what's happening.
It should work for you. The first plot is of a 73X144 grid all of
the value 1. This represents a 2.5 degree global grid.
The second plot is what I get following the interpolation to a 1
degree grid (181X360). The value of one only appears in a region of
the plot instead of being interpolated across the whole domain.
If you have experience with this, I'm hoping you can tell me what I'm
doing wrong. I'm stumped and I've spent many hours on this problem.
Any assistance would be appreciated!
Here's the script:
*****************************************
import matplotlib.pyplot as pyplot #used to build contour and wind barbs plots
from numpy import *
from sys import exit as die #used to kill the python script early
from scipy import interpolate, ndimage
x,y = mgrid[-90:90:2.5,0:357.5:2.5]
test_array = ones_like(x) #a test array to interpolate from
print "********Shape of Test Array *********",test_array.shape
print "********Shape of X array *********",x.shape #(73,144)
print "********Shape of Y Array *********",y.shape #(73,144)
pyplot.figure()
pyplot.pcolor(y,x,test_array)
pyplot.colorbar()
pyplot.title("Sparsely sampled function.")
pyplot.show()
xnew,ynew = mgrid[-90:91:1,0:360:1]
coords = array([xnew,ynew])
print "********Shape of Coordinate Array *********",coords.shape
interpolated = ndimage.map_coordinates(test_array, coords, order=3)
print "********Shape of Interpolated Array
*********",interpolated.shape #(181,360)
pyplot.figure()
pyplot.pcolor(ynew,xnew,interpolated)
pyplot.colorbar()
pyplot.title("Interpolated function.")
pyplot.show()
---------------------------------------
Bruce W. Ford
Clear Science, Inc.
bruce@clearscienceinc.com
bruce.w.ford.ctr@navy.smil.mil
http://www.ClearScienceInc.com
Phone/Fax: 904-379-9704
8241 Parkridge Circle N.
Jacksonville, FL 32211
Skype: bruce.w.ford
Google Talk: fordbw@gmail.com
On Fri, Jan 8, 2010 at 10:08 AM, Jose Gomez-Dans <jgomezdans@gmail.com> wrote:
> Hi,
>
>
> 2010/1/8 Bruce Ford <bruce@clearscienceinc.com>
>>
>> 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.
>
> Looks suspiciously like NCEP reanalysis data ;) for this task, you could use
> map_coordinates:
> <http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.interpolation.map_coordinates.html>
>
> Hope that helps,
> Jose
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
More information about the SciPy-User
mailing list