Despike#

The goal of despiking is to remove cosmic ray hits from images.

Concept#

Despiking is carried out by our implementation of DeForest’s spikejones algorithm. The algorithm works on a single image at a time. It applies an unsharp mask to an image and compares that to a smoothed copy. Pixels with a significant difference are considered spikes.

Applying correction#

The correction is carried out primarily in the punchbowl.level1.despike.spikejones function:

punchbowl.level1.despike.spikejones(image: ndarray, unsharp_size: int = 3, method: str = 'convolve', alpha: float = 1, dilation: int = 0) tuple[ndarray, ndarray]

Remove cosmic ray spikes from an image using spikejones algorithm.

This code is based on drzowie/solarpdl-tools

Parameters:
  • image (np.ndarray) – an array representing an image

  • unsharp_size (int) – half window size in pixels for unsharp mask

  • method (str (either "convolve" or "median")) – method for applying the unsharp mask

  • alpha (float) – threshold for deciding a pixel is a cosmic ray spike, i.e. difference between unsharp and smoothed image

  • dilation (int) – how many times to dilate pixels identified as spikes, allows for identifying a larger spike region

Returns:

an image with spikes replaced by the average of their neighbors and the locations of all spikes

Return type:

(np.ndarray, np.ndarray)

If you wish to incorporate this as a Prefect task in a custom pipeline, using something like the punchbowl.level1.despike.despike_task is recommended.