Labeling dims with units #6594
-
Is there a way to label dimensions with units? For example you can create an image with an X and Y axis using a 2D ndarray:
However, its not clear in this data structure what the field of view in real space is. The X and Y axes could be meters or they could be Angstroms. Is there a way to indicate their units? You can use I tried to use 'pint' but that is not working (xarray '2022.3.0'). It seems like there should be a way since this is a fairly common and important aspect of a quantitative DataArray. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@ercius, have you tried the following??? In [5]: dd.X.attrs['units'] = 'm'
In [6]: dd.Y.attrs['units'] = 'm'
In [8]: dd.Y
Out[8]:
<xarray.DataArray 'Y' (Y: 10)>
array([0. , 0.111111, 0.222222, 0.333333, 0.444444, 0.555556, 0.666667,
0.777778, 0.888889, 1. ])
Coordinates:
* Y (Y) float64 0.0 0.1111 0.2222 0.3333 ... 0.6667 0.7778 0.8889 1.0
Attributes:
units: m |
Beta Was this translation helpful? Give feedback.
@ercius, have you tried the following???