diff --git a/src/calng/agipd_gpu.py b/src/calng/agipd_gpu.py index 8cfbdd0f429fafb504dfb79f479e285645fb49f9..196aa30acd9d46ac1559e1e0af4711a63d408788 100644 --- a/src/calng/agipd_gpu.py +++ b/src/calng/agipd_gpu.py @@ -92,10 +92,20 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): nan_bool = np.isnan(naughty_array) nan_cell, _, _ = np.where(nan_bool) naughty_array[nan_bool] = medians[nan_cell] - # TODO: clamp values outside range (0.8 to 1.2) * median to median + + # TODO: verify that this clamping should be done (as in agipdlib.py) + too_low_bool = naughty_array < 0.8 * medians[:, np.newaxis, np.newaxis] + too_low_cell, _, _ = np.where(too_low_bool) + naughty_array[too_low_bool] = medians[too_low_cell] + + too_high_bool = naughty_array > 1.2 * medians[:, np.newaxis, np.newaxis] + too_high_cell, _, _ = np.where(too_high_bool) + naughty_array[too_high_bool] = medians[too_high_cell] frac_hg_mg = hg_slope / mg_slope - md_additional_offset = (hg_intercept - mg_intercept * frac_hg_mg).astype(np.float32) + md_additional_offset = (hg_intercept - mg_intercept * frac_hg_mg).astype( + np.float32 + ) rel_gain_map = np.ones( (3, self.constant_memory_cells, self.pixels_y, self.pixels_x), dtype=np.float32, @@ -109,13 +119,23 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): def load_rel_gain_ff_map(self, slopes_ff_map): # constant shape: y, x, memory cell if slopes_ff_map.shape[2] == 2: - # old format, is per pixel only - raise NotImplementedError("Old slopes FF map format") + # old format, is per pixel only (shape is y, x, 2) + slopes_ff_map = np.broadcast_to( + slopes_ff_map[..., 0][..., np.newaxis], + (self.pixels_y, self.pixels_x, self.constant_memory_cells), + ) + else: + # TODO: maybe extend in case constant has too few memory cells + # TODO: maybe divide by something because new constants are absolute + ... + # TODO: maybe clamp and replace NaNs like slopes_pc self.rel_gain_xray_map_gpu.set(np.transpose(slopes_ff_map).astype(np.float32)) def correct(self, flags): if flags & CorrectionFlags.BLSHIFT: raise NotImplementedError("Baseline shift not implemented yet") + if flags & CorrectionFlags.BPMASK: + raise NotImplementedError("Bad pixel masking not implemented yet") self.correction_kernel( self.full_grid, self.full_block,