diff --git a/doc/changelog.rst b/doc/changelog.rst index 9bdcef0efc006469d4ecb2ebcaa8d25af5d6f1ef..36ab46d8a551191a57cf3256a1e5e2541a3c215c 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,7 @@ unreleased - **Bug fixes** + - fix :issue:`75` regarding pulse Id assignment when reading BAM data :mr:`272` - **Improvements** diff --git a/src/toolbox_scs/detectors/bam_detectors.py b/src/toolbox_scs/detectors/bam_detectors.py index 2eca1e72a23102c4c472a2f0c77203f753e36fca..fde4b8e09024f40e51eaa92d962cd313cfd2cc73 100644 --- a/src/toolbox_scs/detectors/bam_detectors.py +++ b/src/toolbox_scs/detectors/bam_detectors.py @@ -89,13 +89,13 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3', else: ds_mw = xr.Dataset() + dim_names = {'sase3': 'sa3_pId', 'sase1': 'sa1_pId', + 'scs_ppl': 'ol_pId'} bpt = load_bpt(run, ds_mw) if bpt is not None: mask = is_pulse_at(bpt, bunchPattern) - pattern_changed = ~(mask == mask[0]).all().values + mask = mask.rename({'pulse_slot': dim_names[bunchPattern]}) ds = xr.Dataset() - dim_names = {'sase3': 'sa3_pId', 'sase1': 'sa1_pId', - 'scs_ppl': 'ol_pId'} run_mnemonics = mnemonics_for_run(run) for m in mnemonics: if merge_with is not None and m in merge_with: @@ -105,15 +105,9 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3', da_bam = da_bam.sel(BAMbunchId=slice(0, 5400, 2)) # align the pulse Id if bpt is not None: - if not pattern_changed: - pulseIds = np.nonzero(mask[0].values)[0] - da_bam = da_bam.isel(BAMbunchId=pulseIds) - da_bam = da_bam.assign_coords(BAMbunchId=pulseIds) - da_bam = da_bam.rename(BAMbunchId=dim_names[bunchPattern]) - else: - mask = mask.rename({'pulse_slot': dim_names[bunchPattern]}) - da_bam = da_bam.rename(BAMbunchId=dim_names[bunchPattern]) - da_bam = da_bam.where(mask, drop=True) + da_bam = da_bam.assign_coords(BAMbunchId=np.arange(0, 2700)) + da_bam = da_bam.rename(BAMbunchId=dim_names[bunchPattern]) + da_bam = da_bam.where(mask, drop=True) if run_mnemonics[m]['key'] != 'data.lowChargeArrivalTime': da_bam *= 1e-3 ds = ds.merge(da_bam, join='inner')