another interpolation question

11 messages
Open this post in threaded view
|

another interpolation question

 I've seen a lot of discussion about interpolation and would like to add my question to the discussion. I am looking for a (fast as possible) way to interpolate my data from a coarse to fine grid where the limits may not match. Bilinear interpolation is fine. I saw ndimage.map_coordinates but it seems to want i,j coordinates whereas I have 1D lat,lon coordinate arrays. Input: coarse and fine 2D arrays with 1D coordinate arrays Output: data from coarse grid interpolated onto the fine grid Thanks, Bryan _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user bwoods.vcf (355 bytes) Download Attachment
Open this post in threaded view
|

Re: another interpolation question

 On 2/17/11 7:50 AM, Bryan Woods wrote: > I am looking for a (fast as possible) way to interpolate my data from a > coarse to fine grid where the limits may not match. what do you mean by "limits" -- does that mean you may be extrapolating -- always a problem! > I saw ndimage.map_coordinates but it seems to want i,j coordinates > whereas I have 1D lat,lon coordinate arrays. so your input points are not regularly spaced? Ifso, then you need a routine dsigned for that. A couple options: natural neighbor interpolation: See the natgrid toolkit referenced here: http://matplotlib.sourceforge.net/users/toolkits.htmlRadial basis functions: http://www.scipy.org/Cookbook/RadialBasisFunctionsFor straight linear, you should be able to do a delauney triangulation, and simple linear interpolation from that, though I don't know of a package that does this out of the box. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R            (206) 526-6959   voice 7600 Sand Point Way NE   (206) 526-6329   fax Seattle, WA  98115       (206) 526-6317   main reception [hidden email] _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 A couple options: > > natural neighbor interpolation: > > See the natgrid toolkit referenced here: > http://matplotlib.sourceforge.net/users/toolkits.html> Just curious. Where can I find matplotlib examples using natgrid ?   Nils _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 In reply to this post by Chris Barker - NOAA Federal Thu, 17 Feb 2011 09:38:45 -0800, Christopher Barker wrote: [clip] > For straight linear, you should be able to do a delauney triangulation, > and simple linear interpolation from that, though I don't know of a > package that does this out of the box. Scipy 0.9.0, currently at release candidate 3, does Delaunay triangulation based interpolation (linear & cubic) out of the box. -- Pauli Virtanen _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 In reply to this post by Bryan Woods-3 > I am looking for a (fast as possible) way to interpolate my data   > from a coarse to fine grid where the limits may not match. Bilinear   > interpolation is fine. > > I saw ndimage.map_coordinates but it seems to want i,j coordinates   > whereas I have 1D lat,lon coordinate arrays. > > Input: coarse and fine 2D arrays with 1D coordinate arrays > > Output: data from coarse grid interpolated onto the fine grid I'm not sure if I understand the request -- what are the 1D coordinate   arrays for? If you have data on a coarse 2D grid and have a fine 2D   grid defined, doesn't that alone specify the interpolation? Could you provide a simple example, maybe, with a 2x2 input coarse   array, perhaps? Zach _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 On Thu, Feb 17, 2011 at 12:36, Zachary Pincus <[hidden email]> wrote: >> I am looking for a (fast as possible) way to interpolate my data >> from a coarse to fine grid where the limits may not match. Bilinear >> interpolation is fine. >> >> I saw ndimage.map_coordinates but it seems to want i,j coordinates >> whereas I have 1D lat,lon coordinate arrays. >> >> Input: coarse and fine 2D arrays with 1D coordinate arrays >> >> Output: data from coarse grid interpolated onto the fine grid > > I'm not sure if I understand the request -- what are the 1D coordinate > arrays for? If you have data on a coarse 2D grid and have a fine 2D > grid defined, doesn't that alone specify the interpolation? The 1D coordinate arrays are defining the grid points for each axis. E.g. given a 2D array C and the 1D arrays x_coord, y_coord, the data value at C[i,j] will have the "real-world" location x_coord[j], y_coord[i]. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth."   -- Umberto Eco _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 Yes. The idea is that I am using a nested model where I have an outer domain with fixed latitude / longitude coordinates and I want to downscale the data from that outer domain onto a finer inner domain which is contained inside of the outer domain. All the interpolation that I see seeing is to interpolate randomly spaced data onto a fixed grid. I am looking to reproject data from and to fixed grids. Ideally a function that looks something like: z_fine[x_fine|:,y_fine|:] = interp2d(x[:], y[:], z[x|:,y|:], x_fine[:], y_fine[:]) I am very surprised that I can't find a simple function to do a very quick bilinear interpolation. It seems like a very basic operation for gridded data. On 2/17/11 1:41 PM, Robert Kern wrote: > On Thu, Feb 17, 2011 at 12:36, Zachary Pincus<[hidden email]>  wrote: >>> I am looking for a (fast as possible) way to interpolate my data >>> from a coarse to fine grid where the limits may not match. Bilinear >>> interpolation is fine. >>> >>> I saw ndimage.map_coordinates but it seems to want i,j coordinates >>> whereas I have 1D lat,lon coordinate arrays. >>> >>> Input: coarse and fine 2D arrays with 1D coordinate arrays >>> >>> Output: data from coarse grid interpolated onto the fine grid >> I'm not sure if I understand the request -- what are the 1D coordinate >> arrays for? If you have data on a coarse 2D grid and have a fine 2D >> grid defined, doesn't that alone specify the interpolation? > The 1D coordinate arrays are defining the grid points for each axis. > E.g. given a 2D array C and the 1D arrays x_coord, y_coord, the data > value at C[i,j] will have the "real-world" location x_coord[j], > y_coord[i]. > _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user bwoods.vcf (355 bytes) Download Attachment
