Skip to content

detect_trace

Detect the spectral trace on ctx.image and expose it on ctx.extras["trace"].

Category Extraction (2-D to 1-D)
Backend scipy - implemented here on top of scipy primitives
Version 1.0.1
Reads ctx.image (an ImageFrame)
Writes extras.trace, metrics.trace_center_row, metrics.trace_fwhm_px, metrics.trace_snr

Sibling of the trace step inside extract_spectrum_boxcar / extract_spectrum_optimal — but standalone, pure-numpy, and exposing the result on ctx.extras so the geometry and sky bricks (subtract_sky_2d, correct_smile_polynomial, correct_slant_affine) can resolve their hand-tuned row parameters from a measured value rather than a config file. Required at the head of an 'automatic' reduction preset; the manual mode that pre-fills row parameters from a config remains valid.

Parameters

Parameter Default Required Description
method 'argmax' - Per-slice centroid method: 'argmax' (integer pixel) or 'centroid' (sub-pixel).
poly_order 2 - Polynomial order of the fitted trace y(x).
search_half_width 40 - Half-window (rows) around the global peak in which each slice searches for its local maximum.
n_slices 20 - Number of column slices sampled across the dispersion axis.
min_snr 5.0 - Minimum trace SNR (peak above background / off-trace std). The algorithm fails rather than silently writing a bad trace.
output_key 'trace' - ctx.extras key that receives the trace dict.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("detect_trace", ctx, {
    "method": "argmax",
    "poly_order": 2,
    "search_half_width": 40,
    "n_slices": 20,
    "min_snr": 5.0,
    "output_key": "trace"
})

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": "detect_trace",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "method": "argmax",
      "poly_order": 2,
      "search_half_width": 40,
      "n_slices": 20,
      "min_snr": 5.0,
      "output_key": "trace"
    }
  }
}

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

References

  • Tody 1986, Proc. SPIE 627, 733 — IRAF apall / aptrace heritage.
  • scipy.signal.find_peaks — global peak of the collapsed spatial profile.