pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.61k stars 1.08k forks source link

Error using xarray.interp - function signature does not match with scipy.interpn #7414

Closed Florian1209 closed 6 months ago

Florian1209 commented 1 year ago

What happened?

I am experiencing an error when using the array.interp function. The error message indicates that the function signature does not match with scipy interpn.

It 's linked to scipy update 1.10.0 (2023/01/03).

What did you expect to happen?

I would interpolate 2D data of numpy float64 : two data lattitudes and longitudes following <xarray.DataArray (row: 32, col: 32)>. da is a xarray dataset :

Dimensions:  (lat: 721, lon: 1441)
Coordinates:
  * lat      (lat) float64 90.0 89.75 89.5 89.25 ... -89.25 -89.5 -89.75 -90.0
  * lon      (lon) float64 0.0 0.25 0.5 0.75 1.0 ... 359.2 359.5 359.8 360.0
Data variables:
    hgt      (lat, lon) >f4 13.61 13.61 13.61 13.61 ... -29.53 -29.53 -29.53
Attributes:

Minimal Complete Verifiable Example

interpolated_da = da.interp(
        {
            "x": xr.DataArray(x, dims=("x", "y")),
            "y": xr.DataArray(y, dims=("x", "y")),
        }
    )

MVCE confirmation

Relevant log output

interpolated_da = da.interp(
venv/lib/python3.8/site-packages/xarray/core/dataset.py:3378: in interp
    variables[name] = missing.interp(var, var_indexers, method, **kwargs)
venv/lib/python3.8/site-packages/xarray/core/missing.py:639: in interp
    interped = interp_func(
venv/lib/python3.8/site-packages/xarray/core/missing.py:764: in interp_func
    return _interpnd(var, x, new_x, func, kwargs)
venv/lib/python3.8/site-packages/xarray/core/missing.py:788: in _interpnd
    rslt = func(x, var, xi, **kwargs)
venv/lib/python3.8/site-packages/scipy/interpolate/_rgi.py:654: in interpn
    return interp(xi)
venv/lib/python3.8/site-packages/scipy/interpolate/_rgi.py:336: in __call__
    result = evaluate_linear_2d(self.values,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   TypeError: No matching signature found

_rgi_cython.pyx:19: TypeError

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None python: 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.4.0-135-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.9.0

xarray: 2022.12.0 pandas: 1.5.2 numpy: 1.22.4 scipy: 1.10.0 netCDF4: 1.6.2 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.3.4 cfgrib: None iris: None bottleneck: None dask: 2022.12.1 distributed: 2022.12.1 matplotlib: 3.6.2 cartopy: None seaborn: None numbagg: None fsspec: 2022.11.0 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 65.6.3 pip: 22.3.1 conda: None pytest: 7.2.0 mypy: None IPython: 8.7.0 sphinx: 5.3.0 None

arongergely commented 1 year ago

This breaks the documentation build too, it seems!

Sphinx errors out when it tries to parse https://github.com/pydata/xarray/blob/main/doc/user-guide/interpolation.rst

arongergely commented 1 year ago

Looks like this is the culprit: https://github.com/scipy/scipy/issues/17718 to be fixed in scipy 1.10.1