scmdata.units

Unit handling and conversion

scmdata uses openscm_units to support unit handling and conversion. openscm_units is built on top of pint and includes some additional quantity definitions to support the tracking of emissions timeseries.

UNIT_REGISTRY

UNIT_REGISTRY(input_string, case_sensitive=None, **values): ScmUnitRegistry = <openscm_units._unit_registry.ScmUnitRegistry object>

Unit registry used for when converting units in scmdata

This defaults to openscm_units.unit_registry so any additional units added to openscm_units.unit_registry will also be available in scmdata. Alternatively, this attribute can be overridden with a custom :class:`openscm.ScmUnitRegistry instance if required.

UnitConverter

class UnitConverter(source, target, context=None)[source]

Bases: object

Converts numbers between two units.

property contexts: Sequence[str]

Available contexts for unit conversions

convert_from(v)[source]

Convert value from source unit to target unit.

Parameters:

value – Value in source unit

Returns:

Union[float, np.ndarray] – Value in target unit

convert_to(v)[source]

Convert value from target unit to source unit.

Parameters:

value – Value in target unit

Returns:

Union[float, np.ndarray] – Value in source unit

property source: str

Source unit

property target: str

Target unit

property unit_registry: ScmUnitRegistry

Underlying unit registry

get_unit_registry

get_unit_registry()[source]

Retrieve the global unit registry

Return type:

openscm_units._unit_registry.ScmUnitRegistry