Despike#
Cosmic rays passing through an instrument CCD can leave behind bright spots or streaks in the collected image, depending on the angle of incidence. This despiking module aims to identify and remove cosmic ray artifacts from a sequence of images.
Concept#
A PUNCH roll sequence consists of three polarized exposures, a clear exposure, and three more polarized exposures. As cosmic ray artifacts are temporally transient, a given cluster of pixels will likely only show an artifact in one of these images. N input images from the roll sequence (three minimum) are high-pass-filtered, and the median is computed for each pixel from the resulting N-1 lowest values per pixel. From here z-score filtering is used to identify outlier pixels from cosmic ray strikes, which are removed and filled in from surrounding valid pixels.
Applying correction#
The correction is carried out primarily using the punchbowl.level1.despike.despike_polseq function:
- punchbowl.level1.despike.despike_polseq(reference: NDCube, neighbors: list[NDCube], filter_width: float = 25.0, hpf_zscore_thresh: float = 10.0) tuple[NDCube, ndarray][source]
Remove cosmic ray spikes from a single polarization sequence of images.
This code takes as input multiple (N) images from the same roll sequence. It constructs a high-pass-filtered version of the input images. At each pixel, it computes the median and standard deviation of the (N-1) dimmest pixels, and then the z-score of each pixel. If the z-score exceeds a threshold, a cosmic ray is assumed and the pixel is filled in with the mean of its neighbors.
- Parameters:
reference (NDCube) – an NDCube to correct for cosmic rays
neighbors (List[NDCube]) – a list of NDCube objects representing a polarization image sequence, should not include the reference image
filter_width (float) – width of the gaussian filter used in created the high-pass-filtered image
hpf_zscore_thresh (float) – number of standard deviations above the sequence median[sic] that causes a pixel to be marked as a cosmic ray.
- Returns:
- a NDCube with spikes replaced by the average of their neighbors,
and a list of spike locations for all neighbors
- Return type:
(NDCube, np.ndarray)
If you wish to incorporate this as a Prefect task in a custom pipeline,
using something like the punchbowl.level1.despike.despike_polseq_task is recommended.