modules.image_processing

KPF Image Processing module.

Applies the standard CCD calibration sequence to an assembled L1 frame, in order: bias subtraction, then dark subtraction (an exposure-scaled rate), then flat division. Which steps run is set by the bias/dark/flat flags, resolved DEFAULTS < [MODULE_IMAGE_PROCESSING] config < perform() kwargs. The masters modules drive these same flags per file type (see kpfpipe/modules/masters); science applies the full sequence. Flat division is not yet implemented.

class kpfpipe.modules.image_processing.ImageProcessing(l1_obj, config=None)

Bases: object

Apply calibrations to an assembled KPF L1 frame.

Implements bias and dark subtraction. Flat division will be added in a future update; requesting it now raises NotImplementedError.

Parameters:
  • l1_obj (KPF1) – Assembled L1 frame. The RECEIPT header must contain the {BIAS,DARK}FILE keyword (the master’s full path, written by CalibrationAssociation) for any calibration requested via the header lookup.

  • config (None | dict | ConfigHandler) – Module configuration. Recognized keys: bias, dark, flat (boolean flags toggling each calibration).

static calibration_applied(l1_obj, cal_type)

Return True if cal_type is already flagged applied on l1_obj.

Reads the applied flag (_CALIBRATION_HEADER_KEYS: BIASSUB/DARKSUB/ FLATDIV) from the RECEIPT header — their registry home — written by a prior perform. Lets callers — and perform itself — avoid applying a calibration twice (e.g. a cached frame revisited during stacking).

Parameters:
  • l1_obj (KPF1) – Frame whose RECEIPT header is inspected.

  • cal_type (str) – Calibration name: ‘bias’, ‘dark’, or ‘flat’.

Returns:

True if the calibration’s header flag is present and truthy.

Return type:

bool

info()

Print a summary of the module configuration and processing results.

perform(chips=None, *, bias=None, dark=None, flat=None)

Run image processing calibrations on the L1 frame.

Parameters:
  • chips (list of str, optional) – CCD chips to process. Defaults to self.chips.

  • bias (bool | str | KPFMasterL1, optional) – How to source the master bias. Falsy → skip. True → load via BIASFILE (the master’s full path) in the RECEIPT header. str → treat as an explicit filepath. KPFMasterL1 → use this object directly (no disk I/O). Defaults to self.bias.

  • dark (bool | str | KPFMasterL1, optional) – Same shape as bias, sourced from DARKFILE. Applied after bias subtraction and scaled by the frame’s exposure time. Defaults to self.dark.

  • flat (bool | str | KPFMasterL1, optional) – Same shape as bias. Any truthy value raises NotImplementedError until flat division is built out.

Returns:

The input L1 frame with calibrations applied in-place and a receipt entry added.

Return type:

KPF1

Raises:
  • FileNotFoundError – Propagated from _resolve_master() if a master cannot be located.

  • NotImplementedError – If flat is truthy.

  • TypeError – If bias or dark is not bool, str, or KPFMasterL1.

  • RuntimeError – If a requested calibration is already flagged applied on the frame (BIASSUB/DARKSUB), guarding against double subtraction.

subtract_bias(chip, bias=None)

Subtract the master bias image from the CCD data for a single chip.

Parameters:
  • chip (str) – CCD identifier, e.g. ‘GREEN’ or ‘RED’.

  • bias (bool | str | KPFMasterL1, optional) – Master bias source, resolved via _resolve_master (see perform for the accepted input types). Defaults to self.bias.

Returns:

Modifies l1_obj.data[‘{chip}_CCD’] and [‘{chip}_VAR’] in-place: the bias is subtracted from CCD and its variance added to VAR.

Return type:

None

subtract_dark(chip, dark=None)

Subtract the master dark from the CCD data for a single chip.

The master dark is a rate (electrons/sec), so it is scaled by the frame’s exposure time before subtraction. Otherwise identical to subtract_bias.

Parameters:
  • chip (str) – CCD identifier, e.g. ‘GREEN’ or ‘RED’.

  • dark (bool | str | KPFMasterL1, optional) – Master dark source, resolved via _resolve_master (see perform for the accepted input types). Defaults to self.dark.

Returns:

Modifies l1_obj.data[‘{chip}_CCD’] and [‘{chip}_VAR’] in-place: the exposure-scaled dark is subtracted from CCD and its variance (scaled by exptime**2) added to VAR.

Return type:

None