Skip to content

smooth_savgol

Smooth a spectrum with a Savitzky-Golay filter.

Category Smoothing
Backend scipy - implemented here on top of scipy primitives
Version 2.0.0
Reads ctx.spectrum (a Spectrum1D)
Writes spectrum

Non-finite samples (NaN/inf) are bridged by linear interpolation over the finite neighbours before filtering, so a bad pixel neither raises nor smears ; the original non-finite positions are restored to NaN in the output (finite inputs are processed bit-identically to v1.0.0). v2.0.0 — uncertainty propagation : when the input carries an uncertainty, σ_out,i = sqrt(Σ_k c_k² σ_{i+k}²) with the Savitzky-Golay coefficients of scipy.signal.savgol_coeffs (interior samples) and, for the window//2 samples at each end, the coefficients of the edge polynomial the filter's default 'interp' mode evaluates there. For white noise σ, window 11 and polyorder 3 the interior gives σ_out = 0.4555 σ (= sqrt(Σ c_k²)). Bridged (non-finite) samples contribute no variance and get a NaN uncertainty. The correlation between neighbouring output samples is NOT tracked — χ² fits on a smoothed spectrum under-estimate their parameter errors. Without an input uncertainty the brick is unchanged from v1.0.1.

Parameters

Parameter Default Required Description
window 11 - Sliding-window length in samples (odd; coerced up to the next odd).
polyorder 3 - Polynomial order fitted within each window (< window).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("smooth_savgol", ctx, {
    "window": 11,
    "polyorder": 3
})
spectro run smooth_savgol --input spectrum.fits \
  --param window=11 \
  --param polyorder=3
{
  "tool": "smooth_savgol",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "window": 11,
      "polyorder": 3
    }
  }
}

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

References

  • Savitzky & Golay 1964, Analytical Chemistry 36, 1627
  • scipy.signal.savgol_filter / savgol_coeffs
  • Bevington & Robinson 2003, Data Reduction and Error Analysis for the Physical Sciences, 3rd ed., McGraw-Hill — §3.2, error propagation through a linear combination (σ_out² = Σ c_k² σ_k²).
  • compare_smoothings - Run every smoothing kernel on ctx.spectrum and collect the results.
  • smooth_gaussian - Smooth a spectrum by convolution with a Gaussian kernel.