From b42f44784d0241b57f386fcca84d54e786a6f6fa Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Thu, 12 May 2022 12:52:29 +0200
Subject: [PATCH] Use clearer symbol names in lpdalgs

---
 src/cal_tools/lpdalgs.pyx | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/cal_tools/lpdalgs.pyx b/src/cal_tools/lpdalgs.pyx
index 635dc07de..4614711c3 100644
--- a/src/cal_tools/lpdalgs.pyx
+++ b/src/cal_tools/lpdalgs.pyx
@@ -5,8 +5,8 @@ from cython.parallel cimport prange
 from cal_tools.enums import BadPixels
 
 ctypedef unsigned short cell_t
-ctypedef unsigned short data_t
-ctypedef float pixel_t
+ctypedef unsigned short raw_t
+ctypedef float data_t
 ctypedef unsigned char gain_t
 ctypedef unsigned int mask_t
 
@@ -20,11 +20,11 @@ cdef mask_t WRONG_GAIN_VALUE = BadPixels.WRONG_GAIN_VALUE, \
 @cdivision(True)
 def correct_lpd_frames(
     # (pulse, x, y)
-    data_t[:, :, ::contiguous] in_data,
+    raw_t[:, :, ::contiguous] in_raw,
     cell_t[::contiguous] in_cell,
 
     # (pulse, x, y)
-    pixel_t[:, :, ::contiguous] out_pixels,
+    data_t[:, :, ::contiguous] out_data,
     gain_t[:, :, ::contiguous] out_gain,
     mask_t[:, :, ::contiguous] out_mask,
 
@@ -37,36 +37,38 @@ def correct_lpd_frames(
 ):
     cdef int frame, ss, fs
     cdef cell_t cell
-    cdef pixel_t pixel
+    cdef data_t data
     cdef gain_t gain
     cdef mask_t mask
 
-    for frame in prange(in_data.shape[0], nogil=True, num_threads=num_threads):
-        for ss in range(in_data.shape[1]):
-            for fs in range(in_data.shape[2]):
-                cell = in_cell[frame]
-                pixel = <pixel_t>(in_data[frame, ss, fs] & 0b0000111111111111)
-                gain = in_data[frame, ss, fs] & 0b0000000000000011
+    for frame in prange(in_raw.shape[0], nogil=True, num_threads=num_threads):
+        cell = in_cell[frame]
+
+        for ss in range(in_raw.shape[1]):
+            for fs in range(in_raw.shape[2]):
+                # Decode intensity and gain from raw data.
+                data = <data_t>(in_raw[frame, ss, fs] & 0x0000111111111111)
+                gain = <gain_t>((in_raw[frame, ss, fs] & 0x0000000000000011
 
                 if gain <= 2:
                     mask = ccv_mask[ss, fs, cell, gain]
                 else:
-                    pixel = 0.0
+                    data = 0.0
                     gain = 0
                     mask = WRONG_GAIN_VALUE
 
-                pixel = pixel - ccv_offset[ss, fs, cell, gain]
+                data = data - ccv_offset[ss, fs, cell, gain]
 
                 if ccv_gain[ss, fs, cell, gain] != 0.0:
-                    pixel = pixel * ccv_gain[ss, fs, cell, gain]
+                    data = data * ccv_gain[ss, fs, cell, gain]
                 else:
-                    pixel = 0.0
+                    data = 0.0
                     mask = mask | VALUE_IS_NAN
 
-                if pixel > 1e7 or pixel < -1e7:
-                    pixel = 0.0
+                if data > 1e7 or data < -1e7:
+                    data = 0.0
                     mask = mask | VALUE_OUT_OF_RANGE
 
-                out_pixels[frame, ss, fs] = pixel
+                out_data[frame, ss, fs] = data
                 out_gain[frame, ss, fs] = gain
                 out_mask[frame, ss, fs] = mask
-- 
GitLab