@@ -281,7 +281,7 @@ def __post_init__(self):
281281 json_parameter_type : str = _JSON_PARAMETER_TYPE_ARRAY
282282
283283
284- def ReadParameter (ParameterReadIn : ParameterEntry , ParamToModify , model ):
284+ def ReadParameter (ParameterReadIn : ParameterEntry , ParamToModify , model ) -> None :
285285 """
286286 ReadParameter: A method to take a single ParameterEntry object and use it to update the associated Parameter.
287287 Does validation as well as Unit and Currency conversion
@@ -393,35 +393,78 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
393393 ParamToModify .Provided = True # set provided to true because we are using a user provide value now
394394 ParamToModify .Valid = True # set Valid to true because it passed the validation tests
395395 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
396+ if ' ' in ParamToModify .Name :
397+ New_val = float (ParameterReadIn .sValue )
398+ # Some list parameters are read in with enumerated parameter names; in these cases we use the last
399+ # character of the description to get the position i.e., "Gradient 1" is position 0.
400+ parts = ParameterReadIn .Name .split (' ' )
401+ position = int (parts [1 ]) - 1
402+ if position >= len (ParamToModify .value ):
403+ ParamToModify .value .append (New_val ) # we are adding to the list, so use append
404+ else : # we are replacing a value, so pop the value we want to replace, then insert a new one
405+ ParamToModify .value .pop (position )
406+ ParamToModify .value .insert (position , New_val )
408407 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 () != '' ]
408+ # In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
409+ # correct; however that would only be practical if ParameterEntry had typing information to know
410+ # whether to treat text after a second comma as a comment or list entry.
411+ ParamToModify .value = [float (x .strip ()) for x in ParameterReadIn .raw_entry .split ('--' )[0 ].split (',' )[1 :]
412+ if x .strip () != '' ]
413+
414+ # FIXME WIP TODO validate entries comply with min/max (as implemented in commented code below)
415+
416+ # def _read_list_parameter():
417+ # read_list = []
418+ # if ParameterReadIn.raw_entry is None:
419+ # # Shouldn't happen...
420+ # model.logger.error(f'Invalid parameter entry for {ParamToModify.Name}: {ParameterReadIn.sValue}')
421+ # return
422+ #
423+ # raw_split = ParameterReadIn.raw_entry.split(',')
424+ # for i in range(len(raw_split)):
425+ # raw_entry = raw_split[i].strip()
426+ # read_entry = raw_entry
427+ # try:
428+ # read_entry = float(raw_entry)
429+ # except ValueError:
430+ # if i == len(raw_split) - 1:
431+ # pass # assumed to be comment
432+ # else:
433+ # model.logger.error(f'Invalid parameter entry for {ParamToModify.Name}: {raw_entry}')
434+ #
435+ # read_list.append(read_entry)
436+
437+ # _read_list_parameter()
438+
439+ # New_val = float(ParameterReadIn.sValue)
440+ # if (New_val < float(ParamToModify.Min)) or (New_val > float(ParamToModify.Max)):
441+ # # user provided value is out of range, so announce it, leave set to whatever it was set to (default value)
442+ # if len(ParamToModify.ErrMessage) > 0:
443+ # msg = (
444+ # f'Parameter given ({str(New_val)}) for {ParamToModify.Name} outside of valid range.'
445+ # f'GEOPHIRES will {ParamToModify.ErrMessage}'
446+ # )
447+ # print(f'Warning: {msg}')
448+ # model.logger.warning(msg)
449+ # model.logger.info(f'Complete {str(__name__)}: {sys._getframe().f_code.co_name}')
450+ # return
451+ # else:
452+ # if ' ' in ParamToModify.Name:
453+ # # Some list parameters are read in with enumerated parameter names; in these cases we use the last
454+ # # character of the description to get the position i.e., "Gradient 1" is position 0.
455+ # parts = ParameterReadIn.Name.split(' ')
456+ # position = int(parts[1]) - 1
457+ # if position >= len(ParamToModify.value):
458+ # ParamToModify.value.append(New_val) # we are adding to the list, so use append
459+ # else: # we are replacing a value, so pop the value we want to replace, then insert a new one
460+ # ParamToModify.value.pop(position)
461+ # ParamToModify.value.insert(position, New_val)
462+ # else:
463+ # # In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
464+ # # correct; however that would only be practical if ParameterEntry had typing information to know
465+ # # whether to treat text after a second comma as a comment or list entry.
466+ # ParamToModify.value = [float(x.strip()) for x in ParameterReadIn.raw_entry.split('--')[0].split(',')[1:]
467+ # if x.strip() != '']
425468 elif isinstance (ParamToModify , boolParameter ):
426469 if ParameterReadIn .sValue == "0" :
427470 New_val = False
0 commit comments