From ea33a21ec08a9441fb0cf9243d9cd22da245f47f Mon Sep 17 00:00:00 2001 From: David Hammer <dhammer@mailbox.org> Date: Wed, 1 Dec 2021 09:42:41 +0100 Subject: [PATCH] Reformatting bound schema definitions --- src/calng/AgipdCorrection.py | 19 ++++++------ src/calng/DsscCorrection.py | 2 ++ src/calng/ModuleStacker.py | 8 +++-- src/calng/base_correction.py | 57 ++++++++++++++++++++++++++++++++++++ src/calng/calcat_utils.py | 18 ++++++++++++ 5 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/calng/AgipdCorrection.py b/src/calng/AgipdCorrection.py index d0e46321..b4a6d22d 100644 --- a/src/calng/AgipdCorrection.py +++ b/src/calng/AgipdCorrection.py @@ -354,24 +354,28 @@ class AgipdCalcatFriend(calcat_utils.BaseCalcatFriend): .defaultValue(1.1) .reconfigurable() .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.gainSetting") .assignmentOptional() .defaultValue(0) .reconfigurable() .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.photonEnergy") .assignmentOptional() .defaultValue(9.2) .reconfigurable() .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.gainMode") .assignmentOptional() .defaultValue(0) .reconfigurable() .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.integrationTime") .assignmentOptional() @@ -435,6 +439,7 @@ class AgipdCorrection(BaseCorrection): super(AgipdCorrection, AgipdCorrection).expectedParameters(expected) expected.setDefaultValue("dataFormat.memoryCells", 352) expected.setDefaultValue("preview.selectionMode", "cell") + # WIP: fixed gain mode ( STRING_ELEMENT(expected) .key("gainMode") @@ -445,20 +450,12 @@ class AgipdCorrection(BaseCorrection): .commit(), ) - ( - STRING_ELEMENT(expected) - .key("dataOutput.schema.image.gainMap") - .displayedName("Gain map (optional)") - .assignmentOptional() - .defaultValue("") - .commit() - ) - ( OUTPUT_CHANNEL(expected) .key("preview.outputRawGain") .dataSchema(preview_schema) .commit(), + OUTPUT_CHANNEL(expected) .key("preview.outputGainMap") .dataSchema(preview_schema) @@ -488,6 +485,7 @@ class AgipdCorrection(BaseCorrection): .defaultValue(False) .reconfigurable() .commit(), + FLOAT_ELEMENT(expected) .key("corrections.relGainPc.mdAdditionalOffset") .displayedName("Value for md_additional_offset (if overriding)") @@ -501,6 +499,7 @@ class AgipdCorrection(BaseCorrection): .defaultValue(0) .reconfigurable() .commit(), + FLOAT_ELEMENT(expected) .key("corrections.relGainXray.gGainValue") .displayedName("G_gain_value") @@ -515,6 +514,7 @@ class AgipdCorrection(BaseCorrection): .defaultValue(1) .reconfigurable() .commit(), + STRING_ELEMENT(expected) .key("corrections.badPixels.maskingValue") .displayedName("Bad pixel masking value") @@ -527,6 +527,7 @@ class AgipdCorrection(BaseCorrection): .defaultValue("float('nan')") .reconfigurable() .commit(), + NODE_ELEMENT(expected) .key("corrections.badPixels.subsetToUse") .displayedName("Bad pixel flags to use") diff --git a/src/calng/DsscCorrection.py b/src/calng/DsscCorrection.py index 8c586b3d..9543268e 100644 --- a/src/calng/DsscCorrection.py +++ b/src/calng/DsscCorrection.py @@ -121,11 +121,13 @@ class DsscCalcatFriend(calcat_utils.BaseCalcatFriend): .assignmentOptional() .defaultValue(2.8866323107820637e-36) .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.acquisitionRate") .assignmentOptional() .defaultValue(4.5) .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.encodedGain") .assignmentOptional() diff --git a/src/calng/ModuleStacker.py b/src/calng/ModuleStacker.py index 3490a705..6a3a48ca 100644 --- a/src/calng/ModuleStacker.py +++ b/src/calng/ModuleStacker.py @@ -45,6 +45,7 @@ class ModuleStacker(TrainMatcher.TrainMatcher): .metricPrefix(MetricPrefix.MILLI) .readOnly() .commit(), + STRING_ELEMENT(expected) .key("pathToStack") .displayedName("Data path to stack") @@ -79,8 +80,11 @@ class ModuleStacker(TrainMatcher.TrainMatcher): "These nodes are not used." ) schema = Schema() - NODE_ELEMENT(schema).key("start").description(desc).commit() - NODE_ELEMENT(schema).key("stop").description(desc).commit() + ( + NODE_ELEMENT(schema).key("start").description(desc).commit(), + + NODE_ELEMENT(schema).key("stop").description(desc).commit(), + ) self.path_to_stack = self.get("pathToStack") self.updateSchema(schema) diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py index 7e238664..bcd9db80 100644 --- a/src/calng/base_correction.py +++ b/src/calng/base_correction.py @@ -43,7 +43,9 @@ PROCESSING_STATE_TIMEOUT = 10 preview_schema = Schema() ( NODE_ELEMENT(preview_schema).key("image").commit(), + NDARRAY_ELEMENT(preview_schema).key("image.data").dtype("FLOAT").commit(), + UINT64_ELEMENT(preview_schema) .key("image.trainId") .displayedName("Train ID") @@ -57,81 +59,109 @@ preview_schema = Schema() output_schema = Schema() ( NODE_ELEMENT(output_schema).key("image").commit(), + STRING_ELEMENT(output_schema) .key("image.data") .assignmentOptional() .defaultValue("") .commit(), + NDARRAY_ELEMENT(output_schema).key("image.length").dtype("UINT32").commit(), + NDARRAY_ELEMENT(output_schema).key("image.cellId").dtype("UINT16").commit(), + NDARRAY_ELEMENT(output_schema).key("image.pulseId").dtype("UINT64").commit(), + NDARRAY_ELEMENT(output_schema).key("image.status").commit(), + NDARRAY_ELEMENT(output_schema).key("image.trainId").dtype("UINT64").commit(), + VECTOR_STRING_ELEMENT(output_schema) .key("calngShmemPaths") .assignmentOptional() .defaultValue(["image.data"]) .commit(), + NODE_ELEMENT(output_schema).key("metadata").commit(), + STRING_ELEMENT(output_schema) .key("metadata.source") .assignmentOptional() .defaultValue("") .commit(), + NODE_ELEMENT(output_schema).key("metadata.timestamp").commit(), + INT32_ELEMENT(output_schema) .key("metadata.timestamp.tid") .assignmentOptional() .defaultValue(0) .commit(), + NODE_ELEMENT(output_schema).key("header").commit(), + INT32_ELEMENT(output_schema) .key("header.minorTrainFormatVersion") .assignmentOptional() .defaultValue(0) .commit(), + INT32_ELEMENT(output_schema) .key("header.majorTrainFormatVersion") .assignmentOptional() .defaultValue(0) .commit(), + INT32_ELEMENT(output_schema) .key("header.trainId") .assignmentOptional() .defaultValue(0) .commit(), + INT64_ELEMENT(output_schema) .key("header.linkId") .assignmentOptional() .defaultValue(0) .commit(), + INT64_ELEMENT(output_schema) .key("header.dataId") .assignmentOptional() .defaultValue(0) .commit(), + INT64_ELEMENT(output_schema) .key("header.pulseCount") .assignmentOptional() .defaultValue(0) .commit(), + NDARRAY_ELEMENT(output_schema).key("header.reserved").commit(), + NDARRAY_ELEMENT(output_schema).key("header.magicNumberBegin").commit(), + NODE_ELEMENT(output_schema).key("detector").commit(), + INT32_ELEMENT(output_schema) .key("detector.trainId") .assignmentOptional() .defaultValue(0) .commit(), + NDARRAY_ELEMENT(output_schema).key("detector.data").commit(), + NODE_ELEMENT(output_schema).key("trailer").commit(), + NDARRAY_ELEMENT(output_schema).key("trailer.checksum").commit(), + NDARRAY_ELEMENT(output_schema).key("trailer.magicNumberEnd").commit(), + INT32_ELEMENT(output_schema) .key("trailer.status") .assignmentOptional() .defaultValue(0) .commit(), + INT32_ELEMENT(output_schema) .key("trailer.trainId") .assignmentOptional() @@ -218,10 +248,12 @@ class BaseCorrection(PythonDevice): def expectedParameters(expected): ( INPUT_CHANNEL(expected).key("dataInput").commit(), + OUTPUT_CHANNEL(expected) .key("dataOutput") .dataSchema(output_schema) .commit(), + VECTOR_STRING_ELEMENT(expected) .key("fastSources") .displayedName("Fast data sources") @@ -233,6 +265,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue([]) .commit(), + STRING_ELEMENT(expected) .key("frameFilter") .displayedName("Frame filter") @@ -249,6 +282,7 @@ class BaseCorrection(PythonDevice): .defaultValue("") .reconfigurable() .commit(), + UINT32_ELEMENT(expected) .key("outputShmemBufferSize") .displayedName("Output buffer size limit") @@ -262,6 +296,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue(10) .commit(), + VECTOR_STRING_ELEMENT(expected) .key("availableScenes") .setSpecialDisplayType(DT_SCENES) @@ -275,6 +310,7 @@ class BaseCorrection(PythonDevice): .key("dataFormat") .displayedName("Data format (in/out)") .commit(), + BOOL_ELEMENT(expected) .key("dataFormat.overrideInputAxisOrder") .displayedName("Override input axis order") @@ -289,6 +325,7 @@ class BaseCorrection(PythonDevice): .defaultValue(True) .reconfigurable() .commit(), + STRING_ELEMENT(expected) .key("dataFormat.inputImageDtype") .displayedName("Input image data dtype") @@ -297,6 +334,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue("uint16") .commit(), + STRING_ELEMENT(expected) .key("dataFormat.outputImageDtype") .displayedName("Output image data dtype") @@ -311,6 +349,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue("float32") .commit(), + # important: determines shape of data as going into correction UINT32_ELEMENT(expected) .key("dataFormat.pixelsX") @@ -319,6 +358,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue(512) .commit(), + UINT32_ELEMENT(expected) .key("dataFormat.pixelsY") .displayedName("Pixels y") @@ -326,6 +366,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue(128) .commit(), + UINT32_ELEMENT(expected) .key("dataFormat.memoryCells") .displayedName("Memory cells") @@ -333,6 +374,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .noDefaultValue() # subclass will want to set a default value .commit(), + UINT32_ELEMENT(expected) .key("dataFormat.filteredFrames") .displayedName("Frames after filter") @@ -340,6 +382,7 @@ class BaseCorrection(PythonDevice): .readOnly() .initialValue(0) .commit(), + STRING_ELEMENT(expected) .key("dataFormat.outputAxisOrder") .displayedName("Output axis order") @@ -352,6 +395,7 @@ class BaseCorrection(PythonDevice): .assignmentOptional() .defaultValue("cxy") .commit(), + VECTOR_UINT32_ELEMENT(expected) .key("dataFormat.inputDataShape") .displayedName("Input data shape") @@ -363,6 +407,7 @@ class BaseCorrection(PythonDevice): .readOnly() .initialValue([]) .commit(), + VECTOR_UINT32_ELEMENT(expected) .key("dataFormat.outputDataShape") .displayedName("Output data shape") @@ -393,14 +438,17 @@ class BaseCorrection(PythonDevice): ( NODE_ELEMENT(expected).key("preview").displayedName("Preview").commit(), + OUTPUT_CHANNEL(expected) .key("preview.outputRaw") .dataSchema(preview_schema) .commit(), + OUTPUT_CHANNEL(expected) .key("preview.outputCorrected") .dataSchema(preview_schema) .commit(), + BOOL_ELEMENT(expected) .key("preview.enable") .displayedName("Enable preview data generation") @@ -408,6 +456,7 @@ class BaseCorrection(PythonDevice): .defaultValue(True) .reconfigurable() .commit(), + INT32_ELEMENT(expected) .key("preview.index") .displayedName("Index (or stat) for preview") @@ -421,6 +470,7 @@ class BaseCorrection(PythonDevice): .defaultValue(0) .reconfigurable() .commit(), + STRING_ELEMENT(expected) .key("preview.selectionMode") .displayedName("Index selection mode") @@ -436,6 +486,7 @@ class BaseCorrection(PythonDevice): .defaultValue("frame") .reconfigurable() .commit(), + UINT32_ELEMENT(expected) .key("preview.trainIdModulo") .displayedName("Preview train stride") @@ -460,10 +511,12 @@ class BaseCorrection(PythonDevice): .readOnly() .initialValue(0) .commit(), + NODE_ELEMENT(expected) .key("performance") .displayedName("Performance measures") .commit(), + DOUBLE_ELEMENT(expected) .key("performance.processingTime") .displayedName("Processing time") @@ -475,6 +528,7 @@ class BaseCorrection(PythonDevice): .info("Processing not fast enough for full speed") .needsAcknowledging(False) .commit(), + DOUBLE_ELEMENT(expected) .key("performance.rate") .displayedName("Rate") @@ -916,6 +970,7 @@ def add_correction_step_schema(schema, managed_keys, field_flag_mapping): node_name = f"corrections.{field_name}" ( NODE_ELEMENT(schema).key(node_name).commit(), + BOOL_ELEMENT(schema) .key(f"{node_name}.available") .displayedName("Available") @@ -927,6 +982,7 @@ def add_correction_step_schema(schema, managed_keys, field_flag_mapping): .readOnly() .initialValue(False) .commit(), + BOOL_ELEMENT(schema) .key(f"{node_name}.enable") .displayedName("Enable") @@ -938,6 +994,7 @@ def add_correction_step_schema(schema, managed_keys, field_flag_mapping): .defaultValue(True) .reconfigurable() .commit(), + BOOL_ELEMENT(schema) .key(f"{node_name}.preview") .displayedName("Preview") diff --git a/src/calng/calcat_utils.py b/src/calng/calcat_utils.py index 0b9099cc..0af00de4 100644 --- a/src/calng/calcat_utils.py +++ b/src/calng/calcat_utils.py @@ -54,31 +54,37 @@ def add_status_schema_from_enum(schema, prefix, enum_class): constant_node = f"{prefix}.{constant.name}" ( NODE_ELEMENT(schema).key(constant_node).commit(), + BOOL_ELEMENT(schema) .key(f"{constant_node}.found") .readOnly() .initialValue(False) .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.validFrom") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.calibrationId") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.conditionId") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.constantId") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.constantVersionId") .description( @@ -165,6 +171,7 @@ class BaseCalcatFriend: .key(param_prefix) .displayedName("Constant retrieval parameters") .commit(), + NODE_ELEMENT(schema) .key(status_prefix) .displayedName("Constants retrieved") @@ -189,6 +196,7 @@ class BaseCalcatFriend: .defaultValue("") .reconfigurable() .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.constantVersionEventAt") .displayedName("Event at timestamp (for constant version)") @@ -197,6 +205,7 @@ class BaseCalcatFriend: .defaultValue("") .reconfigurable() .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.detectorType") .displayedName("Detector type name") @@ -206,47 +215,56 @@ class BaseCalcatFriend: .readOnly() .initialValue(detector_type) .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.detectorTypeId") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.detectorName") .assignmentOptional() .defaultValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.detectorId") .readOnly() .initialValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.karaboDa") .assignmentOptional() .defaultValue("") .commit(), + STRING_ELEMENT(schema) .key(f"{param_prefix}.moduleId") .readOnly() .initialValue("") .commit(), + UINT32_ELEMENT(schema) .key(f"{param_prefix}.memoryCells") .assignmentOptional() .noDefaultValue() .reconfigurable() .commit(), + UINT32_ELEMENT(schema) .key(f"{param_prefix}.pixelsX") .assignmentOptional() .defaultValue(512) .commit(), + UINT32_ELEMENT(schema) .key(f"{param_prefix}.pixelsY") .assignmentOptional() .defaultValue(128) .commit(), + DOUBLE_ELEMENT(schema) .key(f"{param_prefix}.biasVoltage") .assignmentOptional() -- GitLab