From d5c6b94287287992c6e9b6450c170bf0c453e58a Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Thu, 25 Mar 2021 10:36:49 +0100
Subject: [PATCH] Satisfying flake8 for agipdlib.py

---
 cal_tools/cal_tools/agipdlib.py | 58 +++++++++++++++++----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py
index 103bbc162..a098b07b8 100644
--- a/cal_tools/cal_tools/agipdlib.py
+++ b/cal_tools/cal_tools/agipdlib.py
@@ -329,7 +329,7 @@ class AgipdCorrections:
             data_dict['rawgain'][:n_img] = raw_data[:, 1]
             data_dict['cellId'][:n_img] = allcells[firange]
             data_dict['pulseId'][:n_img] = allpulses[firange]
-            data_dict['trainId'][:n_img] = np.squeeze(group['trainId'][:][firange])
+            data_dict['trainId'][:n_img] = np.squeeze(group['trainId'][:][firange])  # noqa
         except Exception as e:
             print(f'Error during reading data from file {file_name}: {e}')
             print(f'Error traceback: {traceback.format_exc()}')
@@ -502,10 +502,10 @@ class AgipdCorrections:
             t0 = self.thresholds[module_idx][0]
             t1 = self.thresholds[module_idx][1]
 
-            # load raw_data and rgain to be used during gain_correction if requested
             if self.corr_bools.get("melt_snow"):
-                self.shared_dict[i_proc]["t0_rgain"][first:last] = rawgain / t0[cellid, ...]
-                self.shared_dict[i_proc]["raw_data"][first:last] = np.copy(data)
+                # load raw_data and rgain to be used during gain_correction
+                self.shared_dict[i_proc]["t0_rgain"][first:last] = rawgain / t0[cellid, ...]  # noqa
+                self.shared_dict[i_proc]["raw_data"][first:last] = np.copy(data)  # noqa
 
             # Often most pixels are in high-gain, so it's more efficient to
             # set the whole output block to zero than select the right pixels.
@@ -522,10 +522,10 @@ class AgipdCorrections:
 
         # force into high or medium gain if requested
         if self.corr_bools.get("force_mg_if_below"):
-            gain[(gain == 2) & ((data - offsetb[1]) < self.mg_hard_threshold)] = 1
+            gain[(gain == 2) & ((data - offsetb[1]) < self.mg_hard_threshold)] = 1  # noqa
 
         if self.corr_bools.get("force_hg_if_below"):
-            gain[(gain > 0) & ((data - offsetb[0]) < self.hg_hard_threshold)] = 0
+            gain[(gain > 0) & ((data - offsetb[0]) < self.hg_hard_threshold)] = 0  # noqa
 
         # choose constants according to gain setting
         off = calgs.gain_choose(gain, offsetb)
@@ -637,7 +637,7 @@ class AgipdCorrections:
             # same for relative gain and then bad pixel mask
             if hasattr(self, "rel_gain"):
                 # Get the correct rel_gain depending on cell-id
-                rel_corr = calgs.gain_choose(gain, self.rel_gain[module_idx][:, cellid])
+                rel_corr = calgs.gain_choose(gain, self.rel_gain[module_idx][:, cellid])  # noqa
 
         # Correct for relative gain
         if self.corr_bools.get("rel_gain") and hasattr(self, "rel_gain"):
@@ -700,7 +700,9 @@ class AgipdCorrections:
         # Copy the data across into the existing shared-memory array
         mask[...] = msk[...]
 
-    def get_valid_image_idx(self, idx_base: str, infile: str, raw_format_version: int = 2):
+    def get_valid_image_idx(
+        self, idx_base: str, infile: str, raw_format_version: int = 2
+    ):
         """Return the indices of valid data"""
         if raw_format_version == 2:
             count = np.squeeze(infile[idx_base + "image/count"])
@@ -962,11 +964,11 @@ class AgipdCorrections:
 
             # Extract parameters through identifying
             # unique trains, index and numbers.
-            uq, fidxv, cntsv = np.unique(trains, return_index=True, return_counts=True)
+            uq, fidxv, cntsv = np.unique(trains, return_index=True, return_counts=True)  # noqa
 
             # Validate calculated CORR INDEX contents by checking
             # difference between trainId stored in RAW data and trains from
-            train_diff = np.isin(np.array(infile["/INDEX/trainId"]), uq, invert=True)
+            train_diff = np.isin(np.array(infile["/INDEX/trainId"]), uq, invert=True)  # noqa
 
             # Insert zeros for missing trains.
             # fidxv and cntsv should have same length as
