Which scipy function should I use to interpolate from a rectangular grid to regularly spaced rectangular grid in 2D?
<p>I pretty new to python, and I'm looking for the most efficient pythonic way to interpolate from a grid to another one.
The original grid is a structured grid (the terms regular or rectangular grid are also used), and the spacing is not uniform.
The new grid is a regularly spaced grid. Both grids are 2D. For now it's ok using a simple interpolation method like linear interpolation, pheraps in the future I could try something different like bicubic.</p>

<p>I'm aware that there are methods to interpolate from an irregular grid to a regular one, however given the regular structure of my original grid, more efficient methods should be available.</p>

<p>After searching in the scipy docs, I have found 2 methods that seem to fit my case:  <code>scipy.interpolate.RegularGridInterpolator</code> and <code>scipy.interpolate.RectBivariateSpline</code>.
I don't understand the difference between the two functions, which one should I use?
Is the difference purely in the interpolation methods? Also, while the non-uniform spacing of the original grid is explicitly mentioned in <code>RegularGridInterpolator</code>, <code>RectBivariateSpline</code> doc is silent about it.</p>

<p>Thanks,</p>

<p>Andrea</p>

<h1>RectBivariateSpline</h1>

<p>Imagine your grid as a canyon, where the high values are peaks and the low values are valleys. The bivariate spline is going to try to fit a thin sheet over that canyon to interpolate. This will still work on irregularly space input, as long as the x and y array you supply are also irregularly spaced, and everything still lies on a rectangular grid.</p>

<h1>RegularGridInterpolator</h1>

<p>Same canyon, but now we'll linearly interpolate the surrounding gridpoints to interpolate. We'll assume the input data is regularly space to save some computation. It sounds like this won't work for you. </p>

<h1>Now What?</h1>

<p>Both of these map 2D-1D. It sounds like you have an input space with irregular, but rectangularly space sample points, and an output space with regularly spaced sample points. You might just try LinearNDInterpolator, since you're in 2D it won't be that much more expensive.</p>

<p>If you're trying to interpolate a mapping between two 2D things, you'll want to do two interpolations, one that interpolates (x1, y1) -> x2 and one that interpolates (x1, y1) -> y2. </p>

<p>Vstacking the output of those will give you an array of points in your output space. </p>

<p>I don't know of a more efficient method in scipy for taking advantage of the expected structure of the interpolation output, given an irregular grid input.</p>

python numpy scipy grid