home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 314844258

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1475#issuecomment-314844258 https://api.github.com/repos/pydata/xarray/issues/1475 314844258 MDEyOklzc3VlQ29tbWVudDMxNDg0NDI1OA== 1217238 2017-07-12T17:44:28Z 2017-07-12T17:44:28Z MEMBER

I don't think we need a full NDIntervalIndex unless we also want indexing, which is nice but not essential for just storing data. We do need a way to represent interval data in 1D arrays, though.

Probably the simplest option is to use structured dtypes, which should already work with the existing version of xarray, e.g., ``` import numpy as np import xarray

interval_dtype = np.dtype([('start', float), ('stop', float)]) coords = {'x': 0.5 + np.arange(3), 'x_bounds': ('x', np.array([(0, 1), (1, 2), (2, 3)], dtype=interval_dtype))} da = xarray.DataArray(range(3), coords=coords, dims='x')

da <xarray.DataArray (x: 3)> array([0, 1, 2]) Coordinates: * x (x) float64 0.5 1.5 2.5 x_bounds (x) [('start', '<f8'), ('stop', '<f8')] (0.0, 1.0) (1.0, 2.0) ...

da.x_bounds <xarray.DataArray 'x_bounds' (x: 3)> array([(0.0, 1.0), (1.0, 2.0), (2.0, 3.0)], dtype=[('start', '<f8'), ('stop', '<f8')]) Coordinates: * x (x) float64 0.5 1.5 2.5 x_bounds (x) [('start', '<f8'), ('stop', '<f8')] (0.0, 1.0) (1.0, 2.0) ...

da.x_bounds.data['start'], da.x_bounds.data['stop'] (array([ 0., 1., 2.]), array([ 1., 2., 3.])) ```

We could probably do a few things to make these easier to use: 1. Support indexing like da.x_bounds['start'] to return da.x_bounds.data['start'] wrapped in an xarray.DataArray. 2. Automatically create them as part of netCDF IO.

Conceptually, this is pretty similar to a MultiIndex (see https://github.com/pydata/xarray/pull/1426 for discussion).

{
    "total_count": 2,
    "+1": 2,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  242181620
Powered by Datasette · Queries took 80.969ms · About: xarray-datasette