Multiple coordinates for same dimension? #5482
-
I'm currently writing some code that sits between two existing packages. The code deals with frequency domain spectrums. The problem that I have is that the first package defines the frequency in [radians per second] while the other package uses [Hz]. My data has a dimension "frequency". I'm looking for a way to expose it in a way that makes it easy to use from either package. I think it would be convenient to somehow attach two sets of labels to the frequency axis, one being in Hz and the other one being the values expressed in rad/s. I can see similar use-cases for people working with the same data expressed in different units such as ft and m or F and C. Is this already possible? Or does anyone have a good suggestion on how to implement this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
It should be possible to use non-dimension coordinates but you would need to use distinct names like "frequency" and "angular_velocity". For example: ds = (
xr.Dataset(coords={"frequency": [1, 2, 3]})
.assign_coords(angular_velocity=lambda ds: ("frequency", ds.frequency * 2 * np.pi))
) I would also recommend to have a look at |
Beta Was this translation helpful? Give feedback.
-
Is there a way to have multiple coordinates for a single dimension which can all be sliced? |
Beta Was this translation helpful? Give feedback.
-
I'm also interested in @AlexAtCCRI 's question and specifically the following case: Can we have a dimension with two coordinates - one "dimension coordinate" and one "non-dimension coordinate" - both of which are indexed (i.e. can be used for slicing and alignment)? I use the above terms as defined here. |
Beta Was this translation helpful? Give feedback.
It should be possible to use non-dimension coordinates but you would need to use distinct names like "frequency" and "angular_velocity". For example:
I would also recommend to have a look at
pint-xarray
which should make working with units easier. It is still experimental, though, so I very much welcome feedback.