PeakUtils — A peak finding algorithm.¶
A version of the PyPi PeakUtils, converted from Python3.4 to Python2.7.

class
admit.util.peakfinder.PeakUtils.
PeakUtils
(spec, x=None, **kwarg)[source]¶ PeakUtils peak finding algorithm
Parameters: spec : List or numpy array
The spectrum to be analyzed.
x : List or numpy array, optional
The x coordinates for the spectrum. Default = None.
kwarg : Dict
Any additional arguments, see the Attributes list for a complete listing.
Attributes
spec (numpy array) The spectrum to be analyzed. x (numpy array) The x coordinates of the spectrum. thres (float) Threshold for detecting a peak/valley. The absolute value of the intensity must be above this value. Default: 0.0. min_dist (int) The minimum distance between peaks in channels. Deafult: 5. profile (str) The spectral line profile to use when refining the fits. Choices are “gaussian” and “lorentzian”. Default: “gaussian”. width (int) The number of channels on either side of a peak to use when refining the fit. Default: 10. basedeg (int) Degree of the polynomial that will estimate the data baseline. Default: 3. baseiter (int) The maximum number of iterations to perform when trying to fit the baseline. Default: 100. basetol (float) Tolerance to use when comparing the difference between the current fit coefficient and the ones from the last iteration. Default: 1e3. dobase (boolean) Whether or not to do baseline/continuum subtraction. Default: False. Methods
baseline
([deg, max_it, tol])Computes the baseline of a given data. centroid
([chans])Computes the centroid for the specified data. find
()Method to find any peaks in the spectrum. gaussian
(x, ampl, center, dev)Computes the Gaussian function. gaussian_fit
([chans])Performs a Gaussian fitting of the specified data. indexes
([thres, min_dist])Peak detection routine. interpolate
([ind, width, func])Tries to enhance the resolution of the peak detection by using Gaussian fitting, centroid computation or an arbitrary function on the neighborhood of each previously detected peak index. laurentzian_fit
([chans])Performs a Lorentzian fitting of the specified data. lorentzian
(x, ampl, center, width)Computes the Lorentzian function. scale
(x[, new_range, eps])Changes the scale of an array 
basedeg
= 3¶

baseiter
= 100¶

baseline
(deg=3, max_it=100, tol=0.001)[source]¶ Computes the baseline of a given data.
Iteratively performs a polynomial fitting in the data to detect its baseline. At every iteration, the fitting weights on the regions with peaks is reduced to identify the baseline only.
Parameters: deg : int
Degree of the polynomial that will estimate the data baseline. A low degree may fail to detect all the baseline present, while a high degree may make the data too oscillatory, especially at the edges.
max_it : int
Maximum number of iterations to perform.
tol : float
Tolerance to use when comparing the difference between the current fit coefficient and the ones from the last iteration. The iteration procedure will stop when the difference between them is lower than tol.
Returns: ndarray
Array with the baseline amplitude for every original point in y

basetol
= 0.001¶

centroid
(chans=[0, 1])[source]¶ Computes the centroid for the specified data.
Parameters: chans : list
The indexes to start and end at. Default: [0,1]
Returns: float
Centroid of the data.

dobase
= False¶

find
()[source]¶ Method to find any peaks in the spectrum. A baseline will be subtracted first if requested.
Parameters: None
Returns: numpy array of floats
containing the locations of the peaks

gaussian
(x, ampl, center, dev)[source]¶ Computes the Gaussian function.
Parameters: x : float
Point to evaluate the Gaussian for.
ampl : float
Amplitude.
center : float
Center.
dev : float
Width.
Returns: float
Value of the specified Gaussian at x

gaussian_fit
(chans=[0, 1])[source]¶ Performs a Gaussian fitting of the specified data.
Parameters: chans : list
The indexes to start and end at. Default: [0,1]
Returns: ndarray
Parameters of the Gaussian that fits the specified data

indexes
(thres=0.0, min_dist=5)[source]¶ Peak detection routine.
Finds the peaks in y by taking its first order difference. By using thres and min_dist parameters, it is possible to reduce the number of detected peaks.
Parameters: thres : float
Threshold for detecting a peak/valley. The absolute value of the intensity must be above this value. Default: 0.0
min_dist : int
Minimum distance between each detected peak. The peak with the highest amplitude is preferred to satisfy this constraint.
Returns: ndarray
Array containing the indexes of the peaks that were detected

interpolate
(ind=None, width=10, func='gaussian_fit')[source]¶ Tries to enhance the resolution of the peak detection by using Gaussian fitting, centroid computation or an arbitrary function on the neighborhood of each previously detected peak index.
Parameters: ind : ndarray
Indexes of the previously detected peaks. If None, indexes() will be called with the default parameters.
width : int
Number of points (before and after) each peak index to pass to func in order to increase the resolution in x.
func : function(x,y)
Function that will be called to detect an unique peak in the x,y data.
Returns: ndarray :
Array with the adjusted peak positions (in x)

laurentzian_fit
(chans=[0, 1])[source]¶ Performs a Lorentzian fitting of the specified data.
Parameters: chans : list
The indexes to start and end at. Default: [0,1]
Returns: ndarray
Parameters of the Lorentzian that fits the specified data

lorentzian
(x, ampl, center, width)[source]¶ Computes the Lorentzian function.
Parameters: x : float
Point to evaluate the Gaussian for.
ampl : float
Amplitude.
center : float
Center.
width : float
Width.
Returns: float
Value of the specified Gaussian at x

min_dist
= 1¶

profile
= 'gaussian'¶

scale
(x, new_range=(0.0, 1.0), eps=1e09)[source]¶ Changes the scale of an array
Parameters: x : ndarray
1D array to change the scale (remains unchanged)
new_range : tuple (float, float)
Desired range of the array
eps: float
Numerical precision, to detect degenerate cases (for example, when every value of x is equal)
Returns: ndarray
Scaled array
tuple (float, float)
Previous data range, allowing a rescale to the old range

thres
= 0.0¶

width
= 10¶
