bluemira.base.parameter_frame._units
Functions
|
Validates the user input units and enforces our version of SI units |
Enforces our SI unit system and updates the value accordingly |
|
|
Reconstruct unit from its dimensionality. |
|
Converts angle units and combines non commutative units |
|
Combine commutative units |
Module Contents
- bluemira.base.parameter_frame._units._validate_units(param_data: bluemira.base.parameter_frame._parameter.ParamDictT, value_type: collections.abc.Iterable[type]) bluemira.base.parameter_frame._parameter.ParamDictT
Validates the user input units and enforces our version of SI units
- Returns:
Parameter dictionary
- Raises:
ValueError – If a value raises value error on a Quantity If a value doesnt have a unit
TypeError – When trying to convert offset or logarithmic units or strings/bools/None
- Parameters:
param_data (bluemira.base.parameter_frame._parameter.ParamDictT)
value_type (collections.abc.Iterable[type])
- Return type:
Notes
Firstly this ensures that scaling factors are folded into the value. Deals with empty values (None) and strings for parameters Finally where not one of the above converts to our opinionated SI units
- bluemira.base.parameter_frame._units._ensure_SI_unit_system(quantity: pint.Quantity, param_data: bluemira.base.parameter_frame._parameter.ParamDictT, value_type: collections.abc.Iterable[type]) bluemira.base.parameter_frame._parameter.ParamDictT
Enforces our SI unit system and updates the value accordingly
- Returns:
Parameter dictionary
- Parameters:
quantity (pint.Quantity)
param_data (bluemira.base.parameter_frame._parameter.ParamDictT)
value_type (collections.abc.Iterable[type])
- Return type:
Notes
Also deals with the case where a unit is collapsed to dimensionless with some scaling factor, then the value should be updated
- bluemira.base.parameter_frame._units._remake_units(quantity: pint.Quantity) pint.Quantity
Reconstruct unit from its dimensionality.
- Parameters:
quantity (pint.Quantity) – The quantity to reconstruct
- Returns:
The quantity in new units
- Return type:
pint.Quantity
Notes
The quantity of the conversion is not important here. We just want the custom SI version of the input The value conversion is done later.
- bluemira.base.parameter_frame._units._convert_non_commutative(unit_list: list[pint.Quantity], filter_index: list[int]) pint.Quantity
Converts angle units and combines non commutative units
Notes
Commutative here means units that we dont want to combine eg time and full power year
- Parameters:
unit_list (list[pint.Quantity])
filter_index (list[int])
- Return type:
pint.Quantity
- bluemira.base.parameter_frame._units._combine_commutative(unit_list: list[pint.Quantity], filter_index: list[int]) pint.Quantity
Combine commutative units
Notes
Uses pints milp optimisation which can over combine eg W/m^2 -> kg/s^3. The optimisation minimises combinations eg the “knapsack problem”. This function prioritise shorter original over new which could be improved in future
Commutative here means units that we dont want to combine eg time and full power year
- Parameters:
unit_list (list[pint.Quantity])
filter_index (list[int])
- Return type:
pint.Quantity