@@ -595,23 +595,26 @@ def ConvertUnitsBack(ParamToModify: Parameter, model):
595
595
:return: None
596
596
"""
597
597
model .logger .info (f'Init { str (__name__ )} : { sys ._getframe ().f_code .co_name } for { ParamToModify .Name } ' )
598
- # param_modified: Parameter = parameter_with_units_converted_back_to_preferred_units(ParamToModify, model)
599
- # ParamToModify.value = param_modified.value
600
- # ParamToModify.CurrentUnits = param_modified.CurrentUnits
601
- # ParamToModify.UnitType = param_modified.UnitType
602
598
603
599
try :
604
600
ParamToModify .value = _ureg .Quantity (ParamToModify .value , ParamToModify .CurrentUnits .value ).to (ParamToModify .PreferredUnits .value ).magnitude
605
601
ParamToModify .CurrentUnits = ParamToModify .PreferredUnits
606
602
except AttributeError as ae :
607
- # FIXME WIP
608
- model .logger .warning (f'Error: { ae } ' )
609
- #ParamToModify.UnitType = param_modified.UnitType
603
+ model .logger .warning (f'Failed to convert units with pint, falling back to legacy conversion heuristics ({ ae } )' )
604
+
605
+ param_modified : Parameter = parameter_with_units_converted_back_to_preferred_units (ParamToModify , model )
606
+ ParamToModify .value = param_modified .value
607
+ ParamToModify .CurrentUnits = param_modified .CurrentUnits
608
+ ParamToModify .UnitType = param_modified .UnitType
610
609
611
610
model .logger .info (f'Complete { str (__name__ )} : { sys ._getframe ().f_code .co_name } ' )
612
611
613
612
614
613
def parameter_with_units_converted_back_to_preferred_units (param : Parameter , model ) -> Parameter :
614
+ """
615
+ TODO clean up and consolidate with pint-based conversion in ConvertUnitsBack
616
+ """
617
+
615
618
param_with_units_converted_back = copy .deepcopy (param )
616
619
617
620
# deal with the currency case
@@ -856,6 +859,9 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
856
859
"""
857
860
ConvertOutputUnits Given an output parameter, convert the value(s) from what they contain
858
861
(as calculated by GEOPHIRES) to what the user specified as what they want for outputs. Conversion happens inline.
862
+
863
+ TODO switch to pint-based conversion like in ConvertUnitsBack
864
+
859
865
:param oparam: The parameter you want to be converted (value or list of values). Because Parameters know the
860
866
PreferredUnits and CurrentUnits, this routine knows what to do. It will convert the value(s) in the parameter
861
867
to the new units, and then reset the CurrentUnits to the new units. This is done so that the user can see the units
0 commit comments