home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 374473176

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
374473176 MDU6SXNzdWUzNzQ0NzMxNzY= 2518 Allow reduce to return an additional dimension 6153603 closed 0     2 2018-10-26T17:15:29Z 2018-10-27T14:14:39Z 2018-10-27T14:14:39Z CONTRIBUTOR      

Code Sample, a copy-pastable example if possible

```python import xarray as xr from scipy.interpolate import interp1d

airtemps = xr.tutorial.load_dataset('air_temperature')

def interptotarget(y, axis, **kwargs): x = kwargs['x'] target = kwargs['target'] return interp1d(x, y)(target)

This works

airtemps.groupby('lat').reduce(interptotarget, dim='lon', x=airtemps.lon, target=213.5)

This doesn't, but I'd like it to:

airtemps.groupby('lat').reduce(interptotarget, dim='lon', x=airtemps.lon, target=[213.5, 213.6]) ```

Problem description

In the code above, I give an example of how I'd like to use a reduce to return an additional dimension that I will need to be defined.

The scipy call to interp1d has no trouble calculating the data, but xarray issues ValueError: dimensions ('time', 'lat') must have the same length as the number of data dimensions, ndim=3 as it doesn't know what to do with the additional dimension.

I used the above example as a generic case. I know I could use .interp to do an interpolation, but I have different reduction functions in mind that produce an additional dimension. The scipy interp1 function just serves as a working example.

Expected Output

a =airtemps.groupby('lat').reduce(interptotarget, dim='lon', x=airtemps.lon, target=213.5) b =airtemps.groupby('lat').reduce(interptotarget, dim='lon', x=airtemps.lon, target=213.6) import pandas as pd expected = xr.concat([a, b], pd.Index([213.5, 213.6], name='ilon'))

Output of xr.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.18.16-arch1-1-ARCH machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_CA.UTF-8 LOCALE: en_CA.UTF-8 xarray: 0.10.8 pandas: 0.23.1 numpy: 1.14.5 scipy: 1.1.0 netCDF4: 1.4.0 h5netcdf: 0.6.1 h5py: 2.8.0 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.17.5 distributed: 1.21.8 matplotlib: 2.2.2 cartopy: None seaborn: None setuptools: 39.2.0 pip: 9.0.3 conda: None pytest: 3.6.1 IPython: None sphinx: None ```
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2518/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 74.924ms · About: xarray-datasette