From 9deda5ed9f6f5dcb6b1f4b776c27173266ce40aa Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <laurent.mercadier@xfel.eu> Date: Sun, 22 Sep 2024 17:26:56 +0200 Subject: [PATCH] avoid modifying integParams in get_peaks() --- src/toolbox_scs/detectors/digitizers.py | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/toolbox_scs/detectors/digitizers.py b/src/toolbox_scs/detectors/digitizers.py index 8367242..dad9404 100644 --- a/src/toolbox_scs/detectors/digitizers.py +++ b/src/toolbox_scs/detectors/digitizers.py @@ -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}) -- GitLab