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
One thing I find useful with DataArrays is the ability to take all dimensions but one, stack them into one MultiIndex, and then iterate over the entries of that MultiIndex. For example, I have a DataArray that starts with a time dimension/coordinate. I then add several new dimensions/coords that correspond to varying input parameters (i.e. one for initial velocity, initial position, air density, etc.). What I then want to do is iterate over all 1D time vectors (all the combinations of those variable input parameters). The easiest way I've found to do this is to stack all the dimensions except time and then iterate over the resulting MultiIndex. I have been doing this by converting the dims of the DataArray to a list and then removing "time" from that list and using it as the input to stack.
Describe the solution you'd like
It would be awesome if there was a method that could specifically stack all dimensions except for a list of specified dimension names (something like DataArray.stack_except({"name_of_created_stacked_dimension": ["dim_to_leave_unstacked", "another_dim"])), or some kind of syntax that would allow an "all except" behavior to be passed directly into stack (could be something like `DataArray.stack({"name_of_created_stacked_dimension"}: ["dim_to_leave_unstacked"], invert=True).
Describe alternatives you've considered
If there is a better way to achieve what I'm trying to accomplish (take one dimension and iterate over all the combinations of the other dimensions, resulting in 1D vectors that vary along the single desired dimension), then I would welcome any tips!
Additional context
No response
The text was updated successfully, but these errors were encountered:
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
You can try the Dataset.to_stacked_array method. This will only work for Dataset and stack all data vars on the Dataset. However, if you start from one DataArray (and call to_dataset() on it), this may do what you want.
@mathause that actually does exactly what I'm looking for (I'm working with a Dataset anyway). There goes my work I started to add a PR for the invert=True kwarg on stack() lol. This is great though... I may add a quick PR to add this method to DataArray since most of them use _to_temp_dataset() anyway.
Is your feature request related to a problem?
One thing I find useful with
DataArrays
is the ability to take all dimensions but one,stack
them into oneMultiIndex
, and then iterate over the entries of thatMultiIndex
. For example, I have aDataArray
that starts with atime
dimension/coordinate. I then add several new dimensions/coords that correspond to varying input parameters (i.e. one for initial velocity, initial position, air density, etc.). What I then want to do is iterate over all 1Dtime
vectors (all the combinations of those variable input parameters). The easiest way I've found to do this is tostack
all the dimensions excepttime
and then iterate over the resultingMultiIndex
. I have been doing this by converting thedims
of theDataArray
to alist
and then removing"time"
from that list and using it as the input tostack
.Describe the solution you'd like
It would be awesome if there was a method that could specifically stack all dimensions except for a list of specified dimension names (something like
DataArray.stack_except({"name_of_created_stacked_dimension": ["dim_to_leave_unstacked", "another_dim"])
), or some kind of syntax that would allow an "all except" behavior to be passed directly intostack
(could be something like `DataArray.stack({"name_of_created_stacked_dimension"}: ["dim_to_leave_unstacked"], invert=True).Describe alternatives you've considered
If there is a better way to achieve what I'm trying to accomplish (take one dimension and iterate over all the combinations of the other dimensions, resulting in 1D vectors that vary along the single desired dimension), then I would welcome any tips!
Additional context
No response
The text was updated successfully, but these errors were encountered: