The xarray ecosystem supports unit-aware arrays using pint and pint-xarray. Some changes are required to make these packages work well with UDUNITS format recommended by the CF conventions.

cf_xarray makes those recommended changes when you import cf_xarray.units. These changes allow pint to parse and format UDUNIT units strings, and add several custom units like degrees_north, psu etc.

Formatting units

For now, only the short format using symbols is supported:

from pint import application_registry as ureg
import cf_xarray.units

u = ureg.Unit("m ** 3 / s ** 2")
'm3 s-2'