Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ReturnDataView attributes to xarray.DataArray? #2170

Open
dweindl opened this issue Aug 30, 2023 · 1 comment
Open

Change ReturnDataView attributes to xarray.DataArray? #2170

dweindl opened this issue Aug 30, 2023 · 1 comment
Labels

Comments

@dweindl
Copy link
Member

dweindl commented Aug 30, 2023

I think changing from plain numpy arrays to xarray.DataArray for all data in ReturnDataView would be quite nice:

  1. labeled dimensions make it much easier for newcomers to figure out how to slice / plot / ... the data, this should be possible at barely any cost
  2. adding coordinates on top would be even more convenient, this would add number of identifier lists, but the cost would probably also be negligible

This should be fully backwards-compatible.

# to happen inside ReturnDataView
import xarray as xr
import numpy as np
sx = xr.DataArray(
    np.random.randn(2, 3, 2),
    dims=("time", "observable", "parameter"),
    coords=dict(time=[0, 10], observable=["obs1", "obs2", "obs3"], parameter=["p1", "p2"])
)

# suggestion:
# sx = rdata.sx
# allows for much more convenient slicing, e.g.
sx.sel(time=10, observable="obs2", parameter="p1")

print(sx)

<xarray.DataArray (time: 2, observable: 3, parameter: 2)>
array([[[ 1.17411809, -1.06761371],
        [-0.20386803, -0.11627882],
        [-1.61609636,  0.15455949]],
       [[ 0.90712023, -0.4521838 ],
        [ 1.40426045, -0.35439355],
        [-0.36240905,  2.25663359]]])
Coordinates:
  * time        (time) int64 0 10
  * observable  (observable) <U4 'obs1' 'obs2' 'obs3'
  * parameter   (parameter) <U2 'p1' 'p2'
@FFroehlich
Copy link
Member

Oh sounds nice, didn't know about xarrays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants