I would like to use scipy.signal.find_peaks to find peaks in some 2D data but the function defaults to ignore all edge peaks (peaks that occur on the left or right border of the array). Is there a way to include edge peaks in the results?
For example, I would like this code:
find_peaks([5,4,3,3,2,3])
to produce
[0,5]
but instead it produces
[]
The findpeaks library can detect the edges.
pip install findpeaks
Example:
X = [5,4,3,2,1,2,3,3,2,3,2,4,5,6]
# initialize with smoothing parameter
fp = findpeaks(lookahead=1, interpolate=5)
# fit
results=fp.fit(X)
# Plot
fp.plot()
# Print the xy coordinates.
# The first and last one in the array are the edges.
print(results['df'])
# x y labx valley peak labx_topology valley_topology peak_topology
# 0 5 1.0 True False 1.0 True True
# 1 4 1.0 False False 1.0 False False
# 2 3 1.0 False False 1.0 False False
# 3 2 1.0 False False 1.0 False False
# 4 1 1.0 True False 1.0 True False
# 5 2 2.0 False False 2.0 False False
# 6 3 2.0 False True 2.0 False True
# 7 3 2.0 False False 2.0 False False
# 8 2 2.0 True False 2.0 True False
# 9 3 3.0 False True 3.0 False True
# 10 2 3.0 True False 3.0 True False
# 11 4 4.0 False False 4.0 False False
# 12 5 4.0 True False 4.0 True False
# 13 6 4.0 False False 4.0 False True
Fit is done on a smoothed vector:
Final results are projected back to the original vector:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With