pydata / pydata/xarray

Interpolation using non-dimension coordinates

Open
#3,343 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-interpolation
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

MCVE Code Sample
>>> da = xr.DataArray([1., 2.], coords=[('dim', [.5, 1.])])
>>> da.coords['nondim'] = ('dim', [0., 1.])
>>> da
<xarray.DataArray (dim: 2)>
array([1., 2.])
Coordinates:
  * dim      (dim) float64 0.5 1.0
    nondim   (dim) float64 0.0 1.0
>>> da.interp(dim=.75)
<xarray.DataArray ()>
array(1.5)
Coordinates:
    nondim   float64 0.5
    dim      float64 0.75
>>> da.interp(nondim=.5)
Traceback (most recent call last):

  File "<ipython-input-192-e3df34cff90f>", line 1, in <module>
    da.interp(nondim=.5)

  File "/usr/lib64/python3.6/site-packages/xarray/core/dataarray.py", line 951, in interp
    **coords_kwargs)

  File "/usr/lib64/python3.6/site-packages/xarray/core/dataset.py", line 1860, in interp
    indexers = OrderedDict(self._validate_indexers(coords))

  File "/usr/lib64/python3.6/site-packages/xarray/core/dataset.py", line 1316, in _validate_indexers
    raise ValueError("dimensions %r do not exist" % invalid)

ValueError: dimensions ['nondim'] do not exist
Expected Output

The same interpolation as for 'dim'.

Problem Description

Apparently, xarray currently cannot interpolate using non-dimension coordinates.

Output of xr.show_versions()
commit: None

python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.19.72-gentoo
machine: x86_64
processor: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz
byteorder: little
LC_ALL: None
LANG: nl_BE.UTF-8
LOCALE: nl_BE.UTF-8

xarray: 0.10.8
pandas: 0.24.2
numpy: 1.14.5
scipy: 1.1.0
netCDF4: 1.5.1.2
h5netcdf: None
h5py: 2.9.0
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 1.2.0
distributed: None
matplotlib: 2.2.2
cartopy: None
seaborn: None
setuptools: 40.6.3
pip: 19.1
conda: None
pytest: 3.10.1
IPython: 5.4.1
sphinx: 1.7.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the MCVE, then start at DataArray.interp and Dataset.interp in the traceback and follow _validate_indexers in xarray/core/dataset.py. Compare interpolation by the dimension coordinate with the requested non-dimension coordinate; done means da.interp(nondim=.5) produces the same interpolated result as da.interp(dim=.75).

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.