From c2c94c7ef729261a4002c6ec9c35f797a4b1bea4 Mon Sep 17 00:00:00 2001 From: Christian Tonn Date: Fri, 29 Nov 2024 08:46:55 +0100 Subject: [PATCH 1/3] added fix and test for write_scan_raw with omited low values --- src/pye57/e57.py | 4 ++-- tests/test_main.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pye57/e57.py b/src/pye57/e57.py index 4c7205a..e02039f 100644 --- a/src/pye57/e57.py +++ b/src/pye57/e57.py @@ -376,9 +376,9 @@ def write_scan_raw(self, data: Dict, *, name=None, rotation=None, translation=No max_row = np.max(data["rowIndex"]) min_col = np.min(data["columnIndex"]) max_col = np.max(data["columnIndex"]) - points_prototype.set("rowIndex", libe57.IntegerNode(self.image_file, 0, min_row, max_row)) + points_prototype.set("rowIndex", libe57.IntegerNode(self.image_file, min_row, min_row, max_row)) field_names.append("rowIndex") - points_prototype.set("columnIndex", libe57.IntegerNode(self.image_file, 0, min_col, max_col)) + points_prototype.set("columnIndex", libe57.IntegerNode(self.image_file, min_col, min_col, max_col)) field_names.append("columnIndex") if "cartesianInvalidState" in data: diff --git a/tests/test_main.py b/tests/test_main.py index 0a7aeaa..9b4dd53 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -419,3 +419,27 @@ def test_clone_e57(e57_with_data_and_images_path, temp_e57_write): in_image.close() out_image.close() + + +def test_write_e57_with_rowindex_and_columnindex_omiting_low_values(): + + test_file_path = 'temporary_output_cloud.e57' + with pye57.E57(test_file_path, mode='w') as e57: + # set some test points with missing row and column 0 (so np.min of it in write_scan_raw is larger than 0) + data_raw = {} + data_raw["cartesianX"] = np.array([0, 1, 2, 3]).astype(float) + data_raw["cartesianY"] = np.array([0, 1, 2, 3]).astype(float) + data_raw["cartesianZ"] = np.array([0, 1, 2, 3]).astype(float) + data_raw["rowIndex"] = np.array([1, 1, 2, 3]).astype(int) + data_raw["columnIndex"] = np.array([1, 1, 2, 3]).astype(int) + + try: + # the next line will throw without the suggested fix + e57.write_scan_raw(data_raw, name='test_output_with_row_and_column') + except pye57.libe57.E57Exception as ex: + print(ex) + assert False + + assert os.path.isfile(test_file_path) + os.remove(test_file_path) + assert not os.path.isfile(test_file_path) From 67accd2d3863b3ff38a7a2a0d427266e95d6add7 Mon Sep 17 00:00:00 2001 From: Christian Tonn Date: Sat, 30 Nov 2024 15:18:06 +0100 Subject: [PATCH 2/3] refactor test to use existing fixture temp_e57_write --- tests/test_main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 9b4dd53..924fe9b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -421,10 +421,9 @@ def test_clone_e57(e57_with_data_and_images_path, temp_e57_write): out_image.close() -def test_write_e57_with_rowindex_and_columnindex_omiting_low_values(): +def test_write_e57_with_rowindex_and_columnindex_omiting_low_values(temp_e57_write): - test_file_path = 'temporary_output_cloud.e57' - with pye57.E57(test_file_path, mode='w') as e57: + with pye57.E57(temp_e57_write, mode='w') as e57: # set some test points with missing row and column 0 (so np.min of it in write_scan_raw is larger than 0) data_raw = {} data_raw["cartesianX"] = np.array([0, 1, 2, 3]).astype(float) @@ -440,6 +439,4 @@ def test_write_e57_with_rowindex_and_columnindex_omiting_low_values(): print(ex) assert False - assert os.path.isfile(test_file_path) - os.remove(test_file_path) - assert not os.path.isfile(test_file_path) + assert os.path.isfile(temp_e57_write) From 7f935055aa4ab16526c2cd1f29d7085fc398ea23 Mon Sep 17 00:00:00 2001 From: Christian Tonn Date: Sat, 30 Nov 2024 15:26:02 +0100 Subject: [PATCH 3/3] omitted some not necessary astype conversion in test --- tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 924fe9b..05da420 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -429,8 +429,8 @@ def test_write_e57_with_rowindex_and_columnindex_omiting_low_values(temp_e57_wri data_raw["cartesianX"] = np.array([0, 1, 2, 3]).astype(float) data_raw["cartesianY"] = np.array([0, 1, 2, 3]).astype(float) data_raw["cartesianZ"] = np.array([0, 1, 2, 3]).astype(float) - data_raw["rowIndex"] = np.array([1, 1, 2, 3]).astype(int) - data_raw["columnIndex"] = np.array([1, 1, 2, 3]).astype(int) + data_raw["rowIndex"] = np.array([1, 1, 2, 3]) + data_raw["columnIndex"] = np.array([1, 1, 2, 3]) try: # the next line will throw without the suggested fix