From 4fe97baf1fa4db49ed40ad324950003ef67284e4 Mon Sep 17 00:00:00 2001 From: David Hammer <dhammer@mailbox.org> Date: Mon, 11 Oct 2021 11:00:06 +0200 Subject: [PATCH] Adapt to dynamic manager --- src/calng/AgipdCorrection.py | 30 +++++++++++++++++++++++++----- src/calng/CalibrationManager.py | 6 ++---- src/calng/DsscCorrection.py | 20 +++++++++++++++----- src/calng/base_correction.py | 22 ++++++++++++++++------ src/calng/calcat_utils.py | 26 ++++++++++++++++++++------ src/tests/test_calcat_utils.py | 12 +++++++++--- 6 files changed, 87 insertions(+), 29 deletions(-) diff --git a/src/calng/AgipdCorrection.py b/src/calng/AgipdCorrection.py index 548f00f2..14429564 100644 --- a/src/calng/AgipdCorrection.py +++ b/src/calng/AgipdCorrection.py @@ -7,6 +7,7 @@ from karabo.bound import ( KARABO_CLASSINFO, NODE_ELEMENT, STRING_ELEMENT, + VECTOR_STRING_ELEMENT, ImageData, ) from karabo.common.states import State @@ -32,6 +33,7 @@ class AgipdCorrection(BaseCorrection): _gpu_runner_class = AgipdGpuRunner _calcat_friend_class = AgipdCalcatFriend _constant_enum_class = AgipdConstants + _managed_keys = BaseCorrection._managed_keys[:] # this is just extending (not mandatory) _schema_cache_fields = BaseCorrection._schema_cache_fields | {"sendGainMap"} @@ -56,9 +58,14 @@ class AgipdCorrection(BaseCorrection): .reconfigurable() .commit(), ) - AgipdCalcatFriend.add_schema(expected) + AgipdCorrection._managed_keys.append("sendGainMap") + AgipdCalcatFriend.add_schema(expected, AgipdCorrection._managed_keys) # this is not automatically done by superclass for complicated class reasons - add_correction_step_schema(expected, AgipdCorrection._correction_field_names) + add_correction_step_schema( + expected, + AgipdCorrection._managed_keys, + AgipdCorrection._correction_field_names, + ) # additional settings specific to AGIPD correction steps ( @@ -125,6 +132,10 @@ class AgipdCorrection(BaseCorrection): .displayedName("Bad pixel flags to use") .commit(), ) + AgipdCorrection._managed_keys.append("corrections.relGainPc.overrideMdAdditionalOffset") + AgipdCorrection._managed_keys.append("corrections.relGainPc.mdAdditionalOffset") + AgipdCorrection._managed_keys.append("corrections.relGainXray.gGainValue") + AgipdCorrection._managed_keys.append("corrections.badPixels.maskingValue") # TODO: DRY / encapsulate for field in BadPixelValues: ( @@ -135,6 +146,14 @@ class AgipdCorrection(BaseCorrection): .reconfigurable() .commit() ) + AgipdCorrection._managed_keys.append(f"corrections.badPixels.subsetToUse.{field.name}") + ( + VECTOR_STRING_ELEMENT(expected) + .key("managedKeys") + .assignmentOptional() + .defaultValue(AgipdCorrection._managed_keys) + .commit() + ) @property def input_data_shape(self): @@ -319,9 +338,8 @@ class AgipdCorrection(BaseCorrection): # switch relevant correction on if it just now became available if not self.get(f"corrections.{field_name}.available"): + # TODO: turn off again when flushing self.set(f"corrections.{field_name}.available", True) - self.set(f"corrections.{field_name}.enable", True) - self.set(f"corrections.{field_name}.preview", True) self._update_correction_flags() @@ -366,7 +384,9 @@ class AgipdCorrection(BaseCorrection): self._override_md_additional_offset = None self.gpu_runner.set_g_gain_value(self.get("corrections.relGainXray.gGainValue")) - self._gpu_runner_init_args["g_gain_value"] = self.get("corrections.relGainXray.gGainValue") + self._gpu_runner_init_args["g_gain_value"] = self.get( + "corrections.relGainXray.gGainValue" + ) self.bad_pixel_mask_value = eval(self.get("corrections.badPixels.maskingValue")) self.gpu_runner.set_bad_pixel_mask_value(self.bad_pixel_mask_value) diff --git a/src/calng/CalibrationManager.py b/src/calng/CalibrationManager.py index 39ae1482..c4a80d50 100644 --- a/src/calng/CalibrationManager.py +++ b/src/calng/CalibrationManager.py @@ -1062,10 +1062,8 @@ class CalibrationManager(DeviceClientBase, Device): config = Hash() - # Legacy keys for calibrationBase. - config['det_type'] = self.detectorType - config['det_identifier'] = self.detectorIdentifier - config['da_name'] = aggregator + config['constantParameters.detectorName'] = self.detectorIdentifier.value + config['constantParameters.karaboDa'] = aggregator config['dataInput.connectedOutputChannels'] = [input_channel] config['fastSources'] = [input_source] diff --git a/src/calng/DsscCorrection.py b/src/calng/DsscCorrection.py index 5dd32976..349e5414 100644 --- a/src/calng/DsscCorrection.py +++ b/src/calng/DsscCorrection.py @@ -1,7 +1,7 @@ import timeit import numpy as np -from karabo.bound import KARABO_CLASSINFO +from karabo.bound import KARABO_CLASSINFO, VECTOR_STRING_ELEMENT from karabo.common.states import State from . import utils @@ -19,13 +19,25 @@ class DsscCorrection(BaseCorrection): _gpu_runner_class = DsscGpuRunner _calcat_friend_class = DsscCalcatFriend _constant_enum_class = DsscConstants + _managed_keys = BaseCorrection._managed_keys[:] @staticmethod def expectedParameters(expected): super(DsscCorrection, DsscCorrection).expectedParameters(expected) expected.setDefaultValue("dataFormat.memoryCells", 400) - DsscCalcatFriend.add_schema(expected) - add_correction_step_schema(expected, DsscCorrection._correction_field_names) + DsscCalcatFriend.add_schema(expected, DsscCorrection._managed_keys) + add_correction_step_schema( + expected, + DsscCorrection._managed_keys, + DsscCorrection._correction_field_names, + ) + ( + VECTOR_STRING_ELEMENT(expected) + .key("managedKeys") + .assignmentOptional() + .defaultValue(DsscCorrection._managed_keys) + .commit() + ) @property def input_data_shape(self): @@ -168,7 +180,5 @@ class DsscCorrection(BaseCorrection): self.gpu_runner.load_offset_map(constant_data) if not self.get("corrections.offset.available"): self.set("corrections.offset.available", True) - self.set("corrections.offset.enable", True) - self.set("corrections.offset.preview", True) self._update_correction_flags() diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py index 68573a3e..82022c15 100644 --- a/src/calng/base_correction.py +++ b/src/calng/base_correction.py @@ -44,6 +44,15 @@ class BaseCorrection(PythonDevice): _correction_flag_class = None # subclass must override this with some enum class _gpu_runner_class = None # subclass must set this _gpu_runner_init_args = {} # subclass can set this (TODO: remove, design better) + _managed_keys = [ + "outputShmemBufferSize", + "dataFormat.outputImageDtype", + "preview.enable", + "preview.pulse", + "preview.trainIdModulo", + "corrections.disableAll", + "loadMostRecentConstants", + ] # subclass must extend this and put it in schema _schema_cache_fields = { "doAnything", "dataFormat.memoryCells", @@ -602,7 +611,7 @@ class BaseCorrection(PythonDevice): self.signalEndOfStream("dataOutput") -def add_correction_step_schema(schema, field_flag_mapping): +def add_correction_step_schema(schema, managed_keys, field_flag_mapping): for field_name, _ in field_flag_mapping: node_name = f"corrections.{field_name}" ( @@ -623,11 +632,10 @@ def add_correction_step_schema(schema, field_flag_mapping): .displayedName("Enable") .description( "Controls whether to apply this correction step for main data " - "output - subject to availability. When constants are first loaded " - "and availability toggles on, this, too, will toggle on by default." + "output - subject to availability." ) .assignmentOptional() - .defaultValue(False) + .defaultValue(True) .reconfigurable() .commit(), BOOL_ELEMENT(schema) @@ -635,10 +643,12 @@ def add_correction_step_schema(schema, field_flag_mapping): .displayedName("Preview") .description( "Whether to apply this correction step for corrected preview " - "output. Notes in description of 'Enable' apply here, too." + "output - subject to availability." ) .assignmentOptional() - .defaultValue(False) + .defaultValue(True) .reconfigurable() .commit(), ) + managed_keys.append(f"{node_name}.enable") + managed_keys.append(f"{node_name}.preview") diff --git a/src/calng/calcat_utils.py b/src/calng/calcat_utils.py index 3d1a2dc5..f7453ff3 100644 --- a/src/calng/calcat_utils.py +++ b/src/calng/calcat_utils.py @@ -108,7 +108,7 @@ def _add_status_schema_from_enum(schema, prefix, enum_class): SLOT_ELEMENT(schema) .key(f"{constant_node}.overrideConstantVersion") .displayedName("Override constant version") - .commit() + .commit(), ) @@ -147,6 +147,7 @@ class BaseCalcatFriend: @staticmethod def add_schema( schema, + managed_keys, detector_type, param_prefix="constantParameters", status_prefix="foundConstants", @@ -214,7 +215,7 @@ class BaseCalcatFriend: UINT32_ELEMENT(schema) .key(f"{param_prefix}.pixelsY") .assignmentOptional() - .defaultValue(512) + .defaultValue(128) .commit(), DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.biasVoltage") @@ -223,6 +224,10 @@ class BaseCalcatFriend: .reconfigurable() .commit(), ) + managed_keys.append(f"{param_prefix}.memoryCells") + managed_keys.append(f"{param_prefix}.pixelsX") + managed_keys.append(f"{param_prefix}.pixelsY") + managed_keys.append(f"{param_prefix}.biasVoltage") def __init__( self, @@ -467,10 +472,13 @@ class AgipdCalcatFriend(BaseCalcatFriend): @staticmethod def add_schema( - schema, param_prefix="constantParameters", status_prefix="foundConstants" + schema, + managed_keys, + param_prefix="constantParameters", + status_prefix="foundConstants", ): super(AgipdCalcatFriend, AgipdCalcatFriend).add_schema( - schema, "AGIPD-Type", param_prefix, status_prefix + schema, managed_keys, "AGIPD-Type", param_prefix, status_prefix ) schema.setDefaultValue(f"{param_prefix}.memoryCells", 352) @@ -506,6 +514,9 @@ class AgipdCalcatFriend(BaseCalcatFriend): .reconfigurable() .commit(), ) + managed_keys.append(f"{param_prefix}.acquisitionRate") + managed_keys.append(f"{param_prefix}.gainSetting") + managed_keys.append(f"{param_prefix}.photonEnergy") _add_status_schema_from_enum(schema, status_prefix, AgipdConstants) @@ -545,10 +556,13 @@ class DsscCalcatFriend(BaseCalcatFriend): @staticmethod def add_schema( - schema, param_prefix="constantParameters", status_prefix="foundConstants" + schema, + managed_keys, + param_prefix="constantParameters", + status_prefix="foundConstants", ): super(DsscCalcatFriend, DsscCalcatFriend).add_schema( - schema, "DSSC-Type", param_prefix, status_prefix + schema, managed_keys, "DSSC-Type", param_prefix, status_prefix ) schema.setDefaultValue(f"{param_prefix}.memoryCells", 400) ( diff --git a/src/tests/test_calcat_utils.py b/src/tests/test_calcat_utils.py index 61beb37b..5c465702 100644 --- a/src/tests/test_calcat_utils.py +++ b/src/tests/test_calcat_utils.py @@ -35,10 +35,13 @@ class Stopwatch: # TODO: consider testing by attaching to real karabo.bound.PythonDevice class DummyAgipdDevice: device_class_schema = Schema() + managed_keys = [] @staticmethod def expectedParameters(expected): - calcat_utils.AgipdCalcatFriend.add_schema(expected, "constantParameters") + calcat_utils.AgipdCalcatFriend.add_schema( + expected, DummyAgipdDevice.managed_keys + ) def __init__(self, config): self.log = DummyLogger() @@ -47,6 +50,7 @@ class DummyAgipdDevice: self, _test_calcat_secrets_fn, ) + print(self.managed_keys) def get(self, key): return self.schema.get(key) @@ -56,15 +60,17 @@ class DummyAgipdDevice: DummyAgipdDevice.expectedParameters(DummyAgipdDevice.device_class_schema) - +print(DummyAgipdDevice.device_class_schema) +print(DummyAgipdDevice.managed_keys) class DummyDsscDevice: device_class_schema = Schema() + managed_keys = [] @staticmethod def expectedParameters(expected): # super(DummyDsscDevice, DummyDsscDevice).expectedParameters(expected) - calcat_utils.DsscCalcatFriend.add_schema(expected) + calcat_utils.DsscCalcatFriend.add_schema(expected, DummyDsscDevice.managed_keys) def __init__(self, config): self.log = DummyLogger() -- GitLab