[SciPy-User] Interpolation from a regular grid to a not regular one

Domenico Nappo domenico.nappo at gmail.com
Tue Jun 28 03:38:39 EDT 2011


Hi all,

many thanks for your answers.
I will have a deep look to the mapcoordinates...it seems to be what I need.
Otherwise I'll come back here:)

Have a nice day!

-- 
d

2011/6/25 Davide <davide.lasagna at polito.it>

> Ciao Domenico,
>
> Here is some code i wrote to wrap scipy.ndimage.mapcoordinates.
>
>
> def get_profile( x, y, f, xi, yi, order=3):
>     """Interpolate regular data.
>
>     Parameters
>     ----------
>     x : two dimensional np.ndarray
>         an array for the :math:`x` coordinates
>
>     y : two dimensional np.ndarray
>         an array for the :math:`y` coordinates
>
>     f : two dimensional np.ndarray
>         an array with the value of the function to be interpolated
>         at :math:`x,y` coordinates.
>
>     xi : one dimension np.ndarray
>         the :math:`x` coordinates of the point where we want
>         the function to be interpolated.
>
>     yi : one dimension np.ndarray
>         the :math:`y` coordinates of the point where we want
>         the function to be interpolated.
>
>     order : int
>         the order of the bivariate spline interpolation
>
>
>     Returns
>     -------
>     fi : one dimension np.ndarray
>         the value of the interpolating spline at :math:`xi,yi`
>
>
>     """
>     conditions = [ xi.min() < x.min(),
>                    xi.max() > x.max(),
>                    yi.min() < y.min(),
>                    yi.max() > y.max() ]
>
>     if True in conditions:
>         print "Warning, extrapolation in being done!!"
>
>     dx = x[0,1] - x[0,0]
>     dy = y[1,0] - y[0,0]
>
>     jvals = (xi - x[0,0]) / dx
>     ivals = (yi - y[0,0]) / dy
>
>     coords = np.array([ivals, jvals])
>
>     return  scipy.ndimage.map_coordinates(f, coords, mode='nearest',
> order=order)
>
>
> Buona domenica,
>
>
> Davide
>
> On 06/25/2011 04:23 AM, Zachary Pincus wrote:
> >> lats, longs = latitudes and longitudes of a regular grid (shape is
> (161,201))
> >> vals = corresponding values (shape = (161,201))
> >>
> >> I've got two more 2d numpy arrays which are latitudes and longitudes of
> a non regular grid (shapes are (1900,2400))
> > scipy.ndimage.map_coordinates()
> >
> > A little confusing, very useful. Sorry I've got no time to provide an
> example, but it should be what you want.
> >
> >
> >
> > On Jun 24, 2011, at 8:02 AM, Domenico Nappo wrote:
> >
> >> Hi there,
> >> hope you can help me.
> >>
> >> I'm new to SciPy and I'm not aware of all its nice features.
> >> I need some indications about how to complete the following task...just
> giving me some suggestions about which package/methods to use could be
> enough.
> >>
> >> I have three 2d numpy arrays representing the followings:
> >>
> >> lats, longs = latitudes and longitudes of a regular grid (shape is
> (161,201))
> >> vals = corresponding values (shape = (161,201))
> >>
> >> I've got two more 2d numpy arrays which are latitudes and longitudes of
> a non regular grid (shapes are (1900,2400))
> >>
> >> Now, I've got to produce the grid of values for the non regular grid,
> using interpolation (probably nearest neighbour).
> >> I've come out with something using griddata from the matplotlib.mlab
> module but I'm not sure it's the right way and I don't know how to test the
> interpolated results...
> >>
> >> Many thanks in advance.
> >>
> >> --
> >> dome
> >> _______________________________________________
> >> SciPy-User mailing list
> >> SciPy-User at scipy.org
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User at scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110628/74b52025/attachment.html>


More information about the SciPy-User mailing list