Peakutils works pretty well for peak finding. Found by reading: https://blog.ytotech.com/2015/11/01/findpeaks-in-python/
When comparing with graph in Igor, the function accurately finds the maximum point.
Do not smooth spectra; this was tested and gave peaks that were off.
In [74]:
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal as sps
import peakutils
from peakutils import plot
%matplotlib inline
In [16]:
spectrum=np.genfromtxt('../Data/PointSpectra/Spectrum1.txt', delimiter="", skip_header=1)
In [91]:
#threshold=minimum peak intensity required to count as a peak
#min_distance=should put experimental wavenumber spacing.
peakindices = peakutils.indexes(spectrum[:,1], thres=0.10, min_dist=1)
In [92]:
peakutils.plot.plot(spectrum[:,0],spectrum[:,1], peakindices)
In [46]:
peaksdict={}
for index in indexes:
peaksdict[spectrum[index][0]] = spectrum[index][1]
In [57]:
def SavGolSmooth(self):
wavenumbers = self[:,0]
intensity = self[:,1]
smooth = sps.savgol_filter(intensity, 5, 1, deriv=1, delta=10)
return smooth
In [71]:
smoothed = SavGolSmooth(spectrum)
smoothedindexes = peakutils.indexes(smoothed, thres=0.00008, min_dist=5)
smoothedpeaksdict={}
for index in smoothedindexes:
smoothedpeaksdict[spectrum[index][0]] = spectrum[index][1]
In [73]:
smoothedpeaksdict
#not sure if im indexing incorrectly
Out[73]:
In [ ]: