hispecdrp.processing_component

Classes

ProcessingComponent(action, context)

class ProcessingComponent(action, context)[source]

Bases: BasePrimitive

LOG_CONFIG_FILE = 'logging.yaml'
_create_preview()[source]

Create a preview image for the output data model. This method can be overridden by subclasses to implement specific preview generation logic. By default, this method does nothing.

_get_first_model(dataset, open=True, return_type=False, **kwargs)[source]

Get the first input model and its container type from the dataset.

Parameters:
  • dataset (Any) – The dataset to extract the first model from.

  • open (bool, optional) – If True, open the model if it’s a file path. Default is True.

  • return_type (bool, optional) – If True, also return the container type and length. Default is False.

  • **kwargs – Additional keyword arguments to pass to the datamodels.open() function.

Returns:

DataModel | tuple[DataModel, type | None, int] – If return_type is False, returns the first DataModel. If return_type is True, returns a tuple of (first DataModel, container type, length). Supported container types are Sequence and dict. For a single model, the type is None.

_init_log_config(log_config=None)[source]

Resolve and store self.log_config by merging (lowest → highest priority):

  1. Package defaults from hispecdrp/configs/logging.yaml

  2. logging attribute embedded in self.config.

  3. log_config kwarg passed at construction time (dict or file path/name)

_post_condition()[source]
_pre_condition()[source]
property allowed_parameters
apply(dataset=None, **kwargs)[source]

One of the two primary methods a user calls to run a primitive. The other is Primitive.call(). Users should not need to override this method, and care should be taken if doing so.

Both BasePrimitive and BasePipeline implement apply().

generate_output_path(model, output_dir=None)[source]

Generate an output filepath for a model.

Parameter

modelstr | DataModel

The model to generate the output path for.

output_dirstr | None, optional

The output directory to use. If None, the output directory is determined by self.get_output_dir(model).

classmethod get_config(dataset, context=None)[source]

Retrieve the configuration for this primitive based on the dataset and context.

Parameters:
  • dataset (Any) – The dataset to use for selecting the configuration. Cannot be None.

  • context (dict | None) – Optional context to use for selecting the configuration.

Returns:

config_file (ConfigFile) – The configuration file for this primitive.

static get_do_traces(input_model, do_fibers=None, do_orders=None)[source]

Determine which fibers and orders to process based on the input model and optional user-specified lists.

Parameters:
  • input_model (datamodels.DataModel) – The input data model.

  • do_fibers (list[str] | None, optional) – A list of fiber numbers to process. If None, all fibers are processed.

  • do_orders (list[int] | None, optional) – A list of order numbers to process. If None, all orders are processed.

Returns:
  • do_fibers (list[str | int]) – The list of fiber numbers to process.

  • do_orders (list[int]) – The list of order numbers to process.

get_input_dir(dataset=None)[source]

Get the input directory for a given model.

Parameters:

dataset (Any, optional) – The input model to determine the input directory from. If None, uses self.dataset.

get_output_dir(model)[source]

Get the output directory for saving any results in the context of a model. The priority for determining the output directory is as follows:

  1. self.output_dir if explicitly set (input model not used).

  2. model._filepath directory if available If an input model is provided, the fallback is the directory of self.dataset.

  3. Current working directory as a final fallback.

Parameters:

model (str | DataModel) – The input model to determine the output directory from if self.output_dir is not set.

Returns:

str – The output directory for saving results.

get_pars()[source]

Get the current parameter values.

Returns:

dict – A dictionary of parameter names and their current values. Primitive parameters include both parameters and calibrations.

property pars_str

Pretty print the current parameters and calibrations for this primitive or pipeline.

Returns:

str – A formatted string showing all current parameter values.

save_model(model, output_path=None)[source]

Save a DataModel to a file in the context of this processing component. The file suffix will be added to the existing filename (model.meta.filename) if present and filepath is not set.

Parameters:
  • model (DataModel) – The model to save.

  • output_path (str | None, optional) – The full filepath where to save the model. Supersedes self.output_dir and self.suffix.

Returns:

str – The file path where the model was saved.

save_output()[source]

Saves all datamodels stored at self._output[‘output’].

set_pars(**kwargs)[source]

Set parameter values including calibrations as top-level attributes.

Parameters:

**kwargs – Parameters to set as attributes. For primitives, one can also override calibration values.

Notes

Selector logic is not run here.