spaemis.unit_registry

Unit Registry

Adds H2 related units if they haven’t been previously registered

convert_to_target_unit

convert_to_target_unit(initial_unit, target_unit)[source]

Calculate the scale factor required to convert between units

This function supports converting a subset of the input units dimensions which is helpful in situations where arbitary dimensions can be provided i.e. Mt X/yr where X could be a range of species.

>>> value = ur.Quantity(12, "Mt CH4/yr")
>>> scale_factor = convert_to_target_unit(value.units, target_unit="kg")
>>> ur.Quantity(value.m * scale_factor.m, scale_factor.u)
Parameters:
  • initial_unit (str | pint.Unit | pint.Quantity[float]) – Units of input

  • target_unit (str | pint.Unit) –

    The expected output

    Any dimensions present in the initial_unit, but not in the target unit will be kept the same.

Returns:

pint.Quantity – The magnitude of the quantity represents the required scale factor The units of the quantity represent the resulting unit