Finding and Removing Cosmic Rays

Finding Cosmic Rays

We look for cosmic rays using a sequence of tests, each more discriminating (and more time-consuming) than the preceeding. Initially the frame is searched for pixels that appear to be part of a cosmic ray event; then all of these contaminated pixels are assembled into cosmic ray events, and the pixels around these are examined for evidence of contamination, using a lower standard of proof.

In the following descriptions, C is the candidate cosmic ray pixel, and other pixels are referred to as (e.g.) NW.

               -1     0    1
             1 NW     N    NE
             0  W     C    E
            -1 SW     S    SE

Searching for contaminated pixels follows the following sequence:

After a contaminated pixel has been detected, its value is temporarily replaced by the lowest of the means determined in the last step listed above, in order to make it easier to find further pixels contaminated by the same cosmic ray.

When the whole frame has been processed, contiguous contaminated pixels are merged into single cosmic rays. If the peak pixel is below some minimum (cr_min_e) number of electrons above the sky level, the candidate cosmic ray is rejected, otherwise it's added to the MASK_CR mask.

Next, all cosmic ray pixels are removed.

All the pixels adjacent to each cosmic ray are then examined, using the above set of tests, but with the min_sigma and cond3_fac values relaxed by 50%. Any contaminated pixels are added to their `parent' cosmic ray.

Finally, if the keep flag is set, the original values of all cosmic ray pixels are reinstated; otherwise the MASK_INTERP bit is set for all interpolated pixels

Removing Cosmic Rays

Once all contaminated pixels have been found (as described above), they are interpolated over using a four-point interpolation scheme as described elsewhere (e.g. horizontally we calculate
	-0.2737*I[-2] + 0.7737*I[-1] + 0.7737*I[1] - 0.2737*I[2]
as a possible replacement for I[0]). We interpolate in all four directions (e.g. SW--NE, W--E) and choose the minimum value, after rejecting any involving bad (MASK_INTERP or MASK_NOTCHECKED) pixels. If none of the interpolated values is acceptable, the pixel is replaced by the sky value.

Because we have chosen the minimum of a number of estimates, the resulting value is biased a little low. We correct for this by assuming that there were only two uncontaminated values, and thus add 0.56*(sky sigma).

Restrictions on CR code