Units module#
This module contains the definitions of the units, as well as the unit-registry
object ureg
.
Main units#
general mass units (
g
,t
and their association with prefixes likekg
,Mt
, etc)length and volume units like
m
,L
,m**3
time units (
year
,month
,week
,day
)
In addition, the following units are defined in unit_definitions.txt
.
percent = [] = 0.01*count = %
ton = 1 * tonne
kt = 1000 * tonne
kton = 1000 * tonne
# elements
C = [carbon]
CO2 = [carbon_dioxide] = 12/44 * [carbon]
CO2e = [carbon_dioxide_equivalent]
CH4 = [methane]
N = [nitrogen]
NH3 = [ammonia]
N2O = [nitrous_oxide]
NOx = [nitrogen_oxides]
P = [phosphorus]
P2O5 = [phosphorus_pentoxide]
PO4e = [phosphate_equivalent]
S = [sulfur]
SO2 = [sulfur_dioxide]
SO2e = [sulfur_dioxide_equivalent]
K = [potassium]
K2O = [potassium_oxide]
Na = [sodium]
Ca = [calcium]
Cl = [chloride]
Mg = [magnesium]
H2O = [water]
Fe = [iron]
These units are then combined to g
and t
so you can use directly
gN
, gP
, or tCO2e
.
Any unit that is not directly defined here can be acces via the ureg
object.
Please see the Pint documentation for more details on how to use units.
Contexts#
In addition to the units, the unit_definitions.txt
file defines contexts
that are used to convert between different units.
The following contexts are defined:
“elements”, to convert a mass of molecules to the mass of one of its basic components (e.g. amount of carbon in or ),
“AR4GWP100” (or just “GWP”, global warming potential), to convert greenhouse gases to over a 100 year period,
“eutrophication”, to convert phosphorus-related molecules to (phosphate equivalents),
“acidification”, to convert sulfur-related molecule to .
For each of them, you can convert a quantity q to another unit u under
context c via q.to(u, c)
.
@context elements = el
[mass]*[carbon_dioxide] -> [mass]*[carbon]: 12/44 * value / CO2 * C
[mass]*[methane] -> [mass]*[carbon]: 12/16 * value / CH4 * C
[mass]*[ammonia] -> [mass]*[nitrogen]: 14/17 * value / NH3 * N
[mass]*[nitrous_oxide] -> [mass]*[nitrogen]: 28/44 * value / N2O * N
[mass]*[nitrogen_oxides] -> [mass]*[nitrogen]: 0.3 * value / NOx * N
[mass]*[phosphorus] -> [mass]*[phosphorus_pentoxide]: 142/62 * value / P * P2O5
[mass]*[phosphorus_pentoxide] -> [mass]*[phosphorus]: 62/142 * value / P2O5 * P
[mass]*[potassium_oxide] -> [mass]*[potassium]: 0.4107 * value / K2O * K
[mass]*[potassium] -> [mass]*[potassium_oxide]: 2.409 * value / K * K2O
[mass]*[sulfur] -> [mass]*[sulfur_dioxide]: 2 * value / S * SO2
[mass]*[sulfur_dioxide] -> [mass]*[sulfur]: 0.5 * value / SO2 * S
@end
@context AR5GWP100 = GWP100 = GWP = gwp
[mass]*[carbon_dioxide] -> [mass]*[carbon_dioxide_equivalent]: value / CO2 * CO2e
[mass]*[methane] -> [mass]*[carbon_dioxide_equivalent]: 27 * value / CH4 * CO2e
[mass]*[nitrous_oxide] -> [mass]*[carbon_dioxide_equivalent]: 273 * value / N2O * CO2e
@end
@context eutrophication = EP = ep
[mass]*[phosphorus] -> [mass]*[phosphate_equivalent]: value / P * PO4e
[mass]*[phosphorus_pentoxide] -> [mass]*[phosphate_equivalent]: 2 * value / P2O5 * PO4e
@end
@context acidification = AP = ap
[mass]*[sulfur] -> [mass]*[sulfur_dioxide_equivalent]: value / S * SO2e
[mass]*[sulfur_dioxide] -> [mass]*[sulfur_dioxide_equivalent]: value / SO2 * SO2e
@end