plesty.lib.data.units
Unit parsing, composition, and conversion utilities for Plesty.
Classes
Standardized unit expression parser and composer. |
Module Contents
- class plesty.lib.data.units.Units(dims: Dict[str, int] | None = None, factor: float = 1.0)
Standardized unit expression parser and composer.
The internal representation tracks: -
dims: dimension exponents, e.g. {“L”: 1, “T”: -1} for speed -factor: numeric scaling factor to SI base unitsInitialize a Units instance with dimension exponents and a scaling factor.
- Parameters:
dims (Optional[Dict[str, int]])
factor (float)
- SYMBOLS: dict[str, dict[str, Any]]
- BASE_SYMBOLS
- dims
- factor
- classmethod parse(unit_str: str | None) Units | None
Parse a unit string into a Units instance, returning None if unparseable.
- Parameters:
unit_str (Optional[str])
- Return type:
Optional[Units]
- classmethod standardize(unit_str: str | None) str | None
Return a normalized whitespace-free unit string, or None for empty input.
- Parameters:
unit_str (Optional[str])
- Return type:
Optional[str]
- compatible(other: Units) bool
Return True if this unit has the same dimensions as other.
- Parameters:
other (Units)
- Return type:
bool
- conversion_scale_to(target: Units) float
Return the numeric factor to convert this unit to the target unit.
- Parameters:
target (Units)
- Return type:
float
- power(exponent: int) Units
Return this unit raised to an integer exponent.
- Parameters:
exponent (int)
- Return type:
- to_unit_string() str | None
Render the unit dimensions as a human-readable string.
- Return type:
Optional[str]