My problem starts with scipy 1.2.3 and its function scipy.interpolate.griddata which performs an interpolation and provides me a reference dataset. (I'm interested in cubic 2d interpolation see the test case below)
After updating scipy to scipy 1.5.2, I can’t generate exactly the same results as before...and the differences are not negligibles.
By testing previous versions of scipy made available in my anaconda distribution, I generate exactly the initial interpolated results if I install scipy 1.3.2.
So I think griddata or one of its sub-components was updated after scipy 1.3.2.
But I can’t find any explanation about it in the Scipy release notes: Scipy.org Release Notes, nothing in the history for scipy/scipy/interpolate/ndgriddata.py on GitHub History ndgriddata, nothing in the history for scipy/scipy/interpolate/interpnd.pyx on GitHub History interpnd. Maybe I don't see something evident ?
Has anyone ever encountered this problem : updating scipy has changed the results given by scipy.interpolate.griddata ?
To make a test case I have borrowed some code from : how-can-i-perform-two-dimensional-interpolation-using-scipy (thanks a lot)
from scipy.interpolate import griddata
import numpy as np
# scipy 1.2.3 or (scipy 1.3.2) reference dataset
z_griddata_scipy_1_2_3 = np.array([[1.22464680e-16, 2.99260075e-02, 4.64921877e-02, 3.63387200e-02,
-1.17334278e-02, -4.10790167e-02, -3.53276896e-02, -1.32599029e-02,
6.57516828e-03, 1.46193750e-02, 1.29942167e-02, 4.60176170e-03,
-1.02398072e-02, -3.13455739e-02, -3.89274672e-02, -1.15549286e-02,
3.59960447e-02, 4.60537630e-02, 2.96438015e-02, 1.22464680e-16],
[3.06593878e-01, 2.94590471e-01, 2.55311166e-01, 1.72704804e-01,
6.75755257e-02, -8.71796149e-02, -1.69793095e-01, -2.16754270e-01,
-2.45929090e-01, -2.64204208e-01, -2.83893302e-01, -2.86038057e-01,
-2.52505900e-01, -1.93389278e-01, -9.70877464e-02, 6.22252315e-02,
1.64062151e-01, 2.49498113e-01, 2.91797267e-01, 3.07425460e-01]])
# auxiliary function for mesh generation
def gimme_mesh(n):
minval = -1
maxval = 1
# produce an asymmetric shape in order to catch issues with transpositions
return np.meshgrid(np.linspace(minval, maxval, n), np.linspace(minval, maxval, n+1))
# set up underlying test functions, vectorized
def fun_smooth(x, y):
return np.cos(np.pi * x)*np.sin(np.pi * y)
def test_griddata_cubic():
# sparse input mesh, 6x7 in shape
N_sparse = 6
x_sparse, y_sparse = gimme_mesh(N_sparse)
z_sparse_smooth = fun_smooth(x_sparse, y_sparse)
# dense output mesh, 20x21 in shape
N_dense = 20
x_dense, y_dense = gimme_mesh(N_dense)
z_griddata_scipy_test = griddata(np.array([x_sparse.ravel(), y_sparse.ravel()]).T,
z_sparse_smooth.ravel(),
(x_dense, y_dense),
method='cubic')
try:
np.testing.assert_almost_equal(z_griddata_scipy_1_2_3, z_griddata_scipy_test[:2], decimal=5)
except AssertionError as err:
print (err)
if __name__ == '__main__':
"""
"""
test_griddata_cubic()
The test result on my computer Windows 7, Python 3.7, scipy 1.5.2 :
Arrays are not almost equal to 5 decimals
Mismatched elements: 38 / 40 (95%)
Max absolute difference: 0.03821737
Max relative difference: 0.67726368
x: array([[ 1.22465e-16, 2.99260e-02, 4.64922e-02, 3.63387e-02,
-1.17334e-02, -4.10790e-02, -3.53277e-02, -1.32599e-02,
6.57517e-03, 1.46194e-02, 1.29942e-02, 4.60176e-03,...
y: array([[ 1.22465e-16, 2.97398e-02, 4.62030e-02, 3.61127e-02,
-1.15711e-02, -3.85005e-02, -3.03032e-02, -9.36536e-03,
3.92018e-03, 1.17290e-02, 1.37729e-02, 6.40206e-03,...
I can observe that the differences are not negligibles !