Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D extrapolation not working #6688

Open
4 tasks
rafa-guedes opened this issue Jun 12, 2022 · 3 comments
Open
4 tasks

2D extrapolation not working #6688

rafa-guedes opened this issue Jun 12, 2022 · 3 comments

Comments

@rafa-guedes
Copy link
Contributor

rafa-guedes commented Jun 12, 2022

What happened?

Extrapolation does not seem to be working on 2D data arrays. The area outside the input grid is NaN in the interpolated data when using kwargs={"fill_value": None} as arguments to the interp function (the extrapolation does work when using scipy.interpolate.interpn and passing fill_value=None along with bounds_error=False).

This figure shows the example data arrays from the code snippet provided here:

Screenshot from 2022-06-12 13-10-08

What did you expect to happen?

Area outside the input grid filled with extrapolated data.

Minimal Complete Verifiable Example

import xarray as xr

da = xr.DataArray(
    data=[[1, 2, 3], [3, 4, 5]],
    coords=dict(y=[0, 1], x=[10, 20, 30]),
    dims=("y", "x")
)

dai = da.interp(x=[25, 30, 35], y=[0, 1], kwargs={"fill_value": None})

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 5.13.0-1031-gcp
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.0
libnetcdf: 4.7.4

xarray: 0.20.2
pandas: 1.3.5
numpy: 1.19.5
scipy: 1.7.3
netCDF4: 1.5.8
pydap: None
h5netcdf: None
h5py: 3.7.0
Nio: None
zarr: 2.11.3
cftime: 1.6.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2022.02.0
distributed: None
matplotlib: 3.5.2
cartopy: None
seaborn: 0.11.2
numbagg: None
fsspec: 2022.5.0
cupy: None
pint: 0.18
sparse: None
setuptools: 59.8.0
pip: 22.1.1
conda: 4.12.0
pytest: 7.1.2
IPython: 7.33.0
sphinx: None

@rafa-guedes rafa-guedes added bug needs triage Issue that has not been reviewed by xarray team member labels Jun 12, 2022
@keewis keewis removed bug needs triage Issue that has not been reviewed by xarray team member labels Jun 12, 2022
@keewis
Copy link
Collaborator

keewis commented Jun 12, 2022

you probably need to set kwargs={"fill_value": "extrapolate"} for this to work. As far as I remember, scipy is unfortunately a bit inconsistent in what value of fill_value corresponds to extrapolation, and in this case we're actually using interp1d under the hood (not sure in which situation interp1d is chosen over interpn, though).

@rafa-guedes
Copy link
Contributor Author

That works thanks. I just checked the example in the docs now and that uses kwargs={"fill_value": None} in the 2D example with the result evaluating to NaNs. That one also works and returns actual values when using "extrapolate" instead so it looks like something might have changed in xarray or scipy.

@Illviljan
Copy link
Contributor

There's been some improvements to the docs regarding this, #6639, maybe it'll be better after the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants