antupy.Unit#

class antupy.Unit(unit: str = '-', base_factor: float = 1.0)[source]#

Class containing any unit valid with SI unit system. To initiate it, pass a “unit label”, which correspond to a valid str. It converts it internally to a base representation, which is a dictionary with the 7 base SI units as keys and their respective exponents as values.

Parameters:
  • unit (str, optional) – Valid string with the unit label, e.g. “kg-m/s2”. Default is “-” (dimensionless).

  • base_factor (float, optional) – Multiplicative factor to convert to base SI units. Default is 1.0.

label_unit#

The original unit label string.

Type:

str

base_factor#

Multiplicative factor to convert to base SI units.

Type:

float

base_units#

Dictionary with the 7 base SI units as keys and their respective exponents as values.

Type:

UnitDict

Examples

Creating units from labels:

>>> u1 = Unit("kg-m/s2")
>>> print(u1)
[kg-m/s2]
>>> print(u1.si)
1.00e+03[m-g/s2]

Unit equivalence:

>>> u2 = Unit("N")
>>> print(u2)
[N]
>>> print(u2.si)
1.00e+03[m-g/s2]
>>> u1 == u2
True

Notes

The base representation uses seven SI base units: meter (m), gram (g), second (s), ampere (A), kelvin (K), mole (mol), and candela (cd). Note that gram is used instead of kilogram to simplify prefix handling.

See also

Var

Variable class that uses Unit for dimensional consistency

Array

Array class that uses Unit for dimensional consistency

__init__(unit: str = '-', base_factor: float = 1.0)[source]#
Parameters:

Methods

__init__([unit, base_factor])

compatible()

Attributes

si

Returns the unit in base SI representation.

u

Returns the unit label.