Scipy's RectBivariateSpline returns wrong value?
<p>Trying to interpolate data from a regular input grid, and came across this in the documentation for <code>scipy.interpolate.interp2d</code>:</p>

<blockquote>
  <p>See also RectBivariateSpline Much faster 2D interpolation if your
  input data is on a grid</p>
</blockquote>

<p>So I tried using <code>scipy.interpolate.RectBivariateSpline</code> instead of <code>interp2d</code>. Docs for both functions seem very similar, so I expected this to produce similar results:</p>

<pre><code>import numpy as np
from scipy.interpolate import RectBivariateSpline, interp2d

from .constants import data


x_coords = y_coords = np.arange(data.shape[0])  # Square array
interp_fun = interp2d(x_coords, y_coords, data)
bivar_fun = RectBivariateSpline(x_coords, y_coords, data)

data[250, 60]  # 76.1451873779
interp_fun(60, 250)  # 76.14518738
bivar_fun(60, 250, grid=False)  # 345.24444
</code></pre>

<p>Am I calling this wrong? I have no idea why the interpolation based on <code>RectBivariateSpline</code> is so far off?</p>

<p>I did suspect that maybe <code>RectBivariateSpline</code> operates on a cartesian grid and inverted the y-Axis of input data, but still no luck.</p>

<p>Right, just before submitting this I thought I should try calling <code>bivar_fun(y, x)</code> instead of <code>bivar_fun(x, y)</code> and things suddenly work:</p>

<pre><code>data[250, 60]  # 76.1451873779
interp_fun(60, 250)  # 76.14518738
bivar_fun(250, 60, grid=False)  # [ 76.14518738]
</code></pre>

<p>Still not quite sure why, because the first arguments to <code>interp_fun</code> and <code>bivar_fun</code> should be the same:</p>

<blockquote>
  <p><code>RectBivariateSpline.__call__(x, y, mth=None, dx=0, dy=0, grid=True)</code></p>
</blockquote>

<p><a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.RectBivariateSpline.__call__.html#scipy.interpolate.RectBivariateSpline.__call__" rel="nofollow">RectBivariateSpline Docs</a></p>

<blockquote>
  <p><code>interp2d.__call__(x, y, dx=0, dy=0)</code></p>
</blockquote>

<p><a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.__call__.html#scipy.interpolate.interp2d.__call__" rel="nofollow">Interp2d Docs</a></p>

<p>There's also a related issue on Github: <a href="https://github.com/scipy/scipy/issues/3164" rel="nofollow">https://github.com/scipy/scipy/issues/3164</a></p>

python numpy scipy