Skip to content

Commit e3cf42d

Browse files
authored
Tolerate very slightly non-square pixels (#123)
If pixel X and Y dimensions are different but within a 1e-4 relative tolerance, issue a warning and use the X dimension when stitching and writing output file metadata. Dimensions outside of that tolerance will still raise an exception. Fixes #122
1 parent 46b0d41 commit e3cf42d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ashlar/reg.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,15 @@ def pixel_size(self):
290290
else:
291291
value = v_units.value(UNITS.MICROMETER).doubleValue()
292292
values.append(value)
293+
values = tuple(values)
294+
if not np.isclose(values[0], values[1], rtol=1e-4, atol=0):
295+
raise Exception(f"Can't handle non-square pixels {values[::-1]}")
293296
if values[0] != values[1]:
294-
raise Exception("Can't handle non-square pixels (%f, %f)"
295-
% tuple(values))
296-
return values[0]
297+
warn_data(
298+
f"Pixel size is slightly non-square {values[::-1]}. Using"
299+
f" {values[1]} for both dimensions."
300+
)
301+
return values[1]
297302

298303
@property
299304
def pixel_dtype(self):

0 commit comments

Comments
 (0)