pypeit.par.util module

Utility functions for PypeIt parameter sets

pypeit.par.util._eval_ignore()[source]

Provides a list of strings that should not be evaluated.

pypeit.par.util.parset_to_dict(par)[source]

Convert the provided parset into a dictionary.

Parameters:

par (ParSet)

Returns:

Converted ParSet

Return type:

dict

pypeit.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 results in a dictionary that contains strings or lists of strings. However, when assigning the values for the various ParSets, the from_dict methods expect the dictionary values to have the appropriate type. E.g., the configobj will have something like d[‘foo’] = ‘1’, when the 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 above in the _eval_ignore() function. Any value in this list or where:

ast_literal_eval(d[k]) for k in d.keys()

raises an exception is returned as the original string.

This is currently only used in from_cfg_file(); see further comments there.

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