From 54c101515c158ff730e813365deb8e6bba8aba71 Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <laurent.mercadier@xfel.eu> Date: Tue, 10 Mar 2020 22:48:50 +0100 Subject: [PATCH] Re-add option to integrate over or take extremum of peak --- xgm.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/xgm.py b/xgm.py index 24f2250..7289fc7 100644 --- a/xgm.py +++ b/xgm.py @@ -814,7 +814,8 @@ def matchXgmTimPulseId(data, use_apd=True, intstart=None, intstop=None, # Fast ADC -def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=None, npulses=None): +def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, + period=None, npulses=None, usePeakValue=False, peakType='pos'): ''' Computes peak integration from raw FastADC traces. Inputs: @@ -831,6 +832,8 @@ def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=Non two bunches @ 4.5 MHz. npulses: number of pulses. If None, takes the maximum number of pulses according to the bunch patter (field 'npulses_sase3') + usePeakValue: bool, if True takes the peak value of the signal, + otherwise integrates over integration region. Output: results: DataArray with dims trainId x max(sase3 pulses) @@ -859,11 +862,18 @@ def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=Non bkga = bkgstart + period*i bkgb = bkgstop + period*i bg = np.outer(np.median(data[keyraw][:,bkga:bkgb], axis=1), np.ones(b-a)) - integ = np.trapz(data[keyraw][:,a:b] - bg, axis=1) - results[:,i] = integ + if usePeakValue: + if peakType=='pos': + val = np.max(data[keyraw][:,a:b] - bg, axis=1) + if peakType=='neg': + val = np.min(data[keyraw][:,a:b] - bg, axis=1) + else: + val = np.trapz(data[keyraw][:,a:b] - bg, axis=1) + results[:,i] = val return results -def autoFindFastAdcPeaks(data, channel=5, window='small', display=False, plot=False): +def autoFindFastAdcPeaks(data, channel=5, window='small', usePeakValue=False, + display=False, plot=False): ''' Automatically finds peaks in channel of Fast ADC trace, a minimum width of 4 samples. The find_peaks function and determination of the peak integration region and baseline subtraction is optimized for typical photodiode signals @@ -873,6 +883,8 @@ def autoFindFastAdcPeaks(data, channel=5, window='small', display=False, plot=Fa key: data key of the array of traces window: 'small' or 'large': defines the width of the integration region centered on the peak. + usePeakValue: bool, if True takes the peak value of the signal, + otherwise integrates over integration region. display: bool, displays info on the pulses found plot: bool, plots regions of integration of the first pulse in the trace Output: @@ -916,7 +928,8 @@ def autoFindFastAdcPeaks(data, channel=5, window='small', display=False, plot=Fa print(f'Found {npulses} {posNeg} pulses, avg. width={w}, period={period} samples, ' + f'rep. rate={1e6/(9.230769*period):.3f} kHz') fAdcPeaks = fastAdcPeaks(data, channel=channel, intstart=intstart, intstop=intstop, - bkgstart=bkgstart, bkgstop=bkgstop, period=period, npulses=npulses) + bkgstart=bkgstart, bkgstop=bkgstop, period=period, npulses=npulses, + usePeakValue=usePeakValue, peakType=posNeg[:3]) if plot: plt.figure() plt.plot(trace_plot, 'o-', ms=3) -- GitLab