xarray.DataArray.pint.dequantify

DataArray.pint.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 pint.Unit instance.

Parameters

format (str, default: None) – The format specification (as accepted by pint) used for the string representations. If None, the registry’s default (pint.UnitRegistry.default_format) is used instead.

Returns

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

Return type

DataArray

See also

String formatting

pint’s string formatting guide

Examples

>>> da = xr.DataArray([0, 1], dims="x")
>>> q = da.pint.quantify("m / s")
>>> q
<xarray.DataArray (x: 2)>
<Quantity([0 1], 'meter / second')>
Dimensions without coordinates: x
>>> q.pint.dequantify(format="P")
<xarray.DataArray (x: 2)>
array([0, 1])
Dimensions without coordinates: x
.. attribute:: units

meter/second

>>> q.pint.dequantify(format="~P")
<xarray.DataArray (x: 2)>
array([0, 1])
Dimensions without coordinates: x
.. attribute:: units

m/s

Use the registry’s default format

>>> pint_xarray.unit_registry.default_format = "~L"
>>> q.pint.dequantify()
<xarray.DataArray (x: 2)>
array([0, 1])
Dimensions without coordinates: x
.. attribute:: units

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