From 01c52bc8c0103410319ebb1976ae86500160eca3 Mon Sep 17 00:00:00 2001 From: Egor Sobolev <egor.sobolev@xfel.eu> Date: Fri, 26 Aug 2022 12:19:24 +0200 Subject: [PATCH] Apply suggestions Co-authored-by: Thomas Kluyver <thomas.kluyver@xfel.eu> --- .../AGIPD/AGIPD_Correct_and_Verify.ipynb | 6 +-- src/cal_tools/agipdlib.py | 49 +++++-------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index e1940696b..2048c87e6 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -88,7 +88,7 @@ "use_ppu_device = '' # Device ID for a pulse picker device to only process picked trains, empty string to disable\n", "ppu_train_offset = 0 # When using the pulse picker, offset between the PPU's sequence start and actually picked train\n", "\n", - "use_litframe_finder = 'auto' # Process only illuminated frames: 'off' - disable, 'device' - use online device data, 'offline' - use offline algorithm, 'auto' - choose online/offline source automatically (default)\n", + "use_litframe_finder = 'off' # Process only illuminated frames: 'off' - disable, 'device' - use online device data, 'offline' - use offline algorithm, 'auto' - choose online/offline source automatically (default)\n", "litframe_device_id = '' # Device ID for a lit frame finder device, empty string to auto detection\n", "energy_threshold = -1000 # The low limit for the energy (uJ) exposed by frames subject to processing. If -1000, selection by pulse energy is disabled\n", "\n", @@ -452,7 +452,7 @@ "outputs": [], "source": [ "if use_litframe_finder != 'off':\n", - " from extra_redu import make_litframe_finder\n", + " from extra_redu import make_litframe_finder, SourceNotFound as RequiredSourceNotFound\n", " from extra_redu.litfrm.utils import litfrm_run_report\n", "\n", " if use_litframe_finder not in ['auto', 'offline', 'online']:\n", @@ -482,7 +482,7 @@ " ).format(frmintf=frmintf, trsintf=trsintf, **rec)\n", " )\n", " cell_sel = LitFrameSelection(r, train_ids, max_pulses, energy_threshold)\n", - " except Exception as err:\n", + " except RequiredSourceNotFound as err:\n", " print(\"Cannot use AgipdLitFrameFinder due to:\")\n", " print(err)\n", " cell_sel = CellRange(max_pulses, max_cells=mem_cells)\n", diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py index 852be0440..3da303837 100644 --- a/src/cal_tools/agipdlib.py +++ b/src/cal_tools/agipdlib.py @@ -1002,50 +1002,25 @@ class AgipdCorrections: # Only select data corresponding to selected pulses # and overwrite data in shared-memory leaving # the required indices to correct - # - data - arr = data_dict['data'][:n_img][can_calibrate] - data_dict['data'][:n_img_sel] = arr - # - rawgain` - arr = data_dict['rawgain'][:n_img][can_calibrate] - data_dict['rawgain'][:n_img_sel] = arr - # - cellId - arr = data_dict['cellId'][:n_img][can_calibrate] - data_dict['cellId'][:n_img_sel] = arr - # - pulseId - arr = data_dict['pulseId'][:n_img][can_calibrate] - data_dict['pulseId'][:n_img_sel] = arr - # - trainId - arr = data_dict['trainId'][:n_img][can_calibrate] - data_dict['trainId'][:n_img_sel] = arr - - # arrays generated after reading and initial selection - # - gain - arr = data_dict['gain'][:n_img][can_calibrate] - data_dict['gain'][:n_img_sel] = arr + array_names = ["data", "rawgain", "cellId", "pulseId", "trainId", "gain"] + # if AGIPD in fixed gain mode or melting snow was not requested + # `t0_rgain` and `raw_data` will be empty shared_mem arrays is_adaptive = self.gain_mode is AgipdGainMode.ADAPTIVE_GAIN melt_snow = self.corr_bools.get("melt_snow") if (is_adaptive and melt_snow): - # - t0_rgain - arr = data_dict['t0_rgain'][:n_img][can_calibrate] - data_dict['t0_rgain'][:n_img_sel] = arr - # - raw_gain - arr = data_dict['raw_data'][:n_img][can_calibrate] - data_dict['raw_data'][:n_img_sel] = arr + array_names += ["t0_rgain", "raw_data"] # if baseline correction was not requested # `msk` and `rel_corr` will still be empty shared_mem arrays if any(self.blc_bools): - # - blShift - arr = data_dict['blShift'][:n_img][can_calibrate] - data_dict['blShift'][:n_img_sel] = arr - # - msk - arr = data_dict['msk'][:n_img][can_calibrate] - data_dict['msk'][:n_img_sel] = arr - # - rel_corr + array_names += ["blShift", "msk"] if hasattr(self, "rel_gain"): - arr = data_dict['rel_corr'][:n_img][can_calibrate] - data_dict['rel_corr'][:n_img_sel] = arr + array_names.append("rel_corr") + + for name in array_names: + arr = data_dict[name][:n_img][can_calibrate] + data_dict[name][:n_img_sel] = arr # Overwrite number of images data_dict['nImg'][0] = n_img_sel @@ -1628,7 +1603,7 @@ class LitFrameSelection(CellSelection): litfrmdata: 'AgipdLitFrameFinderOffline', train_ids: List[int], crange: Optional[List[int]] = None, - energy_threshold: Optional[float] = None): + energy_threshold: float = -1000): """Initialize lit frame selection :param litfrmdata: AgipdLitFrameFinder output data @@ -1639,7 +1614,7 @@ class LitFrameSelection(CellSelection): # read AgipdLitFrameFinder data self.dev = litfrmdata.meta.litFrmDev self.crange = validate_selected_pulses(crange, self.ncell_max) - self.ethr = energy_threshold + self.energy_threshold = energy_threshold nfrm = litfrmdata.output.nFrame litfrm_train_ids = litfrmdata.meta.trainId -- GitLab