Skip to content

snr_linear_fit

Estimate SNR from the scatter around a linear fit of a continuum region.

Category Quality / SNR
Backend numpy - implemented here on top of numpy primitives
Version 1.0.1
Reads ctx.spectrum (a Spectrum1D)
Writes metrics.snr_linear_fit

SNR = median(flux) / std(flux − linear fit) over the window. Non-finite samples (NaN/inf) are masked before the fit and excluded from the statistics ; the brick fails when fewer than 3 finite samples remain. Returns inf when the residuals have zero scatter.

Parameters

Parameter Default Required Description
wavelength_min None - Lower bound of the continuum window (Å); null uses the start.
wavelength_max None - Upper bound of the continuum window (Å); null uses the end.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("snr_linear_fit", ctx, {
    "wavelength_min": None,
    "wavelength_max": None
})
spectro run snr_linear_fit --input spectrum.fits \
  --param wavelength_min=none \
  --param wavelength_max=none
{
  "tool": "snr_linear_fit",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "wavelength_min": null,
      "wavelength_max": null
    }
  }
}

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

References

  • Stoehr et al. 2008, 'DER_SNR: A Simple & General Spectroscopic Signal-to-Noise Measurement Algorithm', ASP Conf. Ser. 394, 505 — the comparison baseline (snr_der) for continuum-window SNR estimators.
  • Gray 2005, The Observation and Analysis of Stellar Photospheres, 3rd ed., Cambridge UP — ch. 12, continuum placement and noise estimation in line-free windows.
  • compare_snr_methods - Run every SNR estimator on ctx.spectrum and collect their numbers.
  • snr_der - Derivative-based SNR estimator (DER_SNR, Stoehr et al. 2008).
  • snr_edge - Estimate SNR from the flat, line-free regions at the spectrum's edges.
  • validate_bess_header - Check a FITS header against the BeSS keyword contract.