Skip to content

Commit a6de4c1

Browse files
TODOs re: remaining pint-based conversion refactoring
1 parent 1dabaf8 commit a6de4c1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/geophires_x/Parameter.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,23 +595,26 @@ def ConvertUnitsBack(ParamToModify: Parameter, model):
595595
:return: None
596596
"""
597597
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
602598

603599
try:
604600
ParamToModify.value = _ureg.Quantity(ParamToModify.value, ParamToModify.CurrentUnits.value).to(ParamToModify.PreferredUnits.value).magnitude
605601
ParamToModify.CurrentUnits = ParamToModify.PreferredUnits
606602
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
610609

611610
model.logger.info(f'Complete {str(__name__)}: {sys._getframe().f_code.co_name}')
612611

613612

614613
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+
615618
param_with_units_converted_back = copy.deepcopy(param)
616619

617620
# deal with the currency case
@@ -856,6 +859,9 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
856859
"""
857860
ConvertOutputUnits Given an output parameter, convert the value(s) from what they contain
858861
(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+
859865
:param oparam: The parameter you want to be converted (value or list of values). Because Parameters know the
860866
PreferredUnits and CurrentUnits, this routine knows what to do. It will convert the value(s) in the parameter
861867
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

Comments
 (0)