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

LPD: make bad pixel masking value configurable

parent 47314d47
No related branches found
No related tags found
1 merge request!12Snapshot: field test deployed version as of end of run 202201
......@@ -6,6 +6,7 @@ from karabo.bound import (
DOUBLE_ELEMENT,
KARABO_CLASSINFO,
OVERWRITE_ELEMENT,
STRING_ELEMENT,
VECTOR_STRING_ELEMENT,
)
......@@ -287,6 +288,23 @@ class LpdCorrection(BaseCorrection):
expected, LpdCorrection._managed_keys, LpdCorrection._correction_field_names
)
# additional settings for correction steps
(
STRING_ELEMENT(expected)
.key("corrections.badPixels.maskingValue")
.displayedName("Bad pixel masking value")
.description(
"Any pixels masked by the bad pixel mask will have their value "
"replaced with this. Note that this parameter is to be interpreted as "
"a numpy.float32; use 'nan' to get NaN value."
)
.assignmentOptional()
.defaultValue("nan")
.reconfigurable()
.commit(),
)
LpdCorrection._managed_keys.add("corrections.badPixels.maskingValue")
# mandatory: manager needs this in schema
(
VECTOR_STRING_ELEMENT(expected)
......@@ -305,6 +323,16 @@ class LpdCorrection(BaseCorrection):
self.unsafe_get("dataFormat.pixelsY"),
)
def __init__(self, config):
super().__init__(config)
try:
bad_pixel_mask_value = np.float32(
config.get("corrections.badPixels.maskingValue")
)
except ValueError:
bad_pixel_mask_value = np.float32("nan")
self._kernel_runner_init_args = {"bad_pixel_mask_value": bad_pixel_mask_value}
def _load_constant_to_runner(self, constant, constant_data):
self.kernel_runner.load_constant(constant, constant_data)
correction_step = {
......@@ -390,3 +418,22 @@ class LpdCorrection(BaseCorrection):
),
metadata,
)
def preReconfigure(self, config):
# TODO: DRY (taken from AGIPD device)
super().preReconfigure(config)
if config.has("corrections.badPixels.maskingValue"):
# only check if it is valid (let raise exception)
# if valid, postReconfigure will use it
np.float32(config.get("corrections.badPixels.maskingValue"))
def postReconfigure(self):
super().postReconfigure()
if not hasattr(self, "_prereconfigure_update_hash"):
return
update = self._prereconfigure_update_hash
if update.has("corrections.badPixels.maskingValue"):
masking_value = np.float32(update["corrections.badPixels.maskingValue"])
self._kernel_runner_init_args["bad_pixel_mask_value"] = masking_value
self.kernel_runner.bad_pixel_mask_value = masking_value
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