lair.units#

lair.units#

The pint unit registry lair uses, which is pint-xarray’s, so a quantified xarray object and a plain quantity share it. It has the mass_flux context. Convert a methane flux from moles to mass converts a methane flux with it.

See also

mass_flux

The context that converts between moles and mass.

lair.inventories.convert_units

Converts an array’s units attribute for a pollutant.

Examples

A quantity is a number with a unit, and the registry reads the unit from text, CF spellings such as m-2 s-1 included. to converts within one dimension; a flux in moles needs the mass_flux context to become a flux in mass.

In [1]: from lair import units

In [2]: flux = 10 * units("nmol m-2 s-1")

In [3]: print(f"{flux:~P}")
10.0 nmol/m²/s

In [4]: print(f"{flux.to('mol km-2 d-1'):~P.3f}")
864.000 mol/km²/d