@@ -1244,12 +1246,12 @@ class AgipdCorrections:
         """Initialize calibration constants from a yaml file
 
         :param karabo_da: a karabo data aggregator
-        :param const_yaml: from the "retrieved-constants" part of a yaml
-        file from pre-notebook, which consists of metadata of either the constant
+        :param const_yaml: from the "retrieved-constants" part of a yaml file
+        from pre-notebook, which consists of metadata of either the constant
         file path or the empty constant shape, and the creation-time of the
         retrieved constants
-        :param module_idx: Index of module.
-        :return when: Dictionary of retrieved constants with their creation-time.
+        :param module_idx: Index of module
+        :return when: dict of retrieved constants with their creation-time
         """
 
         # string of the device name.
@@ -1357,17 +1359,17 @@ class AgipdCorrections:
         :param constant_shape: Shape of expected constants (gain, cells, x, y)
         """
         for module_idx in modules:
-            self.offset[module_idx] = sharedmem.empty(constant_shape, dtype="f4")
+            self.offset[module_idx] = sharedmem.empty(constant_shape, dtype="f4")  # noqa
             if self.gain_mode is AgipdGainMode.ADAPTIVE_GAIN:
-                self.thresholds[module_idx] = sharedmem.empty(constant_shape, dtype="f4")
-            self.noise[module_idx] = sharedmem.empty(constant_shape, dtype="f4")
+                self.thresholds[module_idx] = sharedmem.empty(constant_shape, dtype="f4")  # noqa
+            self.noise[module_idx] = sharedmem.empty(constant_shape, dtype="f4")  # noqa
 
-            self.md_additional_offset[module_idx] = sharedmem.empty(constant_shape[1:], dtype="f4")
-            self.rel_gain[module_idx] = sharedmem.empty(constant_shape, dtype="f4")
-            self.frac_high_med[module_idx] = sharedmem.empty(constant_shape[1], dtype="f4")
+            self.md_additional_offset[module_idx] = sharedmem.empty(constant_shape[1:], dtype="f4")  # noqa
+            self.rel_gain[module_idx] = sharedmem.empty(constant_shape, dtype="f4")  # noqa
+            self.frac_high_med[module_idx] = sharedmem.empty(constant_shape[1], dtype="f4")  # noqa
 
             self.mask[module_idx] = sharedmem.empty(constant_shape, dtype="i4")
-            self.xray_cor[module_idx] = sharedmem.empty(constant_shape[1:], dtype="f4")
+            self.xray_cor[module_idx] = sharedmem.empty(constant_shape[1:], dtype="f4")  # noqa
 
     def allocate_images(self, shape, n_cores_files):
         """
@@ -1381,18 +1383,18 @@ class AgipdCorrections:
         self.shared_dict = []
         for i in range(n_cores_files):
             self.shared_dict.append({})
-            self.shared_dict[i]["cellId"] = sharedmem.empty(shape[0], dtype="u2")
-            self.shared_dict[i]["pulseId"] = sharedmem.empty(shape[0], dtype="u8")
-            self.shared_dict[i]["trainId"] = sharedmem.empty(shape[0], dtype="u8")
+            self.shared_dict[i]["cellId"] = sharedmem.empty(shape[0], dtype="u2")  # noqa
+            self.shared_dict[i]["pulseId"] = sharedmem.empty(shape[0], dtype="u8")  # noqa
+            self.shared_dict[i]["trainId"] = sharedmem.empty(shape[0], dtype="u8")  # noqa
             self.shared_dict[i]["moduleIdx"] = sharedmem.empty(1, dtype="i4")
             self.shared_dict[i]["nImg"] = sharedmem.empty(1, dtype="i4")
             self.shared_dict[i]["mask"] = sharedmem.empty(shape, dtype="u4")
             self.shared_dict[i]["data"] = sharedmem.empty(shape, dtype="f4")
             self.shared_dict[i]["rawgain"] = sharedmem.empty(shape, dtype="u2")
             self.shared_dict[i]["gain"] = sharedmem.empty(shape, dtype="u1")
-            self.shared_dict[i]["blShift"] = sharedmem.empty(shape[0], dtype="f4")
+            self.shared_dict[i]["blShift"] = sharedmem.empty(shape[0], dtype="f4")  # noqa
             # Parameters shared between image-wise correction functions
             self.shared_dict[i]["msk"] = sharedmem.empty(shape, dtype="i4")
-            self.shared_dict[i]["raw_data"] = sharedmem.empty(shape, dtype="f4")
-            self.shared_dict[i]["rel_corr"] = sharedmem.empty(shape, dtype="f4")
-            self.shared_dict[i]["t0_rgain"] = sharedmem.empty(shape, dtype="u2")
+            self.shared_dict[i]["raw_data"] = sharedmem.empty(shape, dtype="f4")  # noqa
+            self.shared_dict[i]["rel_corr"] = sharedmem.empty(shape, dtype="f4")  # noqa
+            self.shared_dict[i]["t0_rgain"] = sharedmem.empty(shape, dtype="u2")  # noqa
-- 
GitLab