Units Example

Raw conversion

In some situations it may be useful to convert a raw value to a different unit. It is recommended that all conversions, however simple, are made using bluemira.constants.raw_uc. This is how all unit conversions are performed internally.

Using raw_uc makes it less likely bugs would be introduced in the event of a base unit change.

import bluemira.base.constants as const
print(const.raw_uc(1, "um^3", "m^3"))
# gas flow rate conversion @OdegC
print(const.raw_uc(1, "mol/s", "Pa m^3/s"))
print(const.gas_flow_uc(1, "mol/s", "Pa m^3/s"))
# gas flow rate conversion @25degC
print(const.gas_flow_uc(1, "mol/s", "Pa m^3/s", gas_flow_temperature=298.15))
# boltzmann constant conversion
print(const.raw_uc(1, "eV", "K"))

Raw Temperature conversion with checks from different units

The explicit temperature conversion routines guard against temperatures below absolute zero

try:
    const.to_kelvin(-300)
except ValueError as v:
    print(v)

print(const.to_celsius(10, unit="rankine"))