spectrochempy.despike#
- despike(dataset, size=9, delta=2, method='katsumoto', *, dim=-1)[source]#
Remove spikes from the data.
The
despikemethods can be used to remove cosmic ray peaks from a spectrum.The ‘katsumoto’ implementation (default) is based on the method is described in Katsumoto and Ozaki [2003]:
In the first step, the moving-average method is employed to detect the spike noise. The moving-average window should contain several data points along the abscissa that are larger than those of the spikes in the spectrum. If a window contains a spike, the value on the ordinate for the spike will show an anomalous deviation from the average for this window.
In the second step, each data point value identified as noise is replaced by the moving-averaged value.
In the third step, the moving-average process is applied to the new data set made by the second step.
In the fourth step, the spikes are identified by comparing the differences between the original spectra and the moving-averaged spectra calculated in the third step.
As a result, the proposed method realizes the reduction of convex spikes.
The ‘whitaker’ implementation is based on the method is described in Whitaker and Hayes [2018]:
The spikes are detected when the zscore of the difference between consecutive intensities is larger than the delta parameter.
The spike intensities are replaced by the average of the intensities in a window around the spike, excluding the points that are spikes.
The ‘neighbors’ method compares each sample with its two immediate neighbors along
dim, independently at every position on the other dimensions. A positive excursion above both neighbors is replaced by their mean if it exceedsdeltatimes the scaled median absolute deviation of the residuals from the neighbor mean. Endpoints, triplets with masked or non-finite values are skipped. With zero estimated noise, any strictly positive excess above both neighbors qualifies. For a time series of spectra, choose the acquisition axis. Short traces may contain too few unaffected samples to estimate the noise reliably.- Parameters:
dataset (
NDDatasetor a ndarray-like object) – Input object.size (int, optional, default: 9) – Size of the moving average window (‘katsumoto’ method) or the size of the window around the spike to estimate the intensities (‘whitaker’ method).
delta (float, optional, default: 2) – Set the threshold for the detection of spikes.
method (str, optional, default: ‘katsumoto’) – The method to use. Can be ‘katsumoto’, ‘whitaker’, or ‘neighbors’.
dim (str or int, optional, default: -1) – Dimension used by ‘neighbors’. Each replacement uses exactly two immediate neighbors, independently of
size.
- Returns:
NDdataset– The despike dataset