hispecdrp.driver.config
Functions
|
|
|
Resolve a dotted path against dict-like or attribute-like metadata. |
|
|
|
Resolve the path to a configuration file. |
|
Lazily resolve and return a primitive or pipeline class. |
|
Lazily resolve and return a primitive or pipeline class. |
|
Read a configuration file and return its contents as a dictionary. |
Classes
|
A class representing a configuration file. |
|
|
|
A store for managing configuration files. |
|
Exceptions
|
|
|
- class ConfigFile(name, class_name, description=None, filepath=None, context=None, parameters=None, primitives=None, logging=None)[source]
Bases:
objectA class representing a configuration file.
- _DEFAULT_CONTEXT = {'instrument_era': ['0.0.1', None], 'instrument_mode': None, 'processing_mode': None, 'quicklook': None}
- classmethod from_dict(config)[source]
- classmethod from_file(filepath, **kwargs)[source]
- save(output_path, output_dir=None)[source]
- to_dict()[source]
- class ConfigSelector(class_name, context=None, skip_filters=None)[source]
Bases:
CalibrationSelector- _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_modehas 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 omitsprocessing_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 valueNone) 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 explicitTrue/Falseconfig always takes precedence over a wildcard one for the same class.Cases
Input context = None ConfigFile contexts = (None, …) -> All ConfigFile contexts = (True, False) -> False
- Input context = False
ConfigFile contexts = (True, False) -> False ConfigFile contexts = (None, …) -> All
- 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_candidatesand then selects the best one (or ones) from these candidates usingselect_best. Subclasses can override this method to implement custom selection workflows, but it’s often more appropriate to overrideget_candidatesorselect_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
metablocks 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:
objectA store for managing configuration files.
Examples
>>> with ConfigStore() as store: config_file : ConfigFile = store.select_and_get_config( dataset, selector ) filepath = config_file.filepath- 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.