Skip to content

clip_cosmic_rays

Detect and replace cosmic-ray hits on ctx.image.

Category Cosmic-ray rejection
Backend scipy - implemented here on top of scipy primitives
Version 1.0.0
Reads ctx.image (an ImageFrame)
Writes image, metrics.n_cosmic_rays

L.A.Cosmic detects cosmic-ray cores by Laplacian edge detection and replaces the affected pixels with a local median. The fallback path uses a 3x3 median filter as the reference: any pixel whose excess over the median exceeds sigma standard deviations is replaced by that local median.

Parameters

Parameter Default Required Description
sigma 5.0 - Detection threshold in noise units.
gain 1.0 - Detector gain in electrons/ADU (used by L.A.Cosmic).
readnoise 6.0 - Detector read noise in electrons (used by L.A.Cosmic).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("clip_cosmic_rays", ctx, {
    "sigma": 5.0,
    "gain": 1.0,
    "readnoise": 6.0
})

The CLI loads a single 1-D spectrum with --input; this algorithm needs ctx.image (an ImageFrame). Run it from Python or as a step of a pipeline preset.

{
  "tool": "clip_cosmic_rays",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "sigma": 5.0,
      "gain": 1.0,
      "readnoise": 6.0
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

References

  • van Dokkum 2001, PASP 113, 1420 — L.A.Cosmic
  • McCully et al. — astroscrappy (https://github.com/astropy/astroscrappy)