Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix and test for write_scan_raw with omited low values for rowIndex or columnIndex #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading