Skip to content

Commit 1227b93

Browse files
Minor code cleanup
1 parent 4361af0 commit 1227b93

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

src/geophires_x/Outputs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,17 +636,18 @@ class Outputs:
636636
"""
637637
This class handles all the outputs for the GEOPHIRESv3 model.
638638
"""
639+
639640
def __init__(self, model:Model, output_file:str ='HDR.out'):
640641
model.logger.info(f'Init {__class__!s}: {__name__}')
641642
self.ParameterDict = {}
642643
self.OutputParameterDict = {}
643644
self.filepath_parameter_names = []
644645

645-
def file_path_parameter(p: Parameter) -> Parameter:
646+
def filepath_parameter(p: Parameter) -> Parameter:
646647
self.filepath_parameter_names.append(p.Name)
647648
return p
648649

649-
self.text_output_file = self.ParameterDict[self.text_output_file.Name] = file_path_parameter(strParameter(
650+
self.text_output_file = self.ParameterDict[self.text_output_file.Name] = filepath_parameter(strParameter(
650651
'Improved Text Output File',
651652
DefaultValue='GEOPHIRES_Text.html',
652653
Required=False,
@@ -655,7 +656,7 @@ def file_path_parameter(p: Parameter) -> Parameter:
655656
ToolTipText='Provide a improved text output name if you want to have improved text output (no output if not provided)',
656657
))
657658

658-
self.html_output_file = self.ParameterDict[self.html_output_file.Name] = file_path_parameter(strParameter(
659+
self.html_output_file = self.ParameterDict[self.html_output_file.Name] = filepath_parameter(strParameter(
659660
'HTML Output File',
660661
DefaultValue='GEOPHIRES.html',
661662
Required=False,
@@ -699,6 +700,7 @@ def read_parameters(self, model: Model, default_output_path: Path = None) -> Non
699700
:param model: The container class of the application, giving access to everything else, including the logger
700701
:type model: :class:`~geophires_x.Model.Model`
701702
:param default_output_path: Relative path for non-absolute output path parameters
703+
:type default_output_path: pathlib.Path
702704
:return: None
703705
"""
704706
model.logger.info(f'Init {__class__!s}: {__name__}')

src/geophires_x/SUTRAOutputs.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,8 @@ def PrintOutputs(self, model: Model):
4747
"""
4848
model.logger.info(f'Init {str(__class__)}: {sys._getframe().f_code.co_name}')
4949

50-
# Deal with converting Units back to PreferredUnits, if required.
51-
# before we write the outputs, we go thru all the parameters for all of the objects and set the values back
52-
# to the units that the user entered the data in
53-
# We do this because the value may be displayed in the output, and we want the user to recognize their value,
54-
# not some converted value
55-
# for obj in [model.reserv, model.wellbores, model.surfaceplant, model.economics]:
56-
# for key in obj.ParameterDict:
57-
# param = obj.ParameterDict[key]
58-
# if not param.UnitsMatch: ConvertUnitsBack(param, model)
59-
60-
# now we need to loop through all thw output parameters to update their units to
61-
# whatever units the user has specified.
62-
# i.e., they may have specified that all LENGTH results must be in feet, so we need to convert those
63-
# from whatever LENGTH unit they are to feet.
64-
# same for all the other classes of units (TEMPERATURE, DENSITY, etc).
65-
66-
#for obj in [model.reserv, model.wellbores, model.surfaceplant, model.economics]:
67-
# for key in obj.OutputParameterDict:
68-
# if key in self.ParameterDict:
69-
# if self.ParameterDict[key] != obj.OutputParameterDict[key].CurrentUnits:
70-
# ConvertOutputUnits(obj.OutputParameterDict[key], self.ParameterDict[key], model)
7150

7251
# write results to output file and screen
73-
7452
try:
7553
with open(self.output_file,'w', encoding='UTF-8') as f:
7654
f.write(' *****************\n')
@@ -181,10 +159,10 @@ def PrintOutputs(self, model: Model):
181159
except BaseException as ex:
182160
tb = sys.exc_info()[2]
183161
print(str(ex))
184-
print("Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb.tb_lineno)
162+
msg = "Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb.tb_lineno
163+
print(msg)
185164
model.logger.critical(str(ex))
186-
model.logger.critical("Error: GEOPHIRES Failed to write the output file. Exiting....Line %i" % tb.tb_lineno)
187-
# FIXME raise exception instead of sys.exit()
188-
sys.exit()
165+
model.logger.critical(msg)
166+
raise RuntimeError(msg)
189167

190168
model.logger.info(f'Complete {str(__class__)}: {sys._getframe().f_code.co_name}')

0 commit comments

Comments
 (0)