mangadap.par.util module
Utility functions for parameter sets.
Copyright © 2019, SDSS-IV/MaNGA Pipeline Group
- mangadap.par.util.get_parset_list(cfg, pk, parsetclass)[source]
Create a list of
mangadap.par.parset.ParSet
objects based on a root keyword for a set of defined groups in the configuration file.For example, the a parameter group could allow for a list of parset objects instead of a single one. This function parses the provided configuration object (
cfg
) to find any sections with a string keyword (pk) as its root. The remainder of the section name must be able to be converted to an integer and the section itself must be able to setup an instance of parsetclass. The sections must be number sequentially from 1..N.- Parameters:
cfg (configobj.ConfigObj,
dict
) – The top-level configuration that defines a list of sub-ParSets.pk (
str
) – The root of the keywords used to set a list of sub-ParSets.parsetclass (
mangadap.par.parset.ParSet
) – The class used to construct each element in the list of parameter subsets. The class must have afrom_dict
method that instantiates themangadap.par.parset.ParSet
based on the provided subsection/subdict fromcfg
.
- Returns:
A list of instances of
parsetclass
parsed from the provided configuration data.- Return type:
list
- Raises:
ValueError – Raised if the indices of the subsections are not sequential and 1-indexed.
- mangadap.par.util.recursive_dict_evaluate(d)[source]
Recursively run eval on each element of the provided dictionary.
A raw read of a configuration file with configobj.ConfigObj results in a dictionary that contains strings or lists of strings. However, when assigning the values for the various
mangadap.par.parset.ParSet
objects, themangadap.par.parset.ParSet.from_dict()
methods expect the dictionary values to have the appropriate type. E.g., the configobj.ConfigObj will have something liked['foo'] = '1'
, when themangadap.par.parset.ParSet.from_dict()
method expects the value to be an integer (d['foo'] = 1
).This function tries to evaluate all dictionary values, except for those listed by the
_eval_ignore()
function. Any value in this list or where:eval(d[k]) for k in d.keys()
raises an exception and is returned as the original string.
- Parameters:
d (
dict
) – Dictionary of values to evaluate- Returns:
Identical to input dictionary, but with all string values replaced with the result of
eval(d[k])
for allk
ind.keys()
.- Return type:
dict
- mangadap.par.util.recursive_dict_str_to_None(d)[source]
Recursively run any string values of ‘None’ in a dictionary to be explicitly None.
- Parameters:
d (
dict
) – Dictionary of values to evaluate- Returns:
Identical to input dictionary, but with all string values of ‘None’ set to None explicitly. The input dictionary is altered directly.
- Return type:
dict