Best way to add an alias for a dimension name #8570
-
I hope the answer is not obvious, but I could not see it on a fairly quick search. We have need of aliases for dimensions in our brain imaging datasets. For example, for 4D MRI images, we might reasonably chose to label the dimensions as img['k'].attrs['alias'] = 'slice' We might want to index over the Is there a canconical way of achieving that (using an alias for the standard dimension name)? Or would we have to make a custom accessor to do this - e.g. img.our_accessor.isel(slice=0)`? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You have three options AFAICT:
Xarray tries to not interpret |
Beta Was this translation helpful? Give feedback.
Yes.
set_xindex
sets an "index" which translates from coordinate-space to index-space. We haven't enabled "index-space" selection with.isel
on such additional coordinates. (cc @benbovy )For completeness here's the
cf-xarray
version if you wanted to experiment with the accessor style interface: