Skip to content

subtract_sky_2d

Subtract a per-column sky model fitted from off-trace rows of ctx.image.

Category Preprocessing (2-D image)
Backend numpy - implemented here on top of numpy primitives
Version 1.0.1
Reads ctx.image (an ImageFrame)
Writes image, metrics.sky_median

Sky regions are taken on either side of the trace and far enough away to be clean of stellar flux. The fit defaults to a degree-1 polynomial (linear gradient across the slit), which handles tilted sky and twilight gradients without over-fitting. v1.0.1: all columns are fitted in one vectorised least-squares call (numpy.polyfit on the 2-D sky block) — identical numbers, ~60× faster on a 200×2048 frame.

Parameters

Parameter Default Required Description
trace_row None yes Approximate y-pixel of the spectral trace.
trace_half_width 8 - Half-width (rows) of the protected aperture around the trace.
sky_offset 4 - Number of rows between trace edge and sky window start.
sky_half_width 10 - Half-width (rows) of each sky window.
poly_order 1 - Polynomial degree for the per-column cross-slit sky fit (0 = constant).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("subtract_sky_2d", ctx, {
    "trace_row": "<value>",
    "trace_half_width": 8,
    "sky_offset": 4,
    "sky_half_width": 10,
    "poly_order": 1
})

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": "subtract_sky_2d",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "trace_row": "<value>",
      "trace_half_width": 8,
      "sky_offset": 4,
      "sky_half_width": 10,
      "poly_order": 1
    }
  }
}

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

References

  • Horne 1986, PASP 98, 609 — §2 (standard extraction): sky estimated at each wavelength by a low-order polynomial fit across the spatial direction to the pixels outside the object aperture.
  • Tody 1986, Proc. SPIE 627, 733 — IRAF apall background fitting (per-column polynomial in the background windows).