22
22
from geophires_x .OptionList import EndUseOptions , EconomicModel , ReservoirModel , FractureShape , ReservoirVolume , \
23
23
PlantType
24
24
from geophires_x .GeoPHIRESUtils import UpgradeSymbologyOfUnits , render_default , InsertImagesIntoHTML
25
+ from geophires_x .Parameter import Parameter
25
26
26
27
NL = '\n '
27
28
validFilenameChars = "-_.() %s%s" % (string .ascii_letters , string .digits )
@@ -639,24 +640,29 @@ def __init__(self, model:Model, output_file:str ='HDR.out'):
639
640
model .logger .info (f'Init { __class__ !s} : { __name__ } ' )
640
641
self .ParameterDict = {}
641
642
self .OutputParameterDict = {}
643
+ self .filepath_parameter_names = []
642
644
643
- self .text_output_file = self .ParameterDict [self .text_output_file .Name ] = strParameter (
645
+ def file_path_parameter (p : Parameter ) -> Parameter :
646
+ self .filepath_parameter_names .append (p .Name )
647
+ return p
648
+
649
+ self .text_output_file = self .ParameterDict [self .text_output_file .Name ] = file_path_parameter (strParameter (
644
650
'Improved Text Output File' ,
645
651
DefaultValue = 'GEOPHIRES_Text.html' ,
646
652
Required = False ,
647
653
Provided = False ,
648
654
ErrMessage = 'assume no improved text output' ,
649
655
ToolTipText = 'Provide a improved text output name if you want to have improved text output (no output if not provided)' ,
650
- )
656
+ ) )
651
657
652
- self .html_output_file = self .ParameterDict [self .html_output_file .Name ] = strParameter (
658
+ self .html_output_file = self .ParameterDict [self .html_output_file .Name ] = file_path_parameter ( strParameter (
653
659
'HTML Output File' ,
654
660
DefaultValue = 'GEOPHIRES.html' ,
655
661
Required = False ,
656
662
Provided = False ,
657
663
ErrMessage = 'assume no HTML output' ,
658
664
ToolTipText = 'Provide a HTML output name if you want to have HTML output (no output if not provided)' ,
659
- )
665
+ ) )
660
666
661
667
self .printoutput = self .ParameterDict [self .printoutput .Name ] = boolParameter (
662
668
'Print Output to Console' ,
@@ -677,7 +683,7 @@ def __init__(self, model:Model, output_file:str ='HDR.out'):
677
683
def __str__ (self ):
678
684
return 'Outputs'
679
685
680
- def read_parameters (self , model :Model ) -> None :
686
+ def read_parameters (self , model : Model , default_output_path : Path = None ) -> None :
681
687
"""
682
688
The read_parameters function reads in the parameters from a dictionary and stores them in the parameters.
683
689
It also handles special cases that need to be handled after a value has been read in and checked.
@@ -692,6 +698,7 @@ def read_parameters(self, model:Model) -> None:
692
698
to call this method from you class, which can effectively modify all these superclass parameters in your class.
693
699
:param model: The container class of the application, giving access to everything else, including the logger
694
700
:type model: :class:`~geophires_x.Model.Model`
701
+ :param default_output_path: Relative path for non-absolute output path parameters
695
702
:return: None
696
703
"""
697
704
model .logger .info (f'Init { __class__ !s} : { __name__ } ' )
@@ -702,6 +709,15 @@ def read_parameters(self, model:Model) -> None:
702
709
key = ParameterToModify .Name .strip ()
703
710
if key in model .InputParameters :
704
711
ParameterReadIn = model .InputParameters [key ]
712
+
713
+ if key in self .filepath_parameter_names :
714
+ if not Path (ParameterReadIn .sValue ).is_absolute ():
715
+ original_val = ParameterReadIn .sValue
716
+ ParameterReadIn .sValue = str (
717
+ default_output_path .joinpath (ParameterReadIn .sValue ).absolute ())
718
+ model .logger .info (f'Adjusted { key } path to { ParameterReadIn .sValue } because original value '
719
+ f'({ original_val } ) was not an absolute path.' )
720
+
705
721
# Before we change the parameter, let's assume that the unit preferences will match
706
722
# - if they don't, the later code will fix this.
707
723
ParameterToModify .CurrentUnits = ParameterToModify .PreferredUnits
0 commit comments