Skip to content
Snippets Groups Projects
Commit 9deda5ed authored by Laurent Mercadier's avatar Laurent Mercadier Committed by Loïc Le Guyader
Browse files

avoid modifying integParams in get_peaks()

parent dc092fc6
No related branches found
No related tags found
1 merge request!313Adds AppleX FEL Polarization
......@@ -268,20 +268,21 @@ def get_peaks(run,
min_distance = 24
if digitizer == 'ADQ412':
min_distance = 440
params = integParams.copy()
if autoFind:
stride = int(np.max([1, np.floor(arr.sizes['trainId']/200)]))
trace = arr.isel(trainId=slice(0, None, stride)).mean(dim='trainId')
try:
integParams = find_integ_params(trace)
params = find_integ_params(trace)
except ValueError as err:
log.warning(f'{err}, trying with averaged trace over all trains.')
trace = arr.mean(dim='trainId')
integParams = find_integ_params(trace)
log.debug(f'Auto find peaks result: {integParams}')
params = find_integ_params(trace)
log.debug(f'Auto find peaks result: {params}')
required_keys = ['pulseStart', 'pulseStop', 'baseStart',
'baseStop', 'period', 'npulses']
if integParams is None or not all(name in integParams
if params is None or not all(name in params
for name in required_keys):
raise TypeError('All keys of integParams argument '
f'{required_keys} are required when '
......@@ -290,16 +291,10 @@ def get_peaks(run,
# 2.1. No bunch pattern provided
if bpt is None:
log.info('Missing bunch pattern info.')
log.debug(f'Retrieving {integParams["npulses"]} pulses.')
log.debug(f'Retrieving {params["npulses"]} pulses.')
if extra_dim is None:
extra_dim = 'pulseId'
return peaks_from_raw_trace(arr, integParams['pulseStart'],
integParams['pulseStop'],
integParams['baseStart'],
integParams['baseStop'],
integParams['period'],
integParams['npulses'],
extra_dim=extra_dim)
return peaks_from_raw_trace(arr, **params, extra_dim=extra_dim)
# 2.2 Bunch pattern is provided
# load mask and extract pulse Id:
......@@ -327,7 +322,7 @@ def get_peaks(run,
period_bpt = 0
else:
period_bpt = np.min(np.diff(pid))
if autoFind and period_bpt*min_distance != integParams['period']:
if autoFind and period_bpt*min_distance != params['period']:
log.warning('The period from the bunch pattern is different than '
'that found by the peak-finding algorithm. Either '
'the algorithm failed or the bunch pattern source '
......@@ -335,15 +330,9 @@ def get_peaks(run,
# create array of sample indices for peak integration
sample_id = (pid-pid[0])*min_distance
# override auto find parameters
if isinstance(integParams['pulseStart'], (int, np.integer)):
integParams['pulseStart'] = integParams['pulseStart'] + sample_id
peaks = peaks_from_raw_trace(valid_arr, integParams['pulseStart'],
integParams['pulseStop'],
integParams['baseStart'],
integParams['baseStop'],
integParams['period'],
integParams['npulses'],
extra_dim)
if isinstance(params['pulseStart'], (int, np.integer)):
params['pulseStart'] = params['pulseStart'] + sample_id
peaks = peaks_from_raw_trace(valid_arr, **params, extra_dim=extra_dim)
if pattern_changed:
peaks = peaks.where(mask_on, drop=True)
return peaks.assign_coords({extra_dim: pid})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment