Skip to content
Snippets Groups Projects
Commit 028556c5 authored by David Hammer's avatar David Hammer
Browse files

Add (re)configurability of bad pixel masking value

parent adb87351
No related branches found
No related tags found
2 merge requests!12Snapshot: field test deployed version as of end of run 202201,!3Base correction device, CalCat interaction, DSSC and AGIPD devices
...@@ -153,6 +153,20 @@ class AgipdCorrection(BaseCorrection): ...@@ -153,6 +153,20 @@ class AgipdCorrection(BaseCorrection):
.reconfigurable() .reconfigurable()
.commit() .commit()
) )
(
STRING_ELEMENT(expected)
.key("corrections.badPixelMaskValue")
.displayedName("Bad pixel masking value")
.description(
"Any pixels masked by the bad pixel mask will have their value "
"replaced with this. Note that this setting is evaluated as a string; "
"use float('nan') to get NaN value."
)
.assignmentOptional()
.defaultValue("float('nan')")
.reconfigurable()
.commit()
)
@property @property
def input_data_shape(self): def input_data_shape(self):
...@@ -177,7 +191,11 @@ class AgipdCorrection(BaseCorrection): ...@@ -177,7 +191,11 @@ class AgipdCorrection(BaseCorrection):
def __init__(self, config): def __init__(self, config):
# TODO: different gpu runner for fixed gain mode # TODO: different gpu runner for fixed gain mode
self.gain_mode = AgipdGainMode[config.get("gainMode")] self.gain_mode = AgipdGainMode[config.get("gainMode")]
self._gpu_runner_init_args = {"gain_mode": self.gain_mode} self.bad_pixel_mask_value = eval(config.get("corrections.badPixelMaskValue"))
self._gpu_runner_init_args = {
"gain_mode": self.gain_mode,
"bad_pixel_mask_value": self.bad_pixel_mask_value,
}
super().__init__(config) super().__init__(config)
self._output_transpose = { self._output_transpose = {
...@@ -389,6 +407,11 @@ class AgipdCorrection(BaseCorrection): ...@@ -389,6 +407,11 @@ class AgipdCorrection(BaseCorrection):
for path in config.getPaths() for path in config.getPaths()
): ):
self._has_updated_bad_pixel_selection = False self._has_updated_bad_pixel_selection = False
if config.has("corrections.badPixelMaskValue"):
self.bad_pixel_mask_value = eval(
config.get("corrections.badPixelMaskValue")
)
self.gpu_runner.set_bad_pixel_mask_value(self.bad_pixel_mask_value)
def postReconfigure(self): def postReconfigure(self):
super().postReconfigure() super().postReconfigure()
...@@ -405,4 +428,6 @@ class AgipdCorrection(BaseCorrection): ...@@ -405,4 +428,6 @@ class AgipdCorrection(BaseCorrection):
if not self._has_updated_bad_pixel_selection: if not self._has_updated_bad_pixel_selection:
self._update_bad_pixel_selection() self._update_bad_pixel_selection()
self.gpu_runner.override_bad_pixel_flags_to_use(self._override_bad_pixel_flags) self.gpu_runner.override_bad_pixel_flags_to_use(
self._override_bad_pixel_flags
)
...@@ -36,7 +36,7 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -36,7 +36,7 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner):
output_transpose=(1, 2, 0), # default: memorycells-fast output_transpose=(1, 2, 0), # default: memorycells-fast
input_data_dtype=cupy.uint16, input_data_dtype=cupy.uint16,
output_data_dtype=cupy.float32, output_data_dtype=cupy.float32,
bad_pixel_mask_value=cupy.float32(cupy.nan), bad_pixel_mask_value=cupy.nan,
gain_mode=AgipdGainMode.ADAPTIVE_GAIN, gain_mode=AgipdGainMode.ADAPTIVE_GAIN,
): ):
self.gain_mode = gain_mode self.gain_mode = gain_mode
...@@ -70,7 +70,7 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -70,7 +70,7 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner):
self.md_additional_offset_gpu = cupy.zeros(self.map_shape, dtype=cupy.float32) self.md_additional_offset_gpu = cupy.zeros(self.map_shape, dtype=cupy.float32)
self.rel_gain_xray_map_gpu = cupy.ones(self.map_shape, dtype=cupy.float32) self.rel_gain_xray_map_gpu = cupy.ones(self.map_shape, dtype=cupy.float32)
self.bad_pixel_map_gpu = cupy.zeros(self.gm_map_shape, dtype=cupy.uint32) self.bad_pixel_map_gpu = cupy.zeros(self.gm_map_shape, dtype=cupy.uint32)
self.bad_pixel_mask_value = bad_pixel_mask_value # TODO: make this configurable self.set_bad_pixel_mask_value(bad_pixel_mask_value)
self.update_block_size((1, 1, 64)) self.update_block_size((1, 1, 64))
...@@ -212,6 +212,9 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -212,6 +212,9 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner):
f"Percentage of bad pixels now: {cupy.count_nonzero(self.bad_pixel_map_gpu) / self.bad_pixel_map_gpu.size * 100:.02f}" f"Percentage of bad pixels now: {cupy.count_nonzero(self.bad_pixel_map_gpu) / self.bad_pixel_map_gpu.size * 100:.02f}"
) )
def set_bad_pixel_mask_value(self, mask_value):
self.bad_pixel_mask_value = cupy.float32(mask_value)
def flush_buffers(self): def flush_buffers(self):
self.offset_map_gpu.fill(0) self.offset_map_gpu.fill(0)
self.rel_gain_pc_map_gpu.fill(1) self.rel_gain_pc_map_gpu.fill(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment