mangadap.par.util module

Utility functions for parameter sets.


Copyright © 2019, SDSS-IV/MaNGA Pipeline Group


Provides a list of strings that should not be evaluated.

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.

  • 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 a from_dict method that instantiates the mangadap.par.parset.ParSet based on the provided subsection/subdict from cfg.

A list of instances of parsetclass parsed from the provided configuration data.

Return type:



ValueError – Raised if the indices of the subsections are not sequential and 1-indexed.


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, the mangadap.par.parset.ParSet.from_dict() methods expect the dictionary values to have the appropriate type. E.g., the configobj.ConfigObj will have something like d['foo'] = '1', when the mangadap.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 all k in d.keys().
Return type:dict