@@ -43,6 +43,7 @@ class ParameterEntry:
43
43
Name : str
44
44
sValue : str
45
45
Comment : Optional [str ] = None
46
+ raw_entry : Optional [str ] = None
46
47
47
48
48
49
@dataclass
@@ -253,10 +254,10 @@ def ReadParameter(ParameterReadIn: ParameterEntry, ParamToModify, model):
253
254
"""
254
255
ReadParameter: A method to take a single ParameterEntry object and use it to update the associated Parameter.
255
256
Does validation as well as Unit and Currency conversion
256
- :param ParameterEntry : The value the user wants to change and the value they want to change it to (as a string)
257
+ :param ParameterReadIn : The value the user wants to change and the value they want to change it to (as a string)
257
258
and any comment they provided with it (as a string) - all in one object (ParameterEntry) that is passed in
258
259
to this method as a parameter itself (ParameterReadIn) - see ParameterEntry class for details on the fields in it
259
- :type ParameterEntry : :class:`~geophires_x.Parameter.ParameterEntry`
260
+ :type ParameterReadIn : :class:`~geophires_x.Parameter.ParameterEntry`
260
261
:param ParamToModify: The Parameter that will be modified (assuming it passes validation and conversion) - this is
261
262
the object that will be modified by this method - see Parameter class for details on the fields in it
262
263
:type ParamToModify: :class:`~geophires_x.Parameter.Parameter`
@@ -293,9 +294,9 @@ def ReadParameter(ParameterReadIn: ParameterEntry, ParamToModify, model):
293
294
294
295
def default_parameter_value_message (new_val : Any , param_to_modify_name : str , default_value : Any ) -> str :
295
296
return (
296
- f'Parameter given ({ str (New_val )} ) for { ParamToModify . Name } is the same as the default value. '
297
- f'Consider removing { ParamToModify . Name } from the input file unless you wish '
298
- f'to change it from the default value of ({ str (ParamToModify . DefaultValue )} )'
297
+ f'Parameter given ({ str (new_val )} ) for { param_to_modify_name } is the same as the default value. '
298
+ f'Consider removing { param_to_modify_name } from the input file unless you wish '
299
+ f'to change it from the default value of ({ str (default_value )} )'
299
300
)
300
301
301
302
if isinstance (ParamToModify , intParameter ):
@@ -370,16 +371,23 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
370
371
model .logger .warning (msg )
371
372
model .logger .info (f'Complete { str (__name__ )} : { sys ._getframe ().f_code .co_name } ' )
372
373
return
373
- # All is good. With a list, we have to use the last character of the Description to get the position.
374
- # I.e., "Gradient 1" should yield a position = 0 ("1" - 1)
375
374
else :
376
- parts = ParameterReadIn .Name .split (' ' )
377
- position = int (parts [1 ]) - 1
378
- if position >= len (ParamToModify .value ):
379
- ParamToModify .value .append (New_val ) # we are adding to the list, so use append
380
- else : # we are replacing a value, so pop the value we want to replace, then insert a new one
381
- ParamToModify .value .pop (position )
382
- ParamToModify .value .insert (position , New_val )
375
+ if ' ' in ParamToModify .Name :
376
+ # Some list parameters are read in with enumerated parameter names; in these cases we use the last
377
+ # character of the description to get the position i.e., "Gradient 1" is position 0.
378
+ parts = ParameterReadIn .Name .split (' ' )
379
+ position = int (parts [1 ]) - 1
380
+ if position >= len (ParamToModify .value ):
381
+ ParamToModify .value .append (New_val ) # we are adding to the list, so use append
382
+ else : # we are replacing a value, so pop the value we want to replace, then insert a new one
383
+ ParamToModify .value .pop (position )
384
+ ParamToModify .value .insert (position , New_val )
385
+ else :
386
+ # In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
387
+ # correct; however that would only be practical if ParameterEntry had typing information to know
388
+ # whether to treat text after a second comma as a comment or list entry.
389
+ ParamToModify .value = [float (x .strip ()) for x in ParameterReadIn .raw_entry .split ('--' )[0 ].split (',' )[1 :]
390
+ if x .strip () != '' ]
383
391
elif isinstance (ParamToModify , boolParameter ):
384
392
if ParameterReadIn .sValue == "0" :
385
393
New_val = False
0 commit comments