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:
- 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
Methods
__init__([unit, base_factor])compatible()Attributes
siReturns the unit in base SI representation.
uReturns the unit label.