Open this post in threaded view
|

Re: another interpolation question

 > The idea is that I am using a nested model where I have an outer   > domain with fixed latitude / longitude coordinates and I want to   > downscale the data from that outer domain onto a finer inner domain   > which is contained inside of the outer domain. > > All the interpolation that I see seeing is to interpolate randomly   > spaced data onto a fixed grid. I am looking to reproject data from   > and to fixed grids. Ideally a function that looks something like: > > z_fine[x_fine|:,y_fine|:] = interp2d(x[:], y[:], z[x|:,y|:],   > x_fine[:], y_fine[:]) > > I am very surprised that I can't find a simple function to do a very   > quick bilinear interpolation. It seems like a very basic operation   > for gridded data. If Robert's interpretation of your inputs are correct, it seems then   like you have only some minor rearranging of arrays in order to use   ndimage.map_coordinates to perform precisely this task. map_coordinates takes i,j coordinates in terms of the original array   indices, but given your coordinate arrays it should be pretty trivial   to reformulate your request in terms of (fractional) i,j positions in   the original array, right? You can do this in 1D easily for the x and   y coordinate axes, and then just repeat these values to make the   appropriate coordinate array for map_coordinates. (I can provide more   details if desired.) Also, map_coordinates has various boundary conditions (constant,   mirror, and edge-clamp), which are often useful. Zach > > On 2/17/11 1:41 PM, Robert Kern wrote: >> On Thu, Feb 17, 2011 at 12:36, Zachary   >> Pincus<[hidden email]>  wrote: >>>> I am looking for a (fast as possible) way to interpolate my data >>>> from a coarse to fine grid where the limits may not match. Bilinear >>>> interpolation is fine. >>>> >>>> I saw ndimage.map_coordinates but it seems to want i,j coordinates >>>> whereas I have 1D lat,lon coordinate arrays. >>>> >>>> Input: coarse and fine 2D arrays with 1D coordinate arrays >>>> >>>> Output: data from coarse grid interpolated onto the fine grid >>> I'm not sure if I understand the request -- what are the 1D   >>> coordinate >>> arrays for? If you have data on a coarse 2D grid and have a fine 2D >>> grid defined, doesn't that alone specify the interpolation? >> The 1D coordinate arrays are defining the grid points for each axis. >> E.g. given a 2D array C and the 1D arrays x_coord, y_coord, the data >> value at C[i,j] will have the "real-world" location x_coord[j], >> y_coord[i]. >> > _______________________________________________ > SciPy-User mailing list > [hidden email] > http://mail.scipy.org/mailman/listinfo/scipy-user_______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

Re: another interpolation question

 In reply to this post by Bryan Woods-3 On Thu, 17 Feb 2011 13:51:55 -0500, Bryan Woods wrote: > Yes. > > The idea is that I am using a nested model where I have an outer domain > with fixed latitude / longitude coordinates and I want to downscale the > data from that outer domain onto a finer inner domain which is contained > inside of the outer domain. > > All the interpolation that I see seeing is to interpolate randomly > spaced data onto a fixed grid. I am looking to reproject data from and > to fixed grids. Ideally a function that looks something like: > > z_fine[x_fine|:,y_fine|:] = interp2d(x[:], y[:], z[x|:,y|:], x_fine[:], > y_fine[:]) Yes, we have something like this, but apparently it isn't listed in the docs (aargh!). Try # some random data from numpy import * x = linspace(0, 1, 20) y = linspace(0, 3, 30) z = sin(x)[:,None] * cos(y)[None,:] x_fine = linspace(0, 1, 200) y_fine = linspace(0, 3, 140) from scipy.interpolate import RectBivariateSpline interp = RectBivariateSpline(x, y, z) z_fine = interp(x_fine, y_fine) _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user