stack_spectra¶
Combine every spectrum in ctx.spectra into one stacked spectrum.
| Category | Stacking |
| Backend | numpy - implemented here on top of numpy primitives |
| Version | 2.0.0 |
| Reads | ctx.spectra (a list of Spectrum1D) |
| Writes | spectrum, metrics.n_stacked, metrics.n_nan_samples |
Median stacking is the most robust against cosmic rays and outliers; mean maximises SNR for clean data; sum is useful for co-adding sub-exposures. Each spectrum contributes only inside its own wavelength range: samples of the reference grid outside a spectrum's coverage are NaN for that spectrum and ignored by the NaN-aware combiners (a sample covered by no spectrum at all is NaN in the output; count in metrics.n_nan_samples). v2.0.0: v1 let numpy.interp clamp to the edge value, so a spectrum was extrapolated as a constant over the whole grid — with s1 = 1.0 on 4000-5000 Å and s2 = 3.0 on 4500-5500 Å the v1 mean at 4000 Å was 2.0; it is now 1.0 (2.0 inside the overlap).
Parameters¶
| Parameter | Default | Required | Description |
|---|---|---|---|
method |
'median' |
- | Combination method: mean, median or sum. |
reference_index |
0 |
- | Index in ctx.spectra whose wavelength grid is the target. |
Use it¶
The CLI loads a single 1-D spectrum with --input; this algorithm needs
ctx.spectra (a list of Spectrum1D). Run it from Python or as a step of a pipeline preset.
References¶
- Tody 1993, ASP Conf. Ser. 52, 173 — IRAF scombine: spectra interpolated to a common dispersion, then summed / averaged / medianed sample by sample.
Related algorithms¶
merge_echelle_orders- Merge every Spectrum1D inctx.spectrainto a singlectx.spectrum.