Skip to content

Working with Physical Units

The jetfuelburn package utilises the pint package to support physical units in calculations. The pint package allows for the definition of physical units and the conversion between them.

To use physical units, simply load the ureg object (unit registry) from the jetfuelburn package. You can now start defining physical quantities:

Editor (session: units)Run
from jetfuelburn import ureg
100 * ureg.kg
OutputClear

Warning

Remember that you must load the ureg object from the jetfuelburn package to use physical units. Loading the ureg object will also load the pint package. You cannot simply:

import pint
ureg = pint.UnitRegistry()

since this would create another ureg object. This documented in the section Having a Shared Registry of the pint documentation.

The most frequent use-cases of the ureg object are conversion:

Editor (session: units)Run
my_mass = 100 * ureg.kg
my_mass.to('lbs')
OutputClear

and dimensionality checks:

Editor (session: units)Run
my_mass.check('[mass]')
OutputClear

In order to get a list of all available units, you can use the following code:

Editor (session: units)Run
list(ureg._units.keys())
OutputClear

You can search this list for specific units using list comprehensions:

Editor (session: units)Run
[unit for unit in ureg._units.keys() if "meter" in unit]
OutputClear

Note

Note that because of American hegemony in the world of science, 'ton' refers to a short ton (2000 lbs). If you would instead like to use civilized tons (1000 kg), you can use 'metric_ton' instead.