hypergas.unit_conversion module#
Utility for converting between concentration/flux units that are all anchored to a common base unit: ppm (parts per million).
Supported units#
‘ppm’ : parts per million (the reference/base unit)
‘ppm m’ : ppm integrated over a path length in meters
‘ppb’ : parts per billion
‘umol m-2’ : micromoles per square meter
How it works#
Every unit is defined by a single number: the factor you multiply a ppm value by to express it in that unit (SCALE_FROM_PPM below). To convert between any two supported units, we simply:
Convert the input value back to ppm (divide by its own factor).
Convert that ppm value into the target unit (multiply by the target’s factor).
This means adding a new unit only requires adding one new entry to the SCALE_FROM_PPM dictionary — the conversion logic itself does not need to change.
Usage#
from unit_conversion import convert_units, get_scale_factor
# Convert a value directly value_ppb = convert_units(2.5, input_unit=’ppm’, output_unit=’ppb’)
# Or get the multiplicative factor and apply it yourself factor = get_scale_factor(input_unit=’ppm’, output_unit=’ppb’) value_ppb = 2.5 * factor
- hypergas.unit_conversion.convert_units(value, input_unit, output_unit)[source]#
Convert value from input_unit to output_unit.
- Parameters:
- Returns:
float or array-like – value converted into output_unit.
Examples
>>> convert_units(2.5, 'ppm', 'ppb') 2500.0 >>> convert_units(2500, 'ppb', 'ppm') 2.5
- hypergas.unit_conversion.get_scale_factor(input_unit, output_unit)[source]#
Compute the multiplicative factor to convert a value from input_unit to output_unit.
Both units must be keys in SCALE_FROM_PPM. Conversion always routes through ppm as the common base:
factor = SCALE_FROM_PPM[output_unit] / SCALE_FROM_PPM[input_unit]
- Parameters:
- Returns:
float – Multiply your input value by this to get the output value.
- Raises:
ValueError – If either unit is not in SCALE_FROM_PPM.
- hypergas.unit_conversion.scale_from_ppm(units)[source]#
Return the factor to convert a value FROM ppm TO units.
Equivalent to the original _scale_units method, but as a standalone function. Prefer convert_units/get_scale_factor for new code, since they support arbitrary input/output unit pairs rather than assuming ppm as the input.