diff --git a/src/calng/AgipdCorrection.py b/src/calng/AgipdCorrection.py index 563aca4aee9ac2232a44f699ebf0775b066532db..15d2ecc6f975d61e854811c631d4d233b7b8c446 100644 --- a/src/calng/AgipdCorrection.py +++ b/src/calng/AgipdCorrection.py @@ -219,7 +219,7 @@ class AgipdGpuRunner(base_gpu.BaseGpuRunner): self.g_gain_value = cupy.float32(override_value) def load_bad_pixels_map(self, bad_pixels_map, override_flags_to_use=None): - print(f"Loading bad pixels with shape: {bad_pixels_map.shape}") + self.log_status_info(f"Loading bad pixels with shape: {bad_pixels_map.shape}") # will simply OR with already loaded, does not take into account which ones # TODO: inquire what "mask for double size pixels" means if len(bad_pixels_map.shape) == 3: @@ -619,11 +619,12 @@ class AgipdCorrection(BaseCorrection): else: self._override_md_additional_offset = None - # configurability: disabling subset of bad pixel masking bits self._has_updated_bad_pixel_selection = False - self.registerInitialFunction(self._update_bad_pixel_selection) - self.updateState(State.ON) + + def _initialization(self): + self._update_bad_pixel_selection() + super()._initialization() def process_data( self, @@ -763,6 +764,7 @@ class AgipdCorrection(BaseCorrection): def postReconfigure(self): super().postReconfigure() + # TODO: move after getting cached update, check if necessary if self.get("corrections.relGainPc.overrideMdAdditionalOffset"): self._override_md_additional_offset = self.get( "corrections.relGainPc.mdAdditionalOffset" diff --git a/src/calng/DsscCorrection.py b/src/calng/DsscCorrection.py index 8785c6ef020fdb09b6b47f215b37e4dc50dca2db..4ad37908bef785e07bc14005cf885e86ef92401b 100644 --- a/src/calng/DsscCorrection.py +++ b/src/calng/DsscCorrection.py @@ -205,10 +205,6 @@ class DsscCorrection(BaseCorrection): self.get("dataFormat.pixelsX"), ) - def __init__(self, config): - super().__init__(config) - self.updateState(State.ON) - def process_data( self, data_hash, diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py index 23943d337022b2a2acd05952501126dba898add9..033ba71561f30a4b9cf249e998bc3f1b27c1e21b 100644 --- a/src/calng/base_correction.py +++ b/src/calng/base_correction.py @@ -555,34 +555,34 @@ class BaseCorrection(PythonDevice): k: config.get(k) for k in self._schema_cache_fields if config.has(k) } super().__init__(config) - self.updateState(State.INIT) if not sorted(config.get("dataFormat.outputAxisOrder")) == ["c", "x", "y"]: # TODO: figure out how to get this information to operator self.log_status_error("Invalid output axis order string") return - self.KARABO_ON_INPUT("dataInput", self.input_handler) - self.KARABO_ON_EOS("dataInput", self.handle_eos) + self.input_data_dtype = np.dtype(config.get("dataFormat.inputImageDtype")) + self.output_data_dtype = np.dtype(config.get("dataFormat.outputImageDtype")) self.sources = set(config.get("fastSources")) - self.input_data_dtype = np.dtype(config.get("dataFormat.inputImageDtype")) - self.output_data_dtype = np.dtype(config.get("dataFormat.outputImageDtype")) self.kernel_runner = None # must call _update_buffers to initialize - self.registerInitialFunction(self._update_frame_filter) - self.registerInitialFunction(self._update_buffers) - - self.calcat_friend = self._calcat_friend_class( - self, pathlib.Path.cwd() / "calibration-client-secrets.json" - ) + self._shmem_buffer = None # ditto self._correction_flag_enabled = self._correction_flag_class.NONE self._correction_flag_preview = self._correction_flag_class.NONE + self._buffer_lock = threading.Lock() + self._last_processing_started = 0 # used for processing time and timeout - self._shmem_buffer = None - self._processing_time_ema = utils.ExponentialMovingAverage(alpha=0.3) - self._rate_tracker = utils.WindowRateTracker() + self.registerInitialFunction(self._initialization) + + def _initialization(self): + self.updateState(State.INIT) + self.calcat_friend = self._calcat_friend_class( + self, pathlib.Path.cwd() / "calibration-client-secrets.json" + ) + self._update_frame_filter() + self._update_buffers() self._buffered_status_update = Hash( "trainId", @@ -592,14 +592,15 @@ class BaseCorrection(PythonDevice): "performance.processingTime", 0, ) - self._last_processing_started = 0 # used for processing time and timeout + self._processing_time_ema = utils.ExponentialMovingAverage(alpha=0.3) + self._rate_tracker = utils.WindowRateTracker() self._rate_update_timer = utils.RepeatingTimer( interval=1, callback=self._update_rate_and_state, ) - self._buffer_lock = threading.Lock() - self.KARABO_SLOT(self.loadMostRecentConstants) - self.KARABO_SLOT(self.requestScene) + + self.KARABO_ON_INPUT("dataInput", self.input_handler) + self.KARABO_ON_EOS("dataInput", self.handle_eos) if parse_version(karaboVersion) >= parse_version("2.11"): # TODO: the CalCatFriend could add these for us @@ -620,6 +621,8 @@ class BaseCorrection(PythonDevice): slotName=meth_name, ) + self.updateState(State.ON) + def __del__(self): del self._shmem_buffer