# PeakDetect — Peak detection of peaks and valleys.¶

This module defines a peak detection utility that looks for local maxima and minima. It is based on code by Marcos Duarte, https://github.com/demotu/BMC.

class admit.util.peakfinder.PeakDetect.PeakDetect(spec, x=None, **kwarg)[source]

Detect peaks in data based on their amplitude and other features.

Parameters: spec : 1D array_like The input spectra to search for peaks. x : 1D array_like The x co-ordinates for the spectrum (optional). Default: None. kwarg : Dict Any additional arguments, see the Attributes list for a complete listing.

Examples

from admit.util.peakfinder.PeakDetect import PeakDetect
import numpy as np
x = np.random.randn(100)
x[60:81] = np.nan
# detect all peaks
pd = PeakDetect(x)
ind = pd.find()
print(ind)

x = np.sin(2*np.pi*5*np.linspace(0, 1, 200)) + np.random.randn(200)/5
# set minimum peak height = 0 and minimum peak distance = 20
pd = PeakDetect(x, min_sep=20, thresh=0)
ind = pd.find()

x = [0, 1, 0, 2, 0, 3, 0, 2, 0, 1, 0]
# set minimum peak distance = 2
pd = PeakDetect(x, min_sep=2)
ind = pd.find()

x = [0, 1, 1, 0, 1, 1, 0]
# detect both edges
pd = PeakDetect(x, edge='both')
ind = pd.find()


Attributes

 spec (1D array_like) The input spectra to search for peaks. x (1D array_like) The x co-ordinates for the spectrum (optional) Default: None. thresh (float) Detect peaks that are greater than minimum peak height. Default: 0.0. min_sep (int) Detect peaks that are at least separated by minimum peak distance, in number of channels. Default : 5. edge (str) One of ‘rising’, ‘falling’, or ‘both’, optional. For a flat peak, keep only the rising edge (‘rising’), only the falling edge (‘falling’), both edges (‘both’). Default : ‘rising’. kpsh (bool) Keep peaks with same height even if they are closer than min_sep, optional. Default: False.

Methods

 detect_peaks(spec[, valley]) Detects peaks. find() Method to locate peaks in an input spectrum
detect_peaks(spec, valley=False)[source]

Detects peaks.

Parameters: spec : 1D array The specrum to analyze. valley : bool Whether to search for peaks (positive) or valleys (negative). Default: False 1D array_like indeces of the peaks in spec.

Notes

The detection of valleys instead of peaks is performed internally by simply negating the data: ind_valleys = detect_peaks(-x)

The function can handle NaN’s

See this IPython Notebook [R5].

References

edge = 'rising'
find()[source]

Method to locate peaks in an input spectrum

Parameters: None Numpy array containing the located peaks
kpsh = False
min_sep = 5
thresh = 0.0