Basic demo¶
This notebook gives a basic demonstration of how to use OpenSCM-Units.
For further details, see the rest of the notebooks.
import numpy as np
import openscm_units
UR = openscm_units.unit_registry
print(f"You are using openscm_units version {openscm_units.__version__}")
You are using openscm_units version 0.6.3
Usage¶
With OpenSCM-Units it is possible to attach units to quantities. This is all based on the the Pint library. For full details, see Pint's docs.
OpenSCM-Units adds a number of units relevant to simple climate modelling to Pint's standard registry.
Emissions¶
For example, we can define quantities with emissions units.
emissions_aus = UR.Quantity(np.array([350, 355, 358]), "Mt CO2 / yr")
emissions_aus
| Magnitude | [350 355 358] |
|---|---|
| Units | CO2 megametric_ton/yr |
We can then trivially convert these units to other, equivalent, units.
emissions_aus.to("GtC / yr")
| Magnitude | [0.09545454545454547 0.09681818181818184 0.09763636363636366] |
|---|---|
| Units | gigatC/yr |
Concentrations¶
We can also define quantities with concentrations units.
annual_co2_increase = UR.Quantity(2.2, "ppm / yr")
annual_co2_increase
We can then trivially convert these units to other, equivalent, units.
annual_co2_increase.to("ppb / yr")
Operations¶
Thanks to Pint, units are then carried through operations.
annual_co2_increase_erf_equiv = (
UR.Quantity(4.0, "W / m^2")
/ np.log(2)
/ UR.Quantity(1, "yr")
* np.log(1 + annual_co2_increase * UR.Quantity(1, "yr") / UR.Quantity(278, "ppm"))
)
annual_co2_increase_erf_equiv
Further details¶
This provides a very brief overview to the basic principles. For further details, see design principles and Pint's docs. The notebook on design principles is a good starting point.