SI Unit System Designed For Minimal Overhead – Built with speed by William Bowley
PicoUnits is a low overhead library designed for ensuring dimensional accuracy during runtime. It uses a custom seven fundamental unit system based off the standard SI metric fundamental units.
class SIBase(Enum):
""" SI metric fundamental units expect mass is defined as a gram """
SECOND = auto() # Time
METER = auto() # Length
GRAM = auto() # Mass
AMPERE = auto() # Electric Current
KELVIN = auto() # Temperature
MOLE = auto() # Amount of a substance
CANDELA = auto() # Luminous Intensity
DIMENSIONLESS = auto() # Non-physical quantityEach unit is made up of a subclass called Dimension which itself is made of two sub-dataclasses SIBase, PrefixScale and one integer value exponent:
@dataclass()
class Dimension:
"""
Defines a SI metric dimension through 'SIBase', 'PrefixScale and 'exponent'
"""
prefix: PrefixScale = PrefixScale.BASE
base: SIBase = SIBase.DIMENSIONLESS
exponent: int = 1
class Unit:
"""
Defines a SI metric unit composed of a singular or multiple 'Dimension'.
"""
def __init__(self, *dimensions: Dimension) -> None:
self.dimensions = list(dimensions)Each Quantity has both a magnitude and unit, and through the usage of dunder methods dimensional analysis happens in parallel with arithmetic operations.
@dataclass
class Quantity:
"""
Represents a quantity within the framework with both magnitude and unit
"""
magnitude: float | int
unit: UnitPicoUnits requires Python 3.10 or newer.
pip install picounits