From c7e2aad17a0edd0165bee26a9aca9f33b6b7e97c Mon Sep 17 00:00:00 2001 From: dwills Date: Mon, 6 Feb 2023 12:56:19 -0700 Subject: [PATCH 1/2] Fix bug preventing raw scans without optional child elements from being written --- src/pye57/e57.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/pye57/e57.py b/src/pye57/e57.py index 4c7205a..a7b3d91 100644 --- a/src/pye57/e57.py +++ b/src/pye57/e57.py @@ -231,16 +231,18 @@ def write_scan_raw(self, data: Dict, *, name=None, rotation=None, translation=No if name is None: name = getattr(scan_header, "name", "Scan %s" % len(self.data3d)) - temperature = getattr(scan_header, "temperature", 0) - relativeHumidity = getattr(scan_header, "relativeHumidity", 0) - atmosphericPressure = getattr(scan_header, "atmosphericPressure", 0) - scan_node = libe57.StructureNode(self.image_file) scan_node.set("guid", libe57.StringNode(self.image_file, "{%s}" % uuid.uuid4())) scan_node.set("name", libe57.StringNode(self.image_file, name)) - scan_node.set("temperature", libe57.FloatNode(self.image_file, temperature)) - scan_node.set("relativeHumidity", libe57.FloatNode(self.image_file, relativeHumidity)) - scan_node.set("atmosphericPressure", libe57.FloatNode(self.image_file, atmosphericPressure)) + if "temperature" in data: + temperature = scan_header.temperature + scan_node.set("temperature", libe57.FloatNode(self.image_file, temperature)) + if "relativeHumidity" in data: + relativeHumidity = scan_header.relativeHumidity + scan_node.set("relativeHumidity", libe57.FloatNode(self.image_file, relativeHumidity)) + if "atmosphericPressure" in data: + atmosphericPressure = scan_header.atmosphericPressure + scan_node.set("atmosphericPressure", libe57.FloatNode(self.image_file, atmosphericPressure)) scan_node.set("description", libe57.StringNode(self.image_file, "pye57 v%s" % __version__)) n_points = data["cartesianX"].shape[0] @@ -323,18 +325,23 @@ def write_scan_raw(self, data: Dict, *, name=None, rotation=None, translation=No translation_node.set("z", libe57.FloatNode(self.image_file, translation[2])) pose_node.set("translation", translation_node) - start_datetime = getattr(scan_header, "acquisitionStart_dateTimeValue", 0) - start_atomic = getattr(scan_header, "acquisitionStart_isAtomicClockReferenced", False) - end_datetime = getattr(scan_header, "acquisitionEnd_dateTimeValue", 0) - end_atomic = getattr(scan_header, "acquisitionEnd_isAtomicClockReferenced", False) acquisition_start = libe57.StructureNode(self.image_file) scan_node.set("acquisitionStart", acquisition_start) - acquisition_start.set("dateTimeValue", libe57.FloatNode(self.image_file, start_datetime)) - acquisition_start.set("isAtomicClockReferenced", libe57.IntegerNode(self.image_file, start_atomic)) + if "acquisitionStart_dateTimeValue" in data: + start_datetime = getattr(scan_header, "acquisitionStart_dateTimeValue", 0) + acquisition_start.set("dateTimeValue", libe57.FloatNode(self.image_file, start_datetime)) + if "acquisitionStart_isAtomicClockReferenced" in data: + start_atomic = getattr(scan_header, "acquisitionStart_isAtomicClockReferenced", False) + acquisition_start.set("isAtomicClockReferenced", libe57.IntegerNode(self.image_file, start_atomic)) + acquisition_end = libe57.StructureNode(self.image_file) scan_node.set("acquisitionEnd", acquisition_end) - acquisition_end.set("dateTimeValue", libe57.FloatNode(self.image_file, end_datetime)) - acquisition_end.set("isAtomicClockReferenced", libe57.IntegerNode(self.image_file, end_atomic)) + if "acquisitionEnd_dateTimeValue" in data: + end_datetime = getattr(scan_header, "acquisitionEnd_dateTimeValue", 0) + acquisition_end.set("dateTimeValue", libe57.FloatNode(self.image_file, end_datetime)) + if "acquistionEnd_is_AtomicClockReferenced" in data: + end_atomic = getattr(scan_header, "acquisitionEnd_isAtomicClockReferenced", False) + acquisition_end.set("isAtomicClockReferenced", libe57.IntegerNode(self.image_file, end_atomic)) # todo: pointGroupingSchemes From fda9bf3de8a12a64496341958e35ec86c0cce91e Mon Sep 17 00:00:00 2001 From: Graham Knapp <32717635+dancergraham@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:28:20 +0200 Subject: [PATCH 2/2] Add comments To explain the checks and launch the tests --- src/pye57/e57.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pye57/e57.py b/src/pye57/e57.py index a7b3d91..65adf2f 100644 --- a/src/pye57/e57.py +++ b/src/pye57/e57.py @@ -234,6 +234,7 @@ def write_scan_raw(self, data: Dict, *, name=None, rotation=None, translation=No scan_node = libe57.StructureNode(self.image_file) scan_node.set("guid", libe57.StringNode(self.image_file, "{%s}" % uuid.uuid4())) scan_node.set("name", libe57.StringNode(self.image_file, name)) + # Ignore optional fields if "temperature" in data: temperature = scan_header.temperature scan_node.set("temperature", libe57.FloatNode(self.image_file, temperature)) @@ -327,6 +328,7 @@ def write_scan_raw(self, data: Dict, *, name=None, rotation=None, translation=No acquisition_start = libe57.StructureNode(self.image_file) scan_node.set("acquisitionStart", acquisition_start) + # Ignore optional fields if "acquisitionStart_dateTimeValue" in data: start_datetime = getattr(scan_header, "acquisitionStart_dateTimeValue", 0) acquisition_start.set("dateTimeValue", libe57.FloatNode(self.image_file, start_datetime))