xarray.DataArray.astropy.dequantify

DataArray.astropy.dequantify(format=None)

Convert the units of the DataArray to string attributes.

Will replace .attrs['units'] on each variable with a string representation of the astropy.units.Unit instance.

Parameters:

format (str, default: None) – The format specification (as accepted by astropy) used for the string representations. If None, the default (astropy.units.format.Unicode) is used instead.

Returns:

dequantified – DataArray whose array data is unitless, and of the type that was previously wrapped by astropy.Quantity.

Return type:

DataArray

See also

String Representations of Units and Quantities

astropy’s string formatting guide

Examples

>>> da = xr.DataArray([0, 1], dims="x")
>>> q = da.astropy.quantify("m / s")
>>> q
<xarray.DataArray (x: 2)> Size: 16B
<Quantity [0., 1.] m / s>
Dimensions without coordinates: x
>>> q.astropy.dequantify(format="unicode")
<xarray.DataArray (x: 2)> Size: 16B
array([0., 1.])
Dimensions without coordinates: x
.. attribute:: units

m s⁻¹

>>> q.astropy.dequantify(format="generic")
<xarray.DataArray (x: 2)> Size: 16B
array([0., 1.])
Dimensions without coordinates: x
.. attribute:: units

m / s

>>> q.astropy.dequantify(format="latex")
<xarray.DataArray (x: 2)> Size: 16B
array([0., 1.])
Dimensions without coordinates: x
.. attribute:: units

$mathrm{frac{m}{s}}$