Skip to content

Commit

Permalink
Merge pull request #81 from TonnC/bugfix/fix-E57Exception-ErrorValueO…
Browse files Browse the repository at this point in the history
…fBounds-when-writing-with-rowIndex-or-columnIndex

Added fix and test for write_scan_raw with omited low values for rowIndex or columnIndex
  • Loading branch information
dancergraham authored Nov 30, 2024
2 parents 5ea1c0d + 7f93505 commit d2f9831
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pye57/e57.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d2f9831

Please sign in to comment.