Quantity (Unit Handler)

Classes:

Quantity(value, unit_str)

Lightweight computational replacement for Pint in pyH2A.

UnitDictionary(quantity)

A custom dictionary class designed for lazy runtime unit evaluations.

Functions:

parse_composite_unit(unit_str)

Parse a composite unit (like 'kWh / cm2' or '(kWh * m)/m2') string into conversion multiplier, resulting composite base unit, and composite dimension.

test_quantity()

Run a simple, manual sanity check of quantity parsing and conversion.

class pyH2A.Utilities.Unit_Handler.quantity.Quantity(value, unit_str)[source]

Lightweight computational replacement for Pint in pyH2A.

The constructor parses the supplied unit into base units and a dimension string. Unit conversion is provided lazily through a UnitDictionary stored on self.unit.

class pyH2A.Utilities.Unit_Handler.quantity.UnitDictionary(quantity)[source]

A custom dictionary class designed for lazy runtime unit evaluations. Takes memory and performance into consideration by not calculating all unit conversions upfront. Guarantees that the ‘base_unit’ and ‘supplied_unit’ values are immediately present.

pyH2A.Utilities.Unit_Handler.quantity.parse_composite_unit(unit_str)[source]

Parse a composite unit (like ‘kWh / cm2’ or ‘(kWh * m)/m2’) string into conversion multiplier, resulting composite base unit, and composite dimension.

This function expands user-facing units (e.g., kWh / cm2 or (kWh * m)/m2) into: - a numerical multiplier to convert to base units, - a composite base-unit expression, and - a composite dimension expression.

Parameters:
unit_strstr

Unit expression that may include *, /, and parentheses.

Returns:
combined_multiplierfloat

Multiplier that converts unit_str into its composite base unit.

combined_base_strstr

Composite base unit expression (e.g., J / m2).

combined_dim_strstr

Composite dimension expression in the same operator layout.

Raises:
ValueError

If an unknown unit token is encountered or the expression cannot be evaluated.

pyH2A.Utilities.Unit_Handler.quantity.test_quantity()[source]

Run a simple, manual sanity check of quantity parsing and conversion.

Returns:
NoneNone

Prints example outputs to stdout.