You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I often have to deal with datasets in this form (multiple variables of different sizes, each representing different categories, on the same physical dimension but using different names as they have different labels),
where it would be more convenient to have the data re-arranged into the following form (concatenate the variables into a single variable with a multi-index with the labels of both the categories and the physical coordinate):
Maybe I miss a better way to do this? If I don't, it would be nice to have a convenience method for this, unless this use case is too rare to be worth it. Also not sure at all on what would be a good API such a method.
The text was updated successfully, but these errors were encountered:
This would still need some work (e.g., with set_index#1028) to set the MultiIndex. Ideally, maybe you could write something like combined.set_index(spectrum=['band', 'wn']) to create the new dimension and MultiIndex all at once.
The API is not so obvious for us, though, because we need to supply the new dimension name and levels all at once. Maybe something like xr.concat(arrays, dim={'spectrum': ['band', 'wn']} would work.
Using something like combined.set_index(spectrum=['band', 'wn']) or xr.concat(arrays, dim={'spectrum': ['band', 'wn']}) would be nice, although it may be a bit weird to use the key spectrum to rename the wn dimension here.
For now, I'm fine with setting the MultIndex using the more explicit - though more verbose - combined.set_index(wn=['band', 'wn']).rename({'wn': 'spectrum'})
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity
If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically
I often have to deal with datasets in this form (multiple variables of different sizes, each representing different categories, on the same physical dimension but using different names as they have different labels),
where it would be more convenient to have the data re-arranged into the following form (concatenate the variables into a single variable with a multi-index with the labels of both the categories and the physical coordinate):
The latter would allow using xarray's nice features like
ds.groupby('band').mean()
.Currently, the best way that I've found to transform the data is something like:
Maybe I miss a better way to do this? If I don't, it would be nice to have a convenience method for this, unless this use case is too rare to be worth it. Also not sure at all on what would be a good API such a method.
The text was updated successfully, but these errors were encountered: