Skip to content

wgbowley/PicoUnits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PicoUnits
SI Unit System Designed For Minimal Overhead – Built with speed by William Bowley

Overview

Work in Progress Python Version License

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 quantity

Each 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: Unit

Installation

PicoUnits requires Python 3.10 or newer.

pip install picounits

About

A minimal, embeddable kernel for explicit units and dimensional analysis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages