6.11. rejectCosmicRays

6.11.1. Purpose

This primitive will mask cosmic rays in a GHOST data frame by updating the data mask.

Warning

The algorithm seems to work, but isn’t managing to update the DQ plane. I’m working on the issue. -MCW

6.11.2. Inputs and Outputs

The following options can be passed to rejectCosmicRays via the RecipeSystem, or overridden with a user configuration file, as marked:

Parameter Type Default Override? Description
Recipe User
suffix str _cosmicRaysRejected Y Y Suffix affixed to modified file.
subsampling int 2 Y Y The number of pixels to subsample in each direction of each pixel.
sigma_lim float 5.0 Y Y Sigma clipping value.
f_lim float 6.0 Y Y Fine-structure clipping limit.
n_passes int 2 Y Y Number of iterations to perform.

6.11.3. Algorithm

This primitive is a first-principles implementation of the LACosmic algorithm. NumPy array operations are used for maximum efficiency. For a full-discussion of the algorithm, see van Dokkum 2001, PASP 113, 1420-1427 (ADS). In summary (where the symbol \ast denotes convolution):

  1. Create a Laplacian, \mathcal{L}^+, of the input data frame, I.
    • Subsample the image by a factor of subsampling and apply the Laplacian transformation;
    • Set any negative sub-pixels to have value 0 instead;
    • Re-sample the image back to its original resolution.
  2. Generate the ‘sigma map’, S, of the frame.
    • Form a ‘noise image’ of the data, N=g^{-1}\sqrt{g(M_5\ast I)+\sigma_{rn}^2}, where g and \sigma_{rn} are the data gain and read noise respectively. M_5 is a 5\times 5 median filter used to smooth the data.
    • The sigma map is then generated as S=\mathcal{L}^+ /f_S N, where f_S is the subsampling factor used.
    • Smooth the sigma map to help remove sampling flux, resulting in S^\prime = S - (S\ast M_5).
  3. Generate the ‘fine-structure image’ of the frame, \mathcal{F}=(M_3\ast I) - ((M_3\ast I) \ast M_7), where M_3 and M_7 are 3\times 3 and 7\times 7 median filters,
  4. Mark pixels as cosmic rays (via the image quality plane) if:
    • S^\prime > sigma_lim, and
    • \mathcal{L}^+ /\mathcal{F} > f_lim.
  5. For the purposes of the algorithm (i.e. not in the data to be returned), replace cosmic rays pixels with the median value of surrounding pixels.
  6. Iterate over steps 1-5 until n_passes is reached, or the number of cosmic rays detected falls to 0.

6.11.4. Issues and Limitations

Both strong spectral features and, in high-resolution mode, the ThXe calibration output may be incorrectly flagged as cosmic rays. Therefore, this primitive will trigger a call to need to add more here once this actually works

Note

The current preset values of sigma_lim (15.0, 5.0), f_lim (5.0) and n_passes (5) are a first-pass guess at what seems to flag roughly the correct number of cosmic rays. More complete testing, and the possible implementation of a table of preset values on a case-by-case basis, will need to wait until the findApertures routine (and related routines) are finalized and mixed in with the cosmic ray finding.