scmdata.units

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.

scmdata.units.UNIT_REGISTRY: 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.

class scmdata.units.UnitConverter(source: str, target: str, context: Optional[str] = None)[source]

Bases: object

Converts numbers between two units.

property contexts: Sequence[str]

Available contexts for unit conversions

convert_from(v: Union[float, ndarray]) Union[float, ndarray][source]

Convert value from source unit to target unit.

Parameters

value – Value in source unit

Returns

Value in target unit

Return type

Union[float, np.ndarray]

convert_to(v: Union[float, ndarray]) Union[float, ndarray][source]

Convert value from target unit to source unit.

Parameters

value – Value in target unit

Returns

Value in source unit

Return type

Union[float, np.ndarray]

property source: str

Source unit

property target: str

Target unit

property unit_registry: ScmUnitRegistry

Underlying unit registry

scmdata.units.get_unit_registry() ScmUnitRegistry[source]

Retrieve the global unit registry