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..05da420 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -419,3 +419,24 @@ 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(temp_e57_write): + + 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) + 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]) + data_raw["columnIndex"] = np.array([1, 1, 2, 3]) + + 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(temp_e57_write)