4.1. recipe_system package

4.1.1. Subpackages

4.1.2. Submodules

4.1.3. recipe_system.config module

This module provides an interface to config files, and a globally available config object, to share setup information across the application.

An instance of ConfigObject, globalConf, is initialized when first loading this module, and it should be used as the only interface to the config system.

class recipe_system.config.ConfigObject[source]

Bases: object

Generalized wrapper on ConfigParser.

This class is used for reading, parsing, and updating configurations for DRAGONS calibration service.

_sections
Type:<dict>
_conv

A “converter” dictionary providing a key pointing to a native python data type. E.g., {(section, option): bool}. In the case of the DRAGONS calibration service, the boolean ‘standalone’ configuration option, this dictionary looks like,

{(‘calibs’, ‘standalone’): bool}

Type:<dict>
_exports
Type:<dict>
export_section(section)[source]

Some options from the specified section may be published as environment variables, where spawned processes can find them.

The exported variables would be the ones speficied using update_exports.

Parameters:section (<str>) – Section name, e.g., ‘calibs’
load(filenames, defaults=None, env_override=False)[source]

Loads all or some entries from the specified section in a config file. The extracted values are set as environment variables, so that they are available at a later point to other modules or spawned processes.

Parameters:
  • filenames (<str> or <iterable>) –

    A string or a sequence of strings containing the path(s) to configuration file(s). If a value is present in more than one file, the latest one to be processed overrides the preceding ones.

    Paths can start with ~/, meaning the user home directory.

  • defaults (<dict>, optional) – If some options are not found, and you want to set up a default value, specify them in here. Every key in the dictionary is the name of a section in the config file, and each element is another dictionary establishing attribute-value pairs for that section.
  • env_override (<bool>, optional (default is False)) – If true, after loading values from the configuration files, the environment will be explored in search of options passed down by the parent process. Those options will override the ones taken from the config files.
update(section, values)[source]

Regenerates a section from scratch. If the section had been loaded before, it will take the previous values as a basis and update them with the new ones.

Parameters:
  • section (<str>) – The configuration section to update.
  • values (<dict>) – The values associated to the section.
update_exports(expdict)[source]

Updates the internal export table that will be used to share config information with process spawns.

Parameters:expdict (<dict>) – Each key is the name of a section. The values of the dictionary are sequences of strings, with each string in the sequence being the name of a config entry in that section that will be exported, if found.
update_translation(conv)[source]

Updates the internal mapping table for automatic translation of data types when reading from config files.

Parameters:conv (<dict>) –

A mapping (section_name, item) -> Python type. Used internally for type translation when reading values from the config file. If a section/item pair is missing then a fallback (None, item) will be tried. If no match is found, no translation will be performed.

The only types to be considered are: int, float, bool

class recipe_system.config.Converter(conv_dict, cp)[source]

Bases: object

from_config_file(section, key)[source]
from_raw(section, key, value)[source]
class recipe_system.config.Section(values_dict)[source]

Bases: object

An instance of Section describes the contents for a section of an INI-style config file. Each entry in the section translates to an attribute of the instance. Thus, a piece of config file like this:

[section]
attribute1 = true
attribute2 = /foo/bar

could be accessed like this:

>>> sect = globalConf[SECTION_NAME]
>>> sect.attribute1
'true'
>>> sect.attribute2
'/foo/bar'

The attributes are read-only. Any attempt to set a new one, or change the value of an entry through instances of this class, will raise an exception.

As the entries will be translated as Python attributes, this means that entry names have to be valid Python identifier names.

There is only one reserved name: as_dict. This cannot be used as an entry name.

as_dict()[source]

Returns a dictionary representation of this section

recipe_system.config.environment_variable_name(section, option)[source]

4.1.4. recipe_system.testing module

recipe_system.testing.get_master_arc(path_to_inputs, change_working_dir)[source]

Factory that creates a function that reads the master arc file from the permanent input folder or from the temporarily local cache, depending on command line options.

Parameters:
  • path_to_inputs (pytest.fixture) – Path to the permanent local input files.
  • change_working_dir (contextmanager) – Enable easy change to temporary folder when reducing data.
Returns:

The master arc.

Return type:

AstroData

recipe_system.testing.reduce_arc(change_working_dir)[source]

Factory for function for ARCS data reduction.

Parameters:change_working_dir (pytest.fixture) – Context manager used to write reduced data to a temporary folder.
Returns:
  • function (A function that will read the arcs files, process them and)
  • return the name of the master arc.
recipe_system.testing.reduce_bias(change_working_dir)[source]

Factory for function for BIAS data reduction.

Parameters:change_working_dir (pytest.fixture) – Context manager used to write reduced data to a temporary folder.
Returns:
  • function (A function that will read the bias files, process them and)
  • return the name of the master bias.
recipe_system.testing.reduce_flat(change_working_dir)[source]

Factory for function for FLAT data reduction.

Parameters:change_working_dir (pytest.fixture) – Context manager used to write reduced data to a temporary folder.
Returns:
  • function (A function that will read the flat files, process them and)
  • return the name of the master flat.
recipe_system.testing.ref_ad_factory(path_to_refs)[source]

Read the reference file.

Parameters:path_to_refs (pytest.fixture) – Fixture containing the root path to the reference files.
Returns:function
Return type:function that loads the reference file.