Skip to main content

PyPI version Build status Test coverage

© 2020-2026 IAM-units authors; licensed under the GNU GPL version 3.

The file definitions.txt gives Pint-compatible definitions of energy, climate, and related units to supplement the SI and other units included in Pint’s default_en.txt. These definitions are used by:

and may be used for research in integrated assessment, energy systems, transportation, or other, related fields.

Please open a GitHub issue or pull request to:

  • Add more units to definitions.txt.

  • Add your usage of iam-units to this README.

  • Request or contribute additional features.

Usage

iam_units.registry is a pint.UnitRegistry object with the definitions from definitions.txt loaded:

>>> from iam_units import registry

# Parse an energy unit defined by iam-units
>>> qty = registry('1.2 tce')
>>> qty
1.2 <Unit('tonne_of_coal_equivalent')>

>>> qty.to('GJ')
29.308 <Unit('gigajoule')>

To make the registry from this package the default:

>>> import pint
>>> pint.set_application_registry(registry)

# Now used by default for pint top-level classes and methods
>>> pint.Quantity('1.2 tce')
1.2 <Unit('tonne_of_coal_equivalent')>

Environment variables

The package responds to two optional environment variables:

IAM_UNITS_CACHE

iam-units caches the created registry using pint’s caching mechanism. If set, this variable must contain the path of a directory for the cache. If not set, a default path is used.

IAM_UNITS_CURRENCY

If set, this variable must be a string like “EXC,2005”. The two parts, separated by a comma (“,”), are separated and passed as the method and period arguments to configure_currency() (see below) when iam-units is imported. If not set, the function is not called.

Warnings

iam_units overwrites Pint’s default definitions in the following cases:

pint default

iam_units

Note

‘kt’ = knot [velocity]

‘kt’ = 1000 metric tons

‘kt’ is commonly used for emissions in the IAM-context.

Technical details

Emissions and GWP

The function convert_gwp() converts from mass (or mass-related units) of one specific greenhouse gas (GHG) species to an equivalent quantity of second species, based on global warming potential (GWP) metrics. The supported species are listed in species.txt and the variable iam_units.emissions.SPECIES.

The metrics have names like <IPCC report>GWP<years>, where <years> is the time period over which heat absorption was assessed. The supported metrics are listed in the variable iam_units.emissions.METRICS.

>>> qty = registry('3.5e3 t').to('Mt')
>>> qty
3.5 <Unit('megametric_ton')>

# Convert from mass of N2O to GWP-equivalent mass of CO2
>>> convert_gwp('AR4GWP100', qty, 'N2O', 'CO2')
0.9275 <Unit('megametric_ton')>

# Using a different metric
>>> convert_gwp('AR5GWP100', qty, 'N2O', 'CO2')
1.085 <Unit('megametric_ton')>

The function also accepts input with the commonly-used combination of mass (or related) units and the identity of a particular GHG species:

# Expression combining magnitude, units, *and* GHG species
>>> qty = '3.5 Mt N2O / year'

# Input species is determined from *qty*
>>> convert_gwp('AR5GWP100', qty, 'CO2')
1.085 <Unit('megametric_ton / year')>

Strictly, the original species is not a unit but a nominal property; see the International Vocabulary of Metrology (VIM) used in the SI. To avoid ambiguity, code handling GHG quantities should also track and output these nominal properties, including:

  1. Original species.

  2. Species in which GWP-equivalents are expressed (e.g. CO₂ or C)

  3. GWP metric used to convert (1) to (2).

To aid with this, the function format_mass() is provided to re-assemble strings that include the GHG species or other information:

# Perform a conversion
>>> qty = convert_gwp('AR5GWP100', '3.5 Mt N2O / year', 'CO2e')
>>> qty
927.5 <Unit('megametric_ton / year')>

# Format a string with species and metric info after the mass units of *qty*
>>> format_mass(qty, 'CO₂-e (AR5)', spec=':~')
'Mt CO₂-e (AR5) / a'

See Pint’s formatting documentation for values of the spec argument.

Data sources

The GWP unit definitions are generated from the package globalwarmingpotentials. The version of that package used to generate the definitions is stated in the variable iam_units.emissions.GWP_VERSION.

See DEVELOPING.rst for details on updating the definitions.

Currency

iam_units defines deflators for:

  • USD (United States dollar) for annual periods from 2000 to 2022 inclusive.

  • EUR (Euro) for the periods 2005, 2010, 2015, 2020, and 2024 only.

These can be used via pint-compatible unit expressions like USD_2019 that combine the ISO 4217 alphabetic code with the time period.

To enable conversions between different currencies, use the function configure_currency():

>>> configure_currency(method="EXC", period="2005")

# Then, for example
>>> qty = registry("42.1 USD_2020")
>>> qty
42.1 <Unit('USD_2020')>

>>> qty.to("EUR_2005")
26.022132012144635 <Unit('EUR_2005')>

Calling configure_currency() again with the same method and currency/period pair on the same registry is a no-op. Calling it with a different method for an already configured pair raises ValueError rather than silently reusing the first definition.

Currently iam_units supports:

  • annual OECD Table 4 exchange-rate / PPP methods EXC, EXCE, PPPGDP, PPPPRC, and PPPP41;

  • EUR for the periods 2005, 2010, 2015, 2020, and 2024; and

  • USD as the base currency for those conversions.

Up to v2025.9.12, configure_currency("EXC", 2005) was called automatically.

Contributions that extend the supported currencies, methods, and periods are welcome.

Tests and development

Use pytest iam_units --verbose to run the test suite included in the submodule iam_units.test_all. See DEVELOPING.rst for further details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iam_units-2026.8.5.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iam_units-2026.8.5-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file iam_units-2026.8.5.tar.gz.

File metadata

  • Download URL: iam_units-2026.8.5.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iam_units-2026.8.5.tar.gz
Algorithm Hash digest
SHA256 067b8adc0765b2eccf928dffbe39716b86219def03bbc0de272efc46d99dce84
MD5 c230dbf4f52345ff534d32cad301c991
BLAKE2b-256 c8aa086409e43e796e20c9a7f5d3594e8c8e7546d3cc668ce7156f238e9e4542

See more details on using hashes here.

File details

Details for the file iam_units-2026.8.5-py3-none-any.whl.

File metadata

  • Download URL: iam_units-2026.8.5-py3-none-any.whl
  • Upload date:
  • Size: 53.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for iam_units-2026.8.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c275e4b4871d2b1d6d675ca71ebefa48e7c86807373b0a9910727fc095b9ac40
MD5 cd24cd9014bd685dc3615d9b93d5e8d0
BLAKE2b-256 f71c2aa4856c9c82c8e1d74b6633f79e3de236eb211dafdc0d92df8f5efc127f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page