Unit¶
- class component_model.variable.Unit¶
Bases:
objectHelper class to store and manage units and display units, i.e. base unit of variable and unit differences ‘outside’ and ‘inside’ the model.
One Unit object represents one scalar variable.
- __init__()¶
Methods
__init__()compatible(quantity, ureg[, typ, strict])Check whether the supplied quantity 'q' is compatible with this unit.
derivative(baseunits[, tu])Construct units for a derivative variable of basevars.
identity(x)linear(x, b[, a])make(quantity, ureg[, typ])make_tuple(quantities, ureg[, typ])Make a tuple of Unit objects from the tuple of quantities.
parse_quantity(quantity, ureg[, typ])Parse the provided quantity in terms of magnitude and unit, if provided as string.
val_unit_display(q, ureg)Identify base units and calculate the transformations between display and base units.
- classmethod derivative(baseunits: tuple[Unit, ...], tu: str = 's') tuple[tuple[float, ...], tuple[Unit, ...]]¶
Construct units for a derivative variable of basevars. tu is the time unit.
- classmethod identity(x: float)¶
- classmethod linear(x: float, b: float, a: float = 0.0)¶
- classmethod make(quantity: str | int | float | bool | Enum, ureg: UnitRegistry, typ: type | None = None) tuple[tuple[str | int | float | bool | Enum], tuple[Unit]]¶
- classmethod make_tuple(quantities: tuple | list | ndarray, ureg: UnitRegistry, typ: type | None = None) tuple[tuple[str | int | float | bool | Enum, ...], tuple[Unit, ...]]¶
Make a tuple of Unit objects from the tuple of quantities.
- compatible(quantity: str | int | float | bool | Enum, ureg: UnitRegistry, typ: type | None = None, strict: bool = True) tuple[bool, str | int | float | bool | Enum]¶
Check whether the supplied quantity ‘q’ is compatible with this unit. If strict==True, the supplied quantity shall be in display units.
- parse_quantity(quantity: str | int | float | bool | Enum, ureg: UnitRegistry, typ: type | None = None) str | int | float | bool | Enum¶
Parse the provided quantity in terms of magnitude and unit, if provided as string. If another type is provided, dimensionless units are assumed.
- Parameters:
quantity (PyType) – the quantity to disect. Should be provided as string, but also the trivial cases (int,float,Enum) are allowed.
warning (A free string should not be used and leads to a)
- Returns:
the magnitude in base units, the base unit and the unit as given (display units), together with the conversion functions between the units.
- val_unit_display(q: Quantity, ureg: UnitRegistry) float¶
Identify base units and calculate the transformations between display and base units.
- Returns:
The numerical value of q. As side effect
* the unit u is set. Might be dimensionless
* the display unit du is set to None if same as unit, else –
it is set to the display unit name and
the transformations to_base and from_base are set.