From aa19e7237a7d9c727cc5533a69c9320b8360e648 Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <mercadil@max-exfl039.desy.de> Date: Wed, 1 May 2019 13:58:44 +0200 Subject: [PATCH] raise TypeError if npulses missing when no pulse pattern info is available --- xgm.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/xgm.py b/xgm.py index 195550c..5b292f6 100644 --- a/xgm.py +++ b/xgm.py @@ -126,7 +126,7 @@ def selectSASEinXGM(data, sase='sase3', xgm='SCS_XGM', sase3First=True, npulses= sase: key of sase to select: {'sase1', 'sase3'} xgm: key of xgm to select: {'SA3_XGM', 'SCS_XGM'} sase3First: bool, optional. Used in case no bunch pattern was recorded - npulses: int, optional. Used in case no bunch pattern was recorded. + npulses: int, optional. Required in case no bunch pattern was recorded. Output: DataArray that has all trainIds that contain a lasing @@ -135,10 +135,13 @@ def selectSASEinXGM(data, sase='sase3', xgm='SCS_XGM', sase3First=True, npulses= are filled with NaNs. ''' if sase not in data: - print('Missing bunch pattern info!\n' - +'Retrieving {} SASE {} pulses assuming that '.format(npulses, sase[4]) + print('Missing bunch pattern info!') + if npulses is None: + raise TypeError('npulses argument is required when bunch pattern ' + + 'info is missing.') + print('Retrieving {} SASE {} pulses assuming that '.format(npulses, sase[4]) +'SASE {} pulses come first.'.format('3' if sase3First else '1')) - #in older version of DAQ, non data numbers were filled with 0.0. + #in older version of DAQ, non-data numbers were filled with 0.0. xgmData = data[xgm].where(data[xgm]!=0.0, drop=True) xgmData = xgmData.fillna(0.0).where(xgmData!=1.0, drop=True) if (sase3First and sase=='sase3') or (not sase3First and sase=='sase1'): @@ -449,7 +452,7 @@ def getTIMapd(data, mcp=1, use_apd=True, intstart=None, intstop=None, bkgstop: trace index of background stop t_offset: index separation between two pulses mcp: MCP channel number - npulses: int, optional. Number of pulses to compute. Needed if + npulses: int, optional. Number of pulses to compute. Required if no bunch pattern info is available. stride: int, optional. Used to select pulses in the APD array if no bunch pattern info is available. @@ -458,9 +461,12 @@ def getTIMapd(data, mcp=1, use_apd=True, intstart=None, intstop=None, with N=max(number of pulses per train) ''' if 'sase3' not in data: - print('Missing bunch pattern info!\n' - +'Retrieving {} SASE 3 pulses assuming that '.format(npulses) - +'SASE 3 pulses come first.') + print('Missing bunch pattern info!\n') + if npulses is None: + raise TypeError('npulses argument is required when bunch pattern ' + + 'info is missing.') + print('Retrieving {} SASE 3 pulses assuming that '.format(npulses) + + 'SASE 3 pulses come first.') if use_apd: tim = data['MCP{}apd'.format(mcp)][:,:npulses:stride] else: @@ -800,7 +806,7 @@ def matchXgmTimPulseId(data, use_apd=True, intstart=None, intstop=None, bkgstart: trace index of background start bkgstop: trace index of background stop t_offset: index separation between two pulses - npulses: number of pulses to compute. Needed if no bunch + npulses: number of pulses to compute. Required if no bunch pattern info is available sase3First: bool, needed if bunch pattern is missing. stride: int, used to select pulses in the TIM APD array if -- GitLab