home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 303130664

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
303130664 MDU6SXNzdWUzMDMxMzA2NjQ= 1973 question: dataset variables as coordinates 10928117 closed 0     1 2018-03-07T14:57:19Z 2019-01-13T21:00:29Z 2019-01-13T21:00:29Z NONE      

Problem description

Let's consider two datasets, ds1 and ds2 with dummy data.

```python import xarray as xr import numpy as np

x = np.linspace(0, 1, 10) da1 = xr.concat([xr.DataArray(x2, coords={'x': x, 'a': 0}, dims='x'), xr.DataArray(x2+1, coords={'x': x+1, 'a': 1}, dims='x')], dim='a')

ds1 = da1.to_dataset(name='y')

ds2 = xr.concat([xr.Dataset({'x': ('n', x), 'y': ('n', x2)}, coords={'n': range(10), 'a': 0}), xr.Dataset({'x': ('n', x+1), 'y': ('n', x2+1)}, coords={'n': range(10), 'a': 1})], dim='a') ``` These two datasets represents in principle the same data, stored in two different ways.

```python

ds1.y <xarray.DataArray 'y' (a: 2, x: 19)> array([[ 0. , 0.012346, 0.049383, 0.111111, 0.197531, 0.308642, 0.444444, 0.604938, 0.790123, 1. , nan, nan, nan, nan, nan, nan, nan, nan, nan], [ nan, nan, nan, nan, nan, nan, nan, nan, nan, 1. , 1.012346, 1.049383, 1.111111, 1.197531, 1.308642, 1.444444, 1.604938, 1.790123, 2. ]]) Coordinates: * x (x) float64 0.0 0.1111 0.2222 0.3333 0.4444 0.5556 0.6667 ... * a (a) int64 0 1 python ds2.x <xarray.DataArray 'x' (a: 2, n: 10)> array([[ 0. , 0.111111, 0.222222, 0.333333, 0.444444, 0.555556, 0.666667, 0.777778, 0.888889, 1. ], [ 1. , 1.111111, 1.222222, 1.333333, 1.444444, 1.555556, 1.666667, 1.777778, 1.888889, 2. ]]) Coordinates: * n (n) int64 0 1 2 3 4 5 6 7 8 9 * a (a) int64 0 1 python ds2.y <xarray.DataArray 'y' (a: 2, n: 10)> array([[ 0. , 0.012346, 0.049383, 0.111111, 0.197531, 0.308642, 0.444444, 0.604938, 0.790123, 1. ], [ 1. , 1.012346, 1.049383, 1.111111, 1.197531, 1.308642, 1.444444, 1.604938, 1.790123, 2. ]]) Coordinates: * n (n) int64 0 1 2 3 4 5 6 7 8 9 * a (a) int64 0 1 ```

Question

Is there a straightforward way to reshape ds2 to look like ds1? In this dummy data it is clear that y = y(x) and first structure is more obvious to start with.

Second structure however is more natural when x and y could be some separately calculated quantities depending on parameter a, that one would like to explore as y(x).

Output of xr.show_versions()

# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.4.final.0 python-bits: 64 OS: Linux OS-release: 4.13.16-100.fc25.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 xarray: 0.10.1 pandas: 0.22.0 numpy: 1.13.3 scipy: 0.19.1 netCDF4: None h5netcdf: None h5py: None Nio: None zarr: None bottleneck: None cyordereddict: None dask: None distributed: None matplotlib: 2.1.2 cartopy: None seaborn: None setuptools: 38.5.1 pip: 9.0.1 conda: None pytest: 3.4.1 IPython: 6.1.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1973/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

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 158.013ms · About: xarray-datasette