I am looking to find the peaks in some gaussian smoothed data that I have. I have looked at some of the peak detection methods available but they require an input range over which to search and I want this to be more automated than that. These methods are also designed for non-smoothed data. As my data is already smoothed I require a much more simple way of retrieving the peaks. My raw and smoothed data is in the graph below.
Essentially, is there a pythonic way of retrieving the max values from the array of smoothed data such that an array like
a = [1,2,3,4,5,4,3,2,1,2,3,2,1,2,3,4,5,6,5,4,3,2,1]
would return:
r = [5,3,6]
If you can exclude maxima at the edges of the arrays you can always check if one elements is bigger than each of it's neighbors by checking:
There exists a bulit-in function
argrelextrema
that gets this task done:That gives you the desired output for
r
.As of SciPy version 1.1, you can also use find_peaks. Below are two examples taken from the documentation itself.
Using the
height
argument, one can select all maxima above a certain threshold (in this example, all non-negative maxima; this can be very useful if one has to deal with a noisy baseline; if you want to find minima, just multiply you input by-1
):Another extremely helpful argument is
distance
, which defines the minimum distance between two peaks:If you input represents noisy distrinbutions, you can try smoothing it with numpy convovle function.
If your original data is noisy, then using statistical methods is preferable, as not all peaks are going to be significant. For your
a
array, a possible solution is to use double differentials: