modules.masters.base
Base class for KPF Masters modules.
- class kpfpipe.modules.masters.base.BaseMasterModule(l0_file_list, config=None)
Bases:
objectBase class for KPF masters generation.
The class should not be called directly, but is used for inheritance of masters subclasses: Bias, Dark, Flat, WLS. Masters modules read a stack of L0 files from disk and output a masters L1 object.
Each frame is calibrated before stacking/extraction following standard CCD reduction: bias gets no calibration, dark is bias-subtracted, flat is bias+dark-subtracted, and WLS (like science) is bias+dark-subtracted then flat-divided. Each subclass declares its standard set via _STANDARD_CALIBRATIONS. Which of those actually run is the standard set intersected with the resolved bias/dark/flat flags (DEFAULTS < [MODULE_IMAGE_PROCESSING] config < make_master kwargs): a flag can only turn a standard calibration off, never enable one a master type does not use.
- save_master(level, path, *, overwrite=False)
Write the cached master object to a FITS file at path.
- Parameters:
level (str) – Data level of the master to save; selects which cached object to write. One of ‘L1’ or ‘L2’, matching the subclass’s make_master_l1 / make_master_l2 entry point.
path (str) – Output FITS path. Parent directories are created as needed.
overwrite (bool, optional) – If False (default), refuse to clobber an existing file and raise FileExistsError. If True, replace any existing file at path. Defaults to False to protect against accidental overwrites when called directly; entry points that pass an output path through make_master_lN() should set True explicitly.
- Raises:
ValueError – If level is not a recognized data level.
FileExistsError – If path already exists and overwrite is False.
RuntimeError – If the corresponding make_master_lN() has not been run yet, or raised before constructing the master.
- stack_frames(l0_file_list=None, nstream=6, sigma=None, cal_type=None, max_fail_fraction=0.2, max_fail_number=2)
Stack full-frame images to produce masters L1.
- Parameters:
l0_file_list (list of str, optional) – List of L0 FITS filenames to stack.
nstream (int, optional) – Threshold number of frames at or above which the memory-light streaming path is used instead of the in-memory data cube. Defaults to 6.
sigma (float, optional) – Sigma threshold for frame-to-frame outlier rejection.
cal_type ({'bias', 'dark', 'flat', None}, optional) – Calibration type, forwarded to _clean_l1_arrays to select the final outlier-flagging mode. Defaults to the conservative global-median mode.
max_fail_fraction (float, optional) – Maximum fraction of frames allowed to fail loading before raising. Defaults to 0.2.
max_fail_number (int, optional) – Maximum absolute number of frames allowed to fail loading before raising. Defaults to 2. Stacking raises when either limit is exceeded.
- Returns:
l1_arrays – Dictionary containing per-chip stacked products, with bad pixels interpolated and the bad-pixel mask recomputed (_clean_l1_arrays): - ‘{chip}_IMG’ : mean count rate FFI - ‘{chip}_SNR’ : signal-to-noise ratio FFI - ‘{chip}_MASK’ : boolean bad pixel mask (1 = good, 0 = bad)
- Return type:
dict
Notes
If number of frames is less than nstream, statistics are computed directly from a full data cube. Otherwise, a single-pass streaming accumulation is used to bound memory usage.
An initial subset of frames is processed using the direct data cube method to estimate approximate mean and rms. These estimates define per-pixel clipping bounds for the streaming pass.