hispecdrp.driver.config

Functions

_flow_seq(dumper, data)

_get_nested(meta, path)

Resolve a dotted path against dict-like or attribute-like metadata.

_load_yaml_config_file(config_filepath)

get_config_dir()

get_config_filepath(config_file)

Resolve the path to a configuration file.

get_pipeline_class(name)

Lazily resolve and return a primitive or pipeline class.

get_primitive_class(name)

Lazily resolve and return a primitive or pipeline class.

load_config_file(config_filepath)

Read a configuration file and return its contents as a dictionary.

Classes

ConfigFile(name, class_name[, description, ...])

A class representing a configuration file.

ConfigSelector(class_name[, context, ...])

ConfigStore([keep_in_memory, config_dir])

A store for managing configuration files.

FlowSeqDumper(stream[, default_style, ...])

Exceptions

AmbiguousConfigError

NoConfigFoundError

class ConfigFile(name, class_name, description=None, filepath=None, context=None, parameters=None, primitives=None, logging=None)[source]

Bases: object

A class representing a configuration file.

class_name

The name of the primitive or pipeline class (with or without the module path).

Type:

str

filepath

Full filepath to the config file.

Type:

str

context

A dictionary of metadata for this config file.

Type:

dict

_DEFAULT_CONTEXT = {'instrument_era': ['0.0.1', None], 'instrument_mode': None, 'processing_mode': None, 'quicklook': None}
property class_
property filename
classmethod from_dict(config)[source]
classmethod from_file(filepath, **kwargs)[source]
property is_pipeline
property name

Unique name for a config file.

save(output_path, output_dir=None)[source]
to_dict()[source]
class ConfigSelector(class_name, context=None, skip_filters=None)[source]

Bases: CalibrationSelector

_CUSTOM_FILTERS = {}
_filter_class(candidates)[source]

Filter config files by the primitive or pipeline class they are meant to configure.

Parameters:

candidates (list[ConfigFile]) – The list of candidate config files to filter.

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the class.

_filter_ifs_mode(meta, candidates)[source]

Filter candidates by IFS mode.

Parameters:
  • meta (dict) – Datamodel metadata

  • candidates (list[ConfigFile]) – List of candidate config files to filter.

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the IFS mode.

_filter_instrument_era(meta, candidates)[source]

Filter candidates by the valid instrument_era range.

Parameters:
  • meta (dict) – Datamodel metadata

  • candidates (list[ConfigFile]) – List of candidate config files to filter.

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the instrument era.

_filter_instrument_mode(meta, candidates)[source]

Filter candidates by instrument mode.

Parameters:
  • meta (dict) – Datamodel metadata

  • candidates (list[ConfigFile]) – List of candidate config files to filter.

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the instrument mode.

_filter_processing_mode(candidates)[source]

Filter candidates by the processing mode (self.context.processing_mode).

Unlike quicklook, processing_mode has no natural default value, so an unspecified input (None) leaves the candidates unconstrained. When a value is specified, a config file that explicitly matches it always wins; a config file that omits processing_mode (None, a wildcard) is only used as a fallback when nothing explicitly matches.

Parameters:

candidates (list[ConfigFile]) – List of candidate config files to filter.

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the processing mode criteria.

_filter_quicklook(candidates)[source]

Filter candidates by the quicklook flag (self.quicklook).

A config file that omits quicklook (context value None) is a wildcard: it matches any requested value. It’s only used as a fallback when no candidate explicitly matches the requested value, so an explicit True/False config always takes precedence over a wildcard one for the same class.

Cases

  1. Input context = None ConfigFile contexts = (None, …) -> All ConfigFile contexts = (True, False) -> False

  2. Input context = False

    ConfigFile contexts = (True, False) -> False ConfigFile contexts = (None, …) -> All

  3. Input context = True

    ConfigFile contexts = (True, None) -> True

param candidates:

List of candidate config files to filter.

type candidates:

list[ConfigFile]

Returns:

filtered_candidates (list[ConfigFile]) – The filtered list of config files that match the quicklook criteria.

_select(meta, candidates)[source]

Internal method to perform the core config file selection logic.

This method first retrieves a set of candidate config files using get_candidates and then selects the best one (or ones) from these candidates using select_best. Subclasses can override this method to implement custom selection workflows, but it’s often more appropriate to override get_candidates or select_best.

Parameters:
  • meta (dict) – The metadata for which a config file is to be selected.

  • candidates (list[ConfigFile]) – The list of candidate config files to consider.

Returns:

result (ConfigFile | None) – The selected config file if one is found, otherwise None.

get_candidates(meta, candidates)[source]

Select the most appropriate config file for the given metadata.

Parameters:
  • meta (dict) – Data metadata to match against the meta blocks of the candidate config files.

  • candidates (list[ConfigFile]) – List of candidate config files to consider.

Returns:

config_file (ConfigFile)

classmethod register_filter(key)[source]

Register custom match logic for a selection key with non-equality semantics.

select(meta, candidates)[source]

Select the most appropriate config file for the given metadata.

Parameters:
  • meta (dict) – Data model metadata.

  • candidates (list[ConfigFile]) – List of candidate config files to consider.

Returns:

result (ConfigFile | None) – The selected config file if one is found, otherwise None.

select_best(meta, candidates)[source]
class ConfigStore(keep_in_memory=True, config_dir=None)[source]

Bases: object

A store for managing configuration files.

Examples

>>> with ConfigStore() as store:
        config_file : ConfigFile = store.select_and_get_config(
            dataset,
            selector
        )
        filepath = config_file.filepath
_cache = None
classmethod clear_cache()[source]
populate()[source]
select_and_get_config(dataset, selector)[source]

Given an input dataset and a primitive class to run, select a config file.

Parameters:
  • dataset (Any) – The dataset for which to select a config.

  • selector (ConfigSelector) – The config selector to use for selecting the config.

Returns:

config_file (ConfigFile) – The selected config file object.

get_config_dir()[source]
get_config_filepath(config_file)[source]

Resolve the path to a configuration file.

Parameters:

config_file (str) – The base filename of the configuration file or a valid file path.

Returns:

config_filepath (str) – The resolved path to the configuration file.

load_config_file(config_filepath)[source]

Read a configuration file and return its contents as a dictionary.