Parameter Set (parameters)#
Configure program parameter set.
|
|
|
|
Parameter set. |
|
|
Fetch a parameter set template, either as a YAML file (with explanatory text) or as a dictionary. |
- exception triumvirate.parameters.InvalidParameterError#
Bases:
ValueErrorValueErrorraised when a program parameter is invalid.
- exception triumvirate.parameters.NonParameterError#
Bases:
ValueErrorValueErrorraised when a program parameter is non-existent.
- class triumvirate.parameters.ParameterSet#
Bases:
objectParameter set.
This reads parameters from a file or a
dictobject, stores and prints out the extracted parameters, and validates the parameters.- Parameters:
param_filepath (str or
pathlib.Path, optional) – Parameter file path. This should point to a YAML file. If None (default), param_dict should be provided; otherwise param_dict should be None.param_dict (dict, optional) – Parameter dictionary (nested). If None (default), param_filepath should be provided; otherwise param_filepath should be None.
logger (
logging.Logger, optional) – Program logger (default is None).
- Raises:
ValueError – If neither or both of param_filepath and param_dict is/are None.
Tip
Use
fetch_paramset_template()to generate a template parameter file (with explanatory text).- get(self, key, *default_val)#
Return a possibly non-existent top-level parameter entry like
dict.get().- Parameters:
key (str) – Top-level parameter name, possibly non-existent.
default_val – Default value if the entry does not exist.
- Returns:
Top-level parameter value, None if non-existent.
- Return type:
- items(self)#
Return the full set of parameter entries like
dict.items().- Returns:
Parameters as dictionary items.
- Return type:
dict_items
- names(self)#
Return the full set of top-level parameter names like
dict.keys().- Returns:
Top-level parameter names as dictionary keys.
- Return type:
dict_keys
- print(self)#
Print the parameters as a dictionary with
pprint.pprint().
- save(self, filepath=None)#
Save validated parameters to a YAML file.
- Parameters:
filepath (str or
pathlib.Path, optional) – Saved file path. If None (default), parameters are saved to a default file path in the output measurement directory.
- update(self, *args, **kwargs)#
Update parameter set like
dict.update().
- triumvirate.parameters.fetch_paramset_template(format, ret_defaults=False)#
Fetch a parameter set template, either as a YAML file (with explanatory text) or as a dictionary.
The returned template parameters are not validated.
- Parameters:
format ({‘text’, ‘dict’}) – Template format, either as file content text (‘text’) or a dictionary (‘dict’).
ret_defaults (bool, optional) – If True (default is False), return a list of non-None default parameters in the template. Only used when format is ‘dict’.
- Returns:
template (str or dict) – Parameter set template as text or a dictionary.
defaults (dict) – Parameter set default entries. Only returned when format is ‘dict’ and ret_defaults is True.
- Raises:
ValueError – If format is neither ‘text’ nor ‘dict’.