scmdata.units

Unit handling

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, numpy.ndarray]) Union[float, numpy.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, numpy.ndarray]) Union[float, numpy.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: openscm_units._unit_registry.ScmUnitRegistry

Underlying unit registry