[SciPy-User] another interpolation question

Zachary Pincus zachary.pincus at yale.edu
Thu Feb 17 14:05:46 EST 2011


> 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<zachary.pincus at yale.edu>  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].
>>
> <bwoods.vcf>_______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list