@@ -281,7 +281,7 @@ def __post_init__(self):
281
281
json_parameter_type : str = _JSON_PARAMETER_TYPE_ARRAY
282
282
283
283
284
- def ReadParameter (ParameterReadIn : ParameterEntry , ParamToModify , model ):
284
+ def ReadParameter (ParameterReadIn : ParameterEntry , ParamToModify , model ) -> None :
285
285
"""
286
286
ReadParameter: A method to take a single ParameterEntry object and use it to update the associated Parameter.
287
287
Does validation as well as Unit and Currency conversion
@@ -393,35 +393,8 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
393
393
ParamToModify .Provided = True # set provided to true because we are using a user provide value now
394
394
ParamToModify .Valid = True # set Valid to true because it passed the validation tests
395
395
elif isinstance (ParamToModify , listParameter ):
396
- New_val = float (ParameterReadIn .sValue )
397
- if (New_val < float (ParamToModify .Min )) or (New_val > float (ParamToModify .Max )):
398
- # user provided value is out of range, so announce it, leave set to whatever it was set to (default value)
399
- if len (ParamToModify .ErrMessage ) > 0 :
400
- msg = (
401
- f'Parameter given ({ str (New_val )} ) for { ParamToModify .Name } outside of valid range.'
402
- f'GEOPHIRES will { ParamToModify .ErrMessage } '
403
- )
404
- print (f'Warning: { msg } ' )
405
- model .logger .warning (msg )
406
- model .logger .info (f'Complete { str (__name__ )} : { sys ._getframe ().f_code .co_name } ' )
407
- return
408
- else :
409
- if ' ' in ParamToModify .Name :
410
- # Some list parameters are read in with enumerated parameter names; in these cases we use the last
411
- # character of the description to get the position i.e., "Gradient 1" is position 0.
412
- parts = ParameterReadIn .Name .split (' ' )
413
- position = int (parts [1 ]) - 1
414
- if position >= len (ParamToModify .value ):
415
- ParamToModify .value .append (New_val ) # we are adding to the list, so use append
416
- else : # we are replacing a value, so pop the value we want to replace, then insert a new one
417
- ParamToModify .value .pop (position )
418
- ParamToModify .value .insert (position , New_val )
419
- else :
420
- # In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
421
- # correct; however that would only be practical if ParameterEntry had typing information to know
422
- # whether to treat text after a second comma as a comment or list entry.
423
- ParamToModify .value = [float (x .strip ()) for x in ParameterReadIn .raw_entry .split ('--' )[0 ].split (',' )[1 :]
424
- if x .strip () != '' ]
396
+ _read_list_parameter (ParameterReadIn , ParamToModify , model )
397
+
425
398
elif isinstance (ParamToModify , boolParameter ):
426
399
if ParameterReadIn .sValue == "0" :
427
400
New_val = False
@@ -449,6 +422,47 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
449
422
model .logger .info (f'Complete { str (__name__ )} : { sys ._getframe ().f_code .co_name } ' )
450
423
451
424
425
+ def _read_list_parameter (ParameterReadIn : ParameterEntry , ParamToModify , model ) -> None :
426
+ """
427
+ :type ParamToModify: :class:`~geophires_x.Parameter.Parameter`
428
+ :type model: :class:`~geophires_x.Model.Model`
429
+ """
430
+
431
+ if ' ' in ParamToModify .Name :
432
+ New_val = float (ParameterReadIn .sValue )
433
+ # Some list parameters are read in with enumerated parameter names; in these cases we use the last
434
+ # character of the description to get the position i.e., "Gradient 1" is position 0.
435
+ parts = ParameterReadIn .Name .split (' ' )
436
+ position = int (parts [1 ]) - 1
437
+ if position >= len (ParamToModify .value ):
438
+ ParamToModify .value .append (New_val ) # we are adding to the list, so use append
439
+ else : # we are replacing a value, so pop the value we want to replace, then insert a new one
440
+ ParamToModify .value .pop (position )
441
+ ParamToModify .value .insert (position , New_val )
442
+ else :
443
+ # In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
444
+ # correct; however that would only be practical if ParameterEntry had typing information to know
445
+ # whether to treat text after a second comma as a comment or list entry.
446
+ ParamToModify .value = [float (x .strip ()) for x in ParameterReadIn .raw_entry .split ('--' )[0 ].split (',' )[1 :]
447
+ if x .strip () != '' ]
448
+
449
+ ParamToModify .Provided = True
450
+
451
+ valid = True
452
+ for i in range (len (ParamToModify .value )):
453
+ New_val = ParamToModify .value [i ]
454
+ if (New_val < float (ParamToModify .Min )) or (New_val > float (ParamToModify .Max )):
455
+ msg = (
456
+ f'Value given ({ str (New_val )} ) for { ParamToModify .Name } outside of valid range '
457
+ f'({ ParamToModify .Min } –{ ParamToModify .Max } ).'
458
+ )
459
+ print (f'Warning: { msg } ' )
460
+ model .logger .warning (msg )
461
+ valid = False
462
+
463
+ ParamToModify .Valid = valid
464
+
465
+
452
466
def ConvertUnits (ParamToModify , strUnit : str , model ) -> str :
453
467
"""
454
468
ConvertUnits gets called if a unit version is needed: either currency or standard units like F to C or m to ft
0 commit comments