def midpoint(specdata): """Finds major/minor peaks according to threshold values; Threshold value is divided by max peak height""" if not isinstance(specdata, pd.DataFrame): # check datatype specdata = main(specdata) specdata.set_index('0', inplace = True) #reset index as time-series else: pass midpoint = (len(specdata.iloc[0,:]))/2 # find the mid-timepoint midpoint_spectrum = specdata.iloc[:, midpoint] # find the midpoint spectrum return midpoint_spectrum
def peakfind(specdata, threshold = 0.02): """Finds major/minor peaks according to threshold values; Threshold value is divided by max peak height""" if not isinstance(specdata, pd.DataFrame): # check datatype specdata = main(specdata) specdata.set_index('0', inplace = True) #reset index as time-series else: pass # exectue the peak finding on this spectrum indices = peakutils.indexes(midpoint_spectrum, thres=threshold/max(midpoint_spectrum)) return indices
def series_peakfind(specdata, threshold = 0.2, min_dist=50): "Produces a list of lists containing the peaks at each timepoint" if not isinstance(specdata, pd.DataFrame): # check datatype specdata = main(specdata) specdata.set_index('0', inplace = True) #reset index as time-series print 'Warning: This series is not baseline corrected!' else: pass indexes=[] # initialize the empty array for i in xrange(len(specdata.iloc[0,:])): # execute peakfinding algorithm by column individual_spectrum = specdata.iloc[:,i] indexes.append(peakutils.indexes(individual_spectrum, min_dist= min_dist, thres = threshold/max(individual_spectrum))) return indexes
def series_baseline(seriesdata): """For a spectral series: Performs a baseline-identifying algorithm from -m peakutils, and corrects""" df = main(seriesdata) df.set_index('0', inplace = True) baseline_series = df.copy() # make a deep copy to the dataframe corrected_spectra = df.copy() # make a deep copy to the dataframe for i in xrange(len(df.iloc[0,:])): # execute baseline-identifier algorithm by column baseline_series.iloc[:,i] = peakutils.baseline(df.iloc[:,i]) corrected_spectra = df - baseline_series # subtract from original spectra to find correction return baseline_series, corrected_spectra
def series_peakfind(specdata, threshold = 0.05): if not isinstance(specdata, pd.DataFrame): # check datatype specdata = main(specdata) specdata.set_index('0', inplace = True) #reset index as time-series else: pass indexes=[] for i in xrange(len(specdata.iloc[0,:])): # execute baseline-identifier algorithm by column individual_spectrum = specdata.iloc[:,i] indexes.append(peakutils.indexes(individual_spectrum, thres = threshold/max(individual_spectrum))) # exectue the peak finding on this spectrum #indexes = peakutils.indexes(midpoint_spectrum, thres=threshold/max(midpoint_spectrum)) return indexes #def series_peakshow(specdata, indexes): # Next step """Plots peaks found in peakfind"""
def midpoint_peakfind(specdata): """Finds major peaks according to threshold values; Threshold value is divided by max peak height""" if not isinstance(specdata, pd.DataFrame): # check datatype specdata = main(specdata) specdata.set_index('0', inplace = True) #reset index as time-series else: pass midpoint = (len(specdata.iloc[0,:]))/2 # find the mid-timepoint midpoint_spectrum = specdata.iloc[:, midpoint] # find the midpoint spectrum # exectue the peak finding on this spectrum indices = signal.find_peaks_cwt(midpoint_spectrum) # trace the midpoint spectrum spectrum = go.Scatter( x=[j for j in range(len(midpoint_spectrum))], y=midpoint_spectrum, mode='lines', name='Abs spectrum of the midpoint-time in kinetic series' ) # mark the peaks peaks = go.Scatter( x=indices, y=[midpoint_spectrum.iloc[j] for j in indices], mode='markers', marker=dict( size=8, color='rgb(255,0,0)', symbol='cross' ), name='Detected Peaks' ) data = [spectrum, peaks] return py.plot(data)