modules.image_assembly
KPF Image Assembly module.
Assembles a raw L0 readout into a single L1 full-frame image (overscan correction, amplifier stitching). It applies no calibrations: bias/dark/flat are handled downstream by ImageProcessing following the standard CCD reduction sequence (bias subtraction, then exposure-scaled dark subtraction, then flat division), gated per file type by the masters modules.
- class kpfpipe.modules.image_assembly.ImageAssembly(l0_obj, config=None)
Bases:
objectThis class performs CCD-level processing to convert L0 data to L1.
- Operations include:
orienting amplifier channels
applying gain conversion (ADU –> photo-electrons)
measuring read noise
subtracting overscan bias
assembling full-frame images (FFI)
converting EXPMETER_SCI/SKY wavelengths from nm to Angstroms
- apply_gain_conversion(chip)
Convert pixel values from ADU to photo-electrons using amplifier-specific gain. Amplifier channels are modified in-place.
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
- Return type:
None
Notes
Conversion formula: pixel_electrons = pixel_ADU * gain / 65536
- count_amplifiers(chip)
Count the number of amplifier extensions present for a given CCD and determine their channel dimensions.
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
- Return type:
None
Notes
Sets instance attributes: - self.namp[chip] : number of amplifier regions detected. - self.dims[chip] : shape of each amplifier channel. Only 2-amp and 4-amp configurations are supported.
- info()
Print a summary of the module configuration and processing results.
- measure_read_noise(chip, sigma=None, buffer=(5, 5))
Estimate read noise for each amplifier from overscan pixels.
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
sigma (float, optional) – Threshold for sigma clipping overscan pixels.
buffer (tuple of int, optional) – Number of pixels to ignore at the edges (start, end). Defaults to (5, 5).
- Return type:
None
Notes
Stores results in: - self.readnoise[channel_ext] : standard deviation of cleaned overscan. - self.rn_nongauss[channel_ext] : non-Gaussian factor computed as std/mad.
- orient_channels(chip)
Reorient amplifier channels to a standard orientation in-place. (serial overscan on right, parallel overscan on bottom)
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
- Return type:
None
Notes
The transformations are flips, so each is its own inverse — calling twice restores the input. measure_read_noise and subtract_overscan use this to orient to standard, do their work, then restore the original orientation, so a non-standard orientation never propagates between steps; it is also called directly by Quicklook for its L0 display.
- static orient_ffi(image, chip)
Flip an assembled image into the standard FFI orientation.
- perform(chips=None, *, overscan_method=None, readnoise_sigma=None)
Execute the image assembly algorithm. Optional keyword arguments default to config settings.
- Parameters:
chips (list of str, optional) – CCD identifiers to process, i.e. ‘GREEN’, ‘RED’
overscan_method (str, optional) – Method for overscan subtraction (‘zero’, ‘median’, ‘rowmedian’).
readnoise_sigma (float, optional) – Sigma threshold for clipping overscan pixels when measuring read noise.
- Returns:
l1_obj – L1 data object containing assembled full frame images (FFIs) for data and variance.
- Return type:
Notes
Pipeline steps: 1. Count amplifiers and determine dimensions 2. Apply gain conversion (ADU –> electrons) 3. Measure read noise 4. Subtract overscan bias 5. Stitch channels into a full-frame image 6. Convert EXPMETER_SCI/SKY wavelength column labels from nm to Å
Amplifier-channel orientation is handled on-the-fly inside measure_read_noise and subtract_overscan (each restores the original orientation afterward), not as a separate top-level step.
- stitch_ffi(chip)
Combine individual amplifier channels into a full-frame image (FFI).
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
- Returns:
ccd_ffi (ndarray) – Full-frame data image.
var_ffi (ndarray) – Full-frame variance image, incorporating read noise.
Notes
Supports 2-amp and 4-amp CCD configurations. Raises an error if any other number of amplifiers is detected.
- subtract_overscan(chip, method=None, buffer=(0, 0))
Subtract overscan bias from imaging pixels for each amplifier. Also removes overscan region from amplifier channel, leaving only active imaging area pixels. Amplifier channels are modified in-place.
- Parameters:
chip (str) – CCD identifier, e.g., ‘GREEN’ or ‘RED’.
method (str) – Overscan subtraction method (‘zero’, ‘median’, ‘rowmedian’).
buffer (tuple of int, optional) – Number of pixels to ignore at edges. Defaults to (0, 0).
- Return type:
None