Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
period = 24 * step
else:
period = 1
results = xr.DataArray(np.empty((data.trainId.shape[0], npulses)), coords=data[keyraw].coords,
dims=['trainId', 'peakId'.format(channel)])
for i in range(npulses):
a = intstart + period*i
b = intstop + period*i
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
return results
def mergeFastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop,
period=None, npulses=None, dim='lasPulseId'):
''' Calculates the peaks from Fast ADC raw traces with fastAdcPeaks()
and merges the results in Dataset.
Inputs:
data: xr Dataset with 'FastADC[channel]raw' traces
channel: Fast ADC channel
intstart: trace index of integration start
intstop: trace index of integration stop
bkgstart: trace index of background start
bkgstop: trace index of background stop
period: Number of samples separation between two pulses. Needed
if bunch pattern info is not available. If None, checks the
pulse pattern and determine the period assuming a resolution
of 9.23 ns per sample which leads to 24 samples between
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')
dim: name of the xr dataset dimension along the peaks
'''
peaks = fastAdcPeaks(data, channel=channel, intstart=intstart, intstop=intstop,
bkgstart=bkgstart, bkgstop=bkgstop, period=period,
npulses=npulses)
key = 'FastADC{}peaks'.format(channel)
if key in data:
s = data.drop(key)
else:
s = data
peaks = peaks.rename(key).rename({'peakId':dim})
subset = xr.merge([s, peaks], join='inner')
for k in data.attrs.keys():
subset.attrs[k] = data.attrs[k]
return subset