bioniumx.preprocessing.savitzky_golay
- bioniumx.preprocessing.savitzky_golay(spectrum: BioniumXObject, window: int = 11, polyorder: int = 3)[source]
Apply a Savitzky-Golay filter to smooth a spectrum.
A Savitzky-Golay filter smooths data by fitting successive sub-sets of adjacent data points with a low-degree polynomial. It is excellent for preserving line shapes and peaks while reducing high-frequency noise.
- Parameters:
spectrum (BioniumXObject) – The input spectrum (TransmissionSpectrum or EmissionSpectrum).
window (int, optional) – The length of the filter window. Must be a positive odd integer. Default 11.
polyorder (int, optional) – The order of the polynomial used to fit the samples. Must be less than window. Default 3.
- Returns:
smoothed – A new spectrum object of the same type with smoothed data.
- Return type:
- Raises:
ValueError – If window is even or if polyorder >= window.
Examples
>>> spec = TransmissionSpectrum.read("data.h5") >>> smoothed_spec = savitzky_golay(spec, window=15, polyorder=3)