Utilities#

Units#

Utilities for handling physical units using Pint.

This module provides functions and types for working with physical units and quantities using the Pint library. It includes functionality to parse unit strings commonly found in FMU models and convert them to Pint units.

Classes:
  • QuantityType: Type alias for Pint Quantity.

  • QuantityClass: The Pint Quantity class.

Functions:
  • to_pint_unit(unit_str: str) -> Unit: Convert a unit string to a Pint Unit object.

  • fix_exponent(unit_str: str) -> str: Fix unit strings with exponents for Pint parsing.

class syssimx.utilities.units.Unit#

Bases: Unit

Unit of the default Pint UnitRegistry.

_REGISTRY = <pint.registry.UnitRegistry object>#
Parameters:
  • input_string (str)

  • case_sensitive (bool | None)

  • values (QuantityArgument)

Return type:

QuantityT

syssimx.utilities.units.UnitType#

The Pint Unit class.

syssimx.utilities.units.UnitClass#

The Pint Unit class.

class syssimx.utilities.units.Quantity#

Bases: Quantity

Quantity of the default Pint UnitRegistry.

_REGISTRY = <pint.registry.UnitRegistry object>#
Parameters:
  • input_string (str)

  • case_sensitive (bool | None)

  • values (QuantityArgument)

Return type:

QuantityT

syssimx.utilities.units.QuantityType#

The Pint Quantity class.

syssimx.utilities.units.QuantityClass#

The Pint Quantity class.

syssimx.utilities.units.fix_exponent(unit_str)[source]#

Fixes exponent notation in unit strings for Pint parsing.

FMU unit strings may be in the form “s-2” or “s2” and are not recognized by pint. Adds “^” between any character and a number to allow parsing by pint.

Parameters:

unit_str (str) – The unit string to fix.

Return type:

str

syssimx.utilities.units.to_pint_unit(unit_str)[source]#

Convert a unit string to a Pint Unit object. :param unit_str: The unit string to convert.

Returns:

Pint Unit object corresponding to the input string.

Parameters:

unit_str (str | Unit | None)