extract_spectrum_optimal¶
Optimal (Horne 1986) aperture extraction of ctx.image.
| Category | Extraction (2-D to 1-D) |
| Backend | scipy - implemented here on top of scipy primitives |
| Version | 1.0.0 |
| Reads | ctx.image (an ImageFrame) |
| Writes | spectrum |
Empirical profile built from per-column cutouts then smoothed along the dispersion axis with a median filter (robust to residual cosmics, profile = 1 / N at edge columns where the full aperture doesn't fit). Iterative inverse-variance extraction with σ-clip rejection of deviant pixels — the standard Horne recipe. Output uncertainty is the propagated 1-σ. When to choose this vs the lighter alternatives: extract_spectrum_sum is the simplest pure sum (no trace fit); extract_spectrum_boxcar is the edge-safe boxcar with optional Gaussian profile weighting but no variance model, no uncertainty propagation and no cosmic rejection — pick it for high-SNR sources or extended emission. Pick extract_spectrum_optimal when SNR matters most (faint, read-noise-limited targets), when residual cosmics may remain after clip_cosmic_rays, or when the downstream pipeline needs per-pixel Spectrum1D.uncertainty (e.g. radial-velocity error propagation).
Parameters¶
| Parameter | Default | Required | Description |
|---|---|---|---|
trace_method |
'argmax' |
- | easyspec trace method ('argmax' / 'moments' / 'multi'). |
trace_poly_order |
2 |
- | Polynomial order of the trace fit. |
trace_y_pixel_range |
15 |
- | Half-window (rows) for the trace search. |
trace_peak_height |
100.0 |
- | Minimum peak height when locating the trace. |
trace_peak_distance |
50 |
- | Minimum separation between traces (multi mode). |
trace_half_width |
12 |
- | Aperture half-width (rows) for trace + extraction. |
gain |
1.0 |
- | Detector gain in e⁻/ADU (variance model). |
readnoise |
6.0 |
- | Detector read noise in e⁻ (variance model). |
profile_smooth_columns |
21 |
- | Window (columns) of the median smoothing applied to the empirical profile. Odd; 1 disables smoothing. Larger ⇒ more robust but loses spatial-profile variations along the dispersion axis (curved/tilted traces). |
reject_sigma |
5.0 |
- | σ threshold for outlier rejection during extraction. |
iterations |
3 |
- | Maximum extract→reject→re-extract cycles. |
Use it¶
from spectro_kernel import run_algorithm
output = run_algorithm("extract_spectrum_optimal", ctx, {
"trace_method": "argmax",
"trace_poly_order": 2,
"trace_y_pixel_range": 15,
"trace_peak_height": 100.0,
"trace_peak_distance": 50,
"trace_half_width": 12,
"gain": 1.0,
"readnoise": 6.0,
"profile_smooth_columns": 21,
"reject_sigma": 5.0,
"iterations": 3
})
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": "extract_spectrum_optimal",
"arguments": {
"session_id": "<session_id>",
"params": {
"trace_method": "argmax",
"trace_poly_order": 2,
"trace_y_pixel_range": 15,
"trace_peak_height": 100.0,
"trace_peak_distance": 50,
"trace_half_width": 12,
"gain": 1.0,
"readnoise": 6.0,
"profile_smooth_columns": 21,
"reject_sigma": 5.0,
"iterations": 3
}
}
}
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 — optimal extraction algorithm for CCD spectroscopy.
- Marsh 1989, PASP 101, 1032 — empirical profile for tilted traces.
- Tody 1986, SPIE 627, 733 — IRAF apall heritage.
Related algorithms¶
detect_trace- Detect the spectral trace onctx.imageand expose it onctx.extras["trace"].extract_sky_lateral_bands- Median-combine two off-trace sky bands into a 1D pixel-axis reference.extract_spectrum_boxcar- Trace (easyspec) + pure-numpy aperture extraction onctx.image.extract_spectrum_easyspec- Trace and extract a 1D spectrum from a 2D frame via easyspec.extract_spectrum_sum- Extract a 1D spectrum fromctx.imageby summing across the trace.