CNES / pangeo-pyinterp

Python library for optimized interpolation.
https://pangeo-pyinterp.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
117 stars 17 forks source link

Wrapping with a transpose matrix #12

Closed AntSimi closed 2 years ago

AntSimi commented 2 years ago

Describe the bug Wrong result with wrapping

To Reproduce

import pyinterp
import numpy as np

x_axis = np.arange(0,360,20)
y_axis = np.arange(-90,90,20)
z = np.outer(x_axis,y_axis).T
axis = [pyinterp.Axis(y_axis, is_circle=False), pyinterp.Axis(x_axis, is_circle=True)]
g = pyinterp.Grid2D(*axis, z)
x, y = np.array([20]), np.array([10])
print(z.shape)
print(x - 360, y, pyinterp.bivariate(g, y, x - 360, num_threads=1))
print(x, y, pyinterp.bivariate(g, y, x, num_threads=1))
print(x + 360, y, pyinterp.bivariate(g, y, x + 360, num_threads=1))

Output

(9, 18)
[-3400.]
[200.]
[3800.]

Expected behavior Result must be 200 for each call.

Pyinterp/Numpy/Python version information

>>> print(pyinterp.__version__)
0.15.2
>>> print(numpy.__version__)
1.22.0
>>> print(sys.version)
3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0]
>>> 
fbriol commented 2 years ago

Functions take arguments in longitude (x), latitude (y) order.

g=pyinterp.Grid2D(axis[1], axis[0], z.T)
x, y = np.array([20]), np.array([10])
print(z.shape)
print(x - 360, y, pyinterp.bivariate(g, x - 360, y, num_threads=1))
print(x, y, pyinterp.bivariate(g, x, y, num_threads=1))
print(x + 360, y, pyinterp.bivariate(g, x + 360, y, num_threads=1))

(9, 18)
[-340] [10] [200.]
[20] [10] [200.]
[380] [10] [200.]