From 67e1ba2dc122457d78b5863e1469176568a6bfdc Mon Sep 17 00:00:00 2001 From: David Hammer <dhammer@mailbox.org> Date: Tue, 11 Jan 2022 14:44:17 +0100 Subject: [PATCH] Typos and framework usage fixes suggested by @flucke --- src/calng/base_correction.py | 81 +++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py index 5eaa53a2..28d59130 100644 --- a/src/calng/base_correction.py +++ b/src/calng/base_correction.py @@ -14,6 +14,7 @@ from karabo.bound import ( NDARRAY_ELEMENT, NODE_ELEMENT, OUTPUT_CHANNEL, + OVERWRITE_ELEMENT, SLOT_ELEMENT, STRING_ELEMENT, UINT32_ELEMENT, @@ -241,13 +242,18 @@ class BaseCorrection(PythonDevice): do_generate_preview, ): """Subclass must define data processing (presumably using the kernel runner). - Will be called by input_handler, which will take care of some common checks " - "and extracting the parameters given to process_data.""" + Will be called by input_handler, which will take care of some common checks and + extracting the parameters given to process_data.""" raise NotImplementedError() @staticmethod def expectedParameters(expected): ( + OVERWRITE_ELEMENT(expected) + .key("state") + .setNewDefaultValue(State.INIT) + .commit(), + INPUT_CHANNEL(expected).key("dataInput").commit(), OUTPUT_CHANNEL(expected) @@ -404,7 +410,7 @@ class BaseCorrection(PythonDevice): .displayedName("Memory cells") .description("Full number of memory cells in incoming data") .assignmentOptional() - .noDefaultValue() # subclass will want to set a default value + .defaultValue(1) # subclass will want to set a default value .commit(), UINT32_ELEMENT(expected) @@ -424,6 +430,7 @@ class BaseCorrection(PythonDevice): "the latter indicating the memory cell axis. The default value of " "'cxy' puts pixels on the fast axes." ) + .options("cxy,cyx,xcy,xyc,ycx,yxc") .assignmentOptional() .defaultValue("cxy") .commit(), @@ -483,7 +490,7 @@ class BaseCorrection(PythonDevice): BOOL_ELEMENT(expected) .key("preview.enable") - .displayedName("Enable preview data generation") + .displayedName("Enable preview") .assignmentOptional() .defaultValue(True) .reconfigurable() @@ -494,12 +501,13 @@ class BaseCorrection(PythonDevice): .displayedName("Index (or stat) for preview") .description( "If this value is ≥ 0, the corresponding index (frame, cell, or pulse) " - "will be sliced for the preview output. If this value is ≤ 0, preview " + "will be sliced for the preview output. If this value is < 0, preview " "will be one of the following stats: -1: max, -2: mean, -3: sum, -4: " "stdev. These stats are computed across memory cells." ) .assignmentOptional() .defaultValue(0) + .minInc(-4) .reconfigurable() .commit(), @@ -525,8 +533,8 @@ class BaseCorrection(PythonDevice): .description( "Preview will only be generated for trains whose ID modulo this " "number is zero. Higher values means less frequent preview updates. " - "Keep in mind that the GUI has limited refresh rate of 2 Hz. Should " - "take extra care if DAQ train stride is >1." + "Keep in mind that the GUI has limited refresh rate. Extra care must " + "be taken if DAQ train stride is >1." ) .assignmentOptional() .defaultValue(6) @@ -557,7 +565,7 @@ class BaseCorrection(PythonDevice): .readOnly() .initialValue(0) .warnHigh(100) - .info("Processing not fast enough for full speed") + .info("Processing too slow to reach 10 Hz") .needsAcknowledging(False) .commit(), @@ -584,17 +592,12 @@ class BaseCorrection(PythonDevice): def __init__(self, config): self._schema_cache = { - k: config.get(k) for k in self._schema_cache_fields if config.has(k) + k: config[k] for k in self._schema_cache_fields if config.has(k) } super().__init__(config) - 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.input_data_dtype = np.dtype(config.get("dataFormat.inputImageDtype")) - self.output_data_dtype = np.dtype(config.get("dataFormat.outputImageDtype")) + self.input_data_dtype = np.dtype(config["dataFormat.inputImageDtype"]) + self.output_data_dtype = np.dtype(config["dataFormat.outputImageDtype"]) self.sources = set(config.get("fastSources")) @@ -606,10 +609,32 @@ class BaseCorrection(PythonDevice): self._buffer_lock = threading.Lock() self._last_processing_started = 0 # used for processing time and timeout + # register slots + if parse_version(karaboVersion) >= parse_version("2.11"): + # TODO: the CalCatFriend could add these for us + # note: overly complicated for closure to work + def make_wrapper_capturing_constant(constant): + def aux(): + self.calcat_friend.get_specific_constant_version_and_call_me_back( + constant, self._load_constant_to_runner + ) + + return aux + + for constant in self._constant_enum_class: + slot_name = f"foundConstants.{constant.name}.overrideConstantVersion" + meth_name = slot_name.replace(".", "_") + self.KARABO_SLOT( + make_wrapper_capturing_constant(constant), + slotName=meth_name, + ) + + self.KARABO_SLOT(self.loadMostRecentConstants) + self.KARABO_SLOT(self.requestScene) + 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" ) @@ -634,31 +659,11 @@ class BaseCorrection(PythonDevice): 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 - # note: overly complicated for closure to work - def make_wrapper_capturing_constant(constant): - def aux(): - self.calcat_friend.get_specific_constant_version_and_call_me_back( - constant, self._load_constant_to_runner - ) - - return aux - - for constant in self._constant_enum_class: - slot_name = f"foundConstants.{constant.name}.overrideConstantVersion" - meth_name = slot_name.replace(".", "_") - self.KARABO_SLOT( - make_wrapper_capturing_constant(constant), - slotName=meth_name, - ) - - self.KARABO_SLOT(self.loadMostRecentConstants) - self.KARABO_SLOT(self.requestScene) self.updateState(State.ON) def __del__(self): del self._shmem_buffer + super().__del__() def preReconfigure(self, config): for ts_path in ( -- GitLab