diff --git a/src/calng/AgipdCorrection.py b/src/calng/AgipdCorrection.py index 9777cb8fc1bab007fcd006cfe846d49d1fd01860..7986831a905a0c2980c913587f5f603eb6de0981 100644 --- a/src/calng/AgipdCorrection.py +++ b/src/calng/AgipdCorrection.py @@ -535,11 +535,11 @@ class AgipdCorrection(BaseCorrection): .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." + "replaced with this. Note that this parameter is to be interpreted as " + "a numpy.float32; use 'nan' to get NaN value." ) .assignmentOptional() - .defaultValue("float('nan')") + .defaultValue("nan") .reconfigurable() .commit(), @@ -597,9 +597,14 @@ class AgipdCorrection(BaseCorrection): super().__init__(config) # TODO: consider different gpu runner for fixed gain mode self.gain_mode = AgipdGainMode[config.get("gainMode")] - self.bad_pixel_mask_value = eval( - config.get("corrections.badPixels.maskingValue") - ) + + try: + self.bad_pixel_mask_value = np.float32( + config.get("corrections.badPixels.maskingValue") + ) + except ValueError: + self.bad_pixel_mask_value = np.float32("nan") + self._kernel_runner_init_args = { "gain_mode": self.gain_mode, "bad_pixel_mask_value": self.bad_pixel_mask_value, @@ -745,6 +750,16 @@ class AgipdCorrection(BaseCorrection): selection |= field self._override_bad_pixel_flags = selection + def preReconfigure(self, config): + super().preReconfigure(config) + if config.has("corrections.badPixels.maskingValue"): + # only check if it is valid; postReconfigure will use it + try: + np.float32(config.get("corrections.badPixels.maskingValue")) + except ValueError: + self.log_status_warn("Invalid masking value, ignoring.") + config.erase("corrections.badPixels.maskingValue") + def postReconfigure(self): super().postReconfigure() @@ -772,7 +787,7 @@ class AgipdCorrection(BaseCorrection): ) if update.has("corrections.badPixels.maskingValue"): - self.bad_pixel_mask_value = eval( + self.bad_pixel_mask_value = np.float32( self.get("corrections.badPixels.maskingValue") ) self.kernel_runner.set_bad_pixel_mask_value(self.bad_pixel_mask_value)