From 267ae8a35249d62a5940af2a4409bdf60d262909 Mon Sep 17 00:00:00 2001 From: Philipp Schmidt <philipp.schmidt@xfel.eu> Date: Fri, 13 May 2022 21:28:56 +0200 Subject: [PATCH] Move cell axis to the front front in constants to accelerate native LPD correction code --- notebooks/LPD/LPD_Correct_Fast.ipynb | 12 ++++++------ src/cal_tools/lpdalgs.pyx | 17 ++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb index f624f5fae..12aab1e7d 100644 --- a/notebooks/LPD/LPD_Correct_Fast.ipynb +++ b/notebooks/LPD/LPD_Correct_Fast.ipynb @@ -314,12 +314,12 @@ "ccv_shape = (mem_cells, 256, 256, 3)\n", "\n", "constant_order = {\n", - " 'Offset': (1, 0, 2, 3),\n", - " 'BadPixelsDark': (1, 0, 2, 3),\n", - " 'RelativeGain': (1, 0, 2, 3),\n", - " 'FFMap': (0, 1, 2, 3),\n", - " 'BadPixelsFF': (0, 1, 2, 3),\n", - " 'GainAmpMap': (0, 1, 2, 3),\n", + " 'Offset': (2, 1, 0, 3),\n", + " 'BadPixelsDark': (2, 1, 0, 3),\n", + " 'RelativeGain': (2, 1, 0, 3),\n", + " 'FFMap': (2, 0, 1, 3),\n", + " 'BadPixelsFF': (2, 0, 1, 3),\n", + " 'GainAmpMap': (2, 0, 1, 3),\n", "}\n", "\n", "def prepare_constants(wid, index, aggregator):\n", diff --git a/src/cal_tools/lpdalgs.pyx b/src/cal_tools/lpdalgs.pyx index d7995b51b..66b8b097c 100644 --- a/src/cal_tools/lpdalgs.pyx +++ b/src/cal_tools/lpdalgs.pyx @@ -19,16 +19,16 @@ cdef mask_t WRONG_GAIN_VALUE = BadPixels.WRONG_GAIN_VALUE, \ @wraparound(False) @cdivision(True) def correct_lpd_frames( - # (pulse, x, y) + # (frame, x, y) raw_t[:, :, ::contiguous] in_raw, cell_t[::contiguous] in_cell, - # (pulse, x, y) + # (frame, x, y) data_t[:, :, ::contiguous] out_data, gain_t[:, :, ::contiguous] out_gain, mask_t[:, :, ::contiguous] out_mask, - # (x, y, cell, gain) + # (cell, x, y, gain) float[:, :, :, ::contiguous] ccv_offset, float[:, :, :, ::contiguous] ccv_gain, mask_t[:, :, :, ::contiguous] ccv_mask, @@ -51,19 +51,14 @@ def correct_lpd_frames( gain = <gain_t>((in_raw[frame, ss, fs] & 0x3000) >> 12) if gain <= 2: - mask = ccv_mask[ss, fs, cell, gain] + mask = ccv_mask[cell, ss, fs, gain] else: data = 0.0 gain = 0 mask = WRONG_GAIN_VALUE - data = data - ccv_offset[ss, fs, cell, gain] - - if ccv_gain[ss, fs, cell, gain] != 0.0: - data = data * ccv_gain[ss, fs, cell, gain] - else: - data = 0.0 - mask = mask | VALUE_IS_NAN + data = data - ccv_offset[cell, ss, fs, gain] + data = data * ccv_gain[cell, ss, fs, gain] if data > 1e7 or data < -1e7: data = 0.0 -- GitLab