home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

2 rows where user = 10928117 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

state 2

  • closed 1
  • open 1

type 1

  • issue 2

repo 1

  • xarray 2
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
297560256 MDU6SXNzdWUyOTc1NjAyNTY= 1914 cartesian product of coordinates and using it to index / fill empty dataset RafalSkolasinski 10928117 open 0     17 2018-02-15T19:03:23Z 2024-01-05T17:09:55Z   NONE      

For a given empty dataset with only coordinates

python import xarray as xr import numpy as np data = xr.Dataset(coords={'x': np.linspace(-1, 1), 'y': np.linspace(0, 10), 'a': 1, 'b': 5})

I'd like to iterate over the product of coordinates, in a similar way as it can be done for numpy.arrays

python data = np.zeros((10, 5, 10)) for (i, j, k), _ in np.ndenumerate(data): data[i, j, k] = some_function(i, j, k)

to fill the data with values of some function.

Also I'd like to extend this to the cases of functions that are multi-valued, i.e. they return a numpy.array.

Is there an easy way to do so? I was unable to find anything similar in the docs.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1914/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  reopened xarray 13221727 issue
303130664 MDU6SXNzdWUzMDMxMzA2NjQ= 1973 question: dataset variables as coordinates RafalSkolasinski 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 xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 22.068ms · About: xarray-datasette