Parameters

class sofia_redux.pipeline.parameters.Parameters(default=None)[source]

Bases: object

Container class for all parameters needed for a reduction.

Attributes:
currentlist of ParameterSet

A list of parameters corresponding to a reduction recipe: one ParameterSet object per reduction step.

stepnameslist of str

Reduction step names corresponding to current parameters.

defaultdict

Keys are reduction step names; values are default ParameterSet objects for the step.

Initialize the parameters.

The default attribute is populated with ParameterSet objects based on the values provided in the default parameter.

Parameters:
defaultdict, optional

Default values for all known parameters for the reduction steps. The keys should be the reduction step name, and the values a dictionary of parameter set values, corresponding to any desired options for ParameterSet.set_param.

Methods Summary

add_current_parameters(stepname)

Add a parameter set to the current list.

copy()

Return a copy of the parameters.

fix_param_type(value, dtype)

Cast a value to its expected data type.

from_config(config)

Set parameter values from a configuration object.

get_param_type(value)

Infer a parameter data type from an existing value.

to_config()

Read parameter values into a configuration object.

to_text()

Print the current parameters to a text list.

Methods Documentation

add_current_parameters(stepname)[source]

Add a parameter set to the current list.

If the step name is found in the self.default attribute, then the associated default ParameterSet is appended to the self.current list. Otherwise, an empty ParameterSet is appended. The stepname is stored in self.stapnames.

Parameters:
stepnamestr

Name of the reduction step

copy()[source]

Return a copy of the parameters.

Returns:
Parameters
static fix_param_type(value, dtype)[source]

Cast a value to its expected data type.

This function helps update parameters in ParameterSet objects when the data type of the parameters is not known to match its expected data type. For example, if the value is read from a text widget, but the data type is numerical, it can cast the data to its expected form. Any problems with converting the value to its expected format cause the value to be returned as a string.

Parameters:
valuestr, float, int, bool, or list

The input value to cast

dtype{‘str’, ‘int’, ‘float’, ‘bool’, ‘strlist’, ‘intlist’, ‘floatlist’, ‘boollist’}

The data type, as expected by a ParameterSet object.

Returns:
str, float, int, bool, or list

The data type, converted to dtype if possible.

from_config(config)[source]

Set parameter values from a configuration object.

This function expects reduction step names as the keys of the configuration dictionary (the section headers in INI format). The step name may be recorded in either stepindex: stepname format, or as stepname alone, if no step names are repeated in the reduction recipe.

Parameters:
configstr, dict, or ConfigObj

Configuration file or object. May be any type accepted by the configobj.ConfigObj constructor.

Raises:
ValueError

If the step names in the configuration file/object and the currently loaded stepnames do not match.

static get_param_type(value)[source]

Infer a parameter data type from an existing value.

This function helps format parameters into ParameterSet objects when the data type of the parameters is not separately recorded. It attempts to determine if the input data is a one of the supported simple types (str, float, int, or bool), or if it is a list of any of these simple types. List element type is determined from the first element in the array. Any value for which the type cannot be determined is treated as a string.

Parameters:
valuestr, float, int, bool, list, or object

The parameter value to be tested.

Returns:
{‘str’, ‘int’, ‘float’, ‘bool’, ‘strlist’, ‘intlist’, ‘floatlist’, ‘boollist’}

The inferred data type of the input value.

to_config()[source]

Read parameter values into a configuration object.

Section names in the output object are written as stepindex: stepname in order to record the order of reduction steps, and to keep any repeated step names uniquely identified. Only the current parameter values are recorded. Other information, such as data or widget type or default values, is lost.

Returns:
ConfigObj

The parameter values in a configobj.ConfigObj object.

to_text()[source]

Print the current parameters to a text list.

Returns:
list of str

The parameters in INI-formatted strings.