src.units module

Functions wrapping unit conversion methods from the third-party cfunits library.

src.units.to_cfunits(*args)[source]

Coerce string-valued units and (quantity, unit) tuples to cfunits.Units objects.

src.units.to_equivalent_units(*args)[source]

Same as to_cfunits, but raise TypeError if units of all quantities not equivalent.

src.units.relative_tol(x, y)[source]

HACK to return max(|x-y|/x, |x-y|/y) for unit-ful quantities x, y. Vulnerable to underflow in principle.

src.units.units_equivalent(*args)[source]

Returns True if and only if all units in arguments are equivalent (represent the same physical quantity, up to a multiplicative conversion factor.)

src.units.units_reftime_base_eq(*args)[source]

Returns True if and only if all units in arguments are equivalent (represent the same physical quantity, up to a multiplicative conversion factor.)

src.units.units_equal(*args, rtol=None)[source]

Returns True if and only if all quantities in arguments are strictly equal (represent the same physical quantity and conversion factor = 1).

Note

rtol, atol tolerances on floating-point equality not currently implemented in cfunits, so we implement rtol in a hacky way here.

src.units.conversion_factor(source_unit, dest_unit)[source]

Defined so that (conversion factor) * (quantity in source_units) = (quantity in dest_units).

src.units.convert_scalar_coord(coord, dest_units, log=<Logger src.units (WARNING)>)[source]

Given scalar coordinate coord, return the appropriate scalar value in new units dest_units.

src.units.convert_dataarray(ds, da_name, src_unit=None, dest_unit=None, log=<Logger src.units (WARNING)>)[source]

Wrapper for cfunits.conform() that does unit conversion in-place on a member of an xarray Dataset, updating its units attribute.