This is an example similar to what my data looks like, there's a sharp peak, surrounded by some small noise, and mostly constant elsewhere with small noise.
Both find_peaks_cwt
and peakutils
don't perform as I would have hoped on this data.
find_peaks_cwt
:
>>> x
[0.1, 0.1, 0.1, 0.11, 0.1, 0.09, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.0, 0.0, 0.4, 0.7, 0.7, 0.2, 0.0, 0.005, 0.1, 0.1]
>>> peaks = scipy.signal.find_peaks_cwt(x, np.arange(1,5))
>>> peaks
[1, 2, 3, 9, 12, 16, 17]
16 and 17 were correct peaks, but what's up with 1,2,3,9,12 being detected? Also, this routine lacks the ability to identify 16/17 as a single peak. That's somewhat problematic for me.
The findpeaks
package seems more robust, and I've tried implementing it, but it has weird issues. It will throw exceptions for no reason that makes sense to me when I look at the data (there's a clear peak), and sometimes it'll even produce negative indexes for no obvious reason! I got the buggy heeby jeebies after working with it for a while.
Even on this example, peakutils
doesn't seem to perform as hoped for:
>>> x
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.0, 0.0, 0.4, 0.7, 0.7, 0.2, 0.0, 0.005, 0.1, 0.1]
>>> peakutils.indexes(x, thres=0.0) # I tried many values of thres
array([], dtype=int64)
Any suggestions on identifying sharp peaks like this? I'm considering not using peak detection and just writing my own function to identify them.