koa_middleware.selector_base

Classes

CalibrationSelector()

Base class for calibration selectors.

class koa_middleware.selector_base.CalibrationSelector[source]

Bases: object

Base class for calibration selectors.

This abstract base class defines the interface for selecting one or more calibrations based on input data and a database of available calibrations. Subclasses are expected to implement specific selection logic by overriding methods like get_candidates and select_best.

A selector can be used to find a single best-fit calibration or a group of calibrations (e.g., bracketing etalon exposures).

get_candidates(input, db: CalibrationDB, **kwargs)[source]

Abstract method to retrieve an initial set of candidate calibrations.

Subclasses must implement this method to define how potential calibrations are identified from the database based on the input data and any additional criteria.

Parameters:
  • input – The input data file or model object.

  • db (CalibrationDB) – The database instance for querying.

  • **kwargs – Additional filtering parameters.

Returns:

list – A list of candidate calibration objects (e.g., CalibrationORM instances).

Raises:

NotImplementedError – If the subclass does not implement this method.

select(input, db: CalibrationDB, **kwargs)[source]

Selects the best calibration for the given input data.

This is the primary entry point for calibration selection. It calls the internal _select method and, if no result is found, attempts to use a fallback mechanism. Subclasses should generally not override this method, but rather _select, get_candidates, select_best, or select_fallback.

Parameters:
  • input – The input data file or model object for which a calibration is to be selected. The exact type depends on the specific selector implementation.

  • db (CalibrationDB) – An instance of CalibrationDB (or a subclass) providing access to the calibration database for querying.

  • **kwargs – Additional filtering parameters that can be passed to the underlying selection logic (e.g., _select, get_candidates, select_best).

Returns:

Any – The selected calibration file or model object. The type of the returned object depends on the specific selector and the CalibrationORM used. Returns None if no suitable calibration is found, even after fallback.

select_best(input, candidates, **kwargs)[source]

Select the best calibration(s) based on the candidates. By default, it returns the first candidate. This should be overriden by most subclasses.

Parameters:
  • input – Input data file or model object to select a calibration for.

  • candidates – Candidate calibrations returned from self.get_candidates().

  • kwargs – Additional filtering parameters.

Returns:

Selected calibration file (s)

select_fallback(input, db: CalibrationDB, **kwargs)[source]

Select a fallback calibration if no suitable candidates are found. By default, it returns None. This should be overriden by most subclasses.

Parameters:
  • input – Input data file or model object to select a calibration for.

  • db – Database session for querying.

  • kwargs – Additional filtering parameters.

Returns:

Fallback calibration file (s)