SI

class pydsol.core.units.SI(value, unit: str = '', **kwargs)[source]

Bases: float

Class that contains a quantity of a non-predefined type. An example would be s/m, which has the inverse signature as speed. Quantities that don’t fit the regular type are returned as an instance of SI.So, when one calculates 1.0 / Speed(10, m/s), the answer is SI(0.1, ‘s/m’). If one would calculate 1.0 / SI(0.1, ‘s/m’), the answer is SI(10.0, ‘m/s’). With the as_quantity(type) method, this number can be transformed back to a Speed.

Attributes:
  • float() (float) – Internally, SI subclasses the float class and stores the si value as a float number.

  • _sisig (list[int]) – The SI signature stored as a list of 9 exponents for the defined SIUNITS. kgm/s2 is stored, e.g., as [0, 0, 1, 1, -2, 0, 0, 0, 0].

  • _unit (str) – The human readable version of the signature is stored as well, using a division sign to separate the positive from negative exponents. For the above example, _unit would have the value ‘kgm/s2’.

SIUNITS = ('rad', 'sr', 'kg', 'm', 's', 'A', 'K', 'mol', 'cd')

The SI units in the right order, as an immutable tuple. This tuple is not to be changed.

__init__(value: float, unit: str = '', **kwargs)[source]

Create an SI quantity. The si-value of the quantity is stored in the float superclass.

Raises:

ValueError – when the provided unit is not a legal SI unit

static str_to_sisig(unitstr: str) List[int][source]

Test and standardize the unit string, which can be of any of the following forms (used kgm2/s2 as an example): kgm2/s2, kgm^2/s^2, kgm2s-2, kgm^2s^-2, kg.m2/s2, kg.m^2/s^2, kg.m2.s-2, kg.m^2.s^-2.

Parameters:

unitstr (str) – The unit string that needs to be parsed.

Returns:

List with indices for the provided string, in the following order: [‘rad’, ‘sr’, ‘kg’, ‘m’, ‘s’, ‘A’, ‘K’, ‘mol’, ‘cd’]. For kgm2/s2, the return value would be: [0, 0, 0, 1, 2, -2, 0, 0, 0, 0].

Return type:

list[int]

Raises:

ValueError – when the string cannot be properly parsed.

property displayvalue: float

Return the display value of the quantity. For the SI unit, this is the stored value.

property si: float

Return the internal unit value of the SI quantity. For the SI unit, this is the stored value.

property unit: str

Return the SI-unit with which the quantity was defined.

sisig() List[int][source]

Return the internal SI signature as a list of exponents for the SI units. m/s would return [0, 0, 0, 1, -1, 0, 0, 0, 0]. Note that this is not defined as a property method, to keep it symmetric with the quantity.sisig() method.

as_quantity(quantity: Type[Quantity]) Q[source]

Return a new quantity that has been transformed from the SI value. The SI exponents have to match. So you cannot change an SI value with SI signature kgm/s2 into Length. The transformation will always use the base (SI) unit.

Parameters:

quantity (type) – The quantity to change the SI value into

Raises:
  • ValueError – when the SI units of the quantity don’t match with this SI value

  • TypeError – when the quantity is not of type Quantity

siunit(div: bool = True, hat: str = '', dot: str = '') str[source]

Method to return a string with the SI-signature of this SI value.

Parameters:
  • div – Defines whether to use a divisor (when div == True) or negative indices for the SI units (when div == False). When div is true, Force returns kgm/s2; when it is false, it returns kgms-2.

  • hat – Defines the hat sign to use for indices larger than 1. When set to ‘^’, Energy would return kgm^2/s^2. When left blank, kgm2/s2.

  • dot – Defines the dot sign to use between quantities. When set to ‘.’, ElectricalResistance would return kg.m2/s3.A2. When left blank, kgm2/s3A2. Combined with hat=’^’: kg.m^2/s^3.A^2

class pydsol.core.units.SIDist(wrapped_distribution: Distribution, unit: str)[source]

Bases: QuantityDist

Probability distribution for generic SI quantity

__init__(wrapped_distribution: Distribution, unit: str)[source]

Create a random distribution function that returns a quantity.

draw()[source]

Draw an SI quantity from the wrapped distribution