units

The units module provides classes that represent quantities and units, with quantities like Duration, Length and Speed, and units for the quantities, e.g.,’s’, ‘h’ and ‘min’ for the Duration quantity. For simulation models, it is convenient to enter durations and delays using a quantity with a unit, and to display the simulator time in a value with a unit, to know, e.g., that 3 hours have passed in the simulation.

For now, units assume linear scales with respect to a base unit, usually an SI unit. Most of the calculation and transformation work is done in the Quantity class. The Quantity class subclasses the builtin float class. Internally, the value of the quantity is stored in the base unit in the float class, and the actual unit is stored in the Quantity class as a str.

This module has been based on the Java DJUNITS project (Delft Java units), as documented at https://djunits.org.

Terminology:
  • si (float) – The si-value of a quantity.

  • sidict (dict[str, int]) – Dictionary that maps SI-units onto the exponents of the signature, e.g., {‘m’: 1, ‘s’: -2} for Acceleration.

  • sisig (list[int]) – List with a length of 9, mapping the 2 plus 7 SI units onto the exponents of the signature, e.g., [0, 0, 0, 1, -2, 0, 0, 0, 0] for Acceleration.

  • siunit (str) – String representation of the unit using the SI units, e.g., ‘m/s2’ for Acceleration.

Click below for the API of a specific unit. Each file has the class description of the unit, and the class description of a distribution wrapper, so elements with a unit can be drawn from a stochastic distribution.

The Quantity class is the generic parent class for the unit classes. The SI class is a generic class where a new unit with any combination of the SI units (rad, sr, kg, m, s, A, K, mol, cd) can be constructed.

Classes