Skip to content

Commit 03372c3

Browse files
committed
TST: add test for fix in PR 500
Orientations calculation did not take into account what would happen with not-square matrices, 500 fixes this. These are some tests for fixed behavior.
1 parent 6104bd1 commit 03372c3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

nibabel/tests/test_orientations.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
flip_axis, apply_orientation, OrientationError,
1919
ornt2axcodes, axcodes2ornt, aff2axcodes)
2020

21-
from ..affines import from_matvec
21+
from ..affines import from_matvec, to_matvec
2222

2323

2424
IN_ARRS = [np.eye(4),
@@ -188,8 +188,8 @@ def test_io_orientation():
188188
[1, 1],
189189
[2, 1]])
190190
eps = np.finfo(float).eps
191-
# Test that a Y axis appears as we increase the difference between the first
192-
# two columns
191+
# Test that a Y axis appears as we increase the difference between the
192+
# first two columns
193193
for y_val, has_y in ((0, False),
194194
(eps, False),
195195
(eps * 5, False),
@@ -203,6 +203,23 @@ def test_io_orientation():
203203
assert_array_equal(io_orientation(def_aff, tol=0), pass_tol)
204204
def_aff[1, 1] = eps * 10
205205
assert_array_equal(io_orientation(def_aff, tol=1e-5), fail_tol)
206+
# Test drop of rows, columns
207+
mat, vec = to_matvec(def_aff)
208+
aff_extra_col = np.zeros((4, 5))
209+
aff_extra_col[:3, :3] = mat
210+
aff_extra_col[:3, -1] = vec
211+
assert_array_equal(io_orientation(aff_extra_col, tol=1e-5),
212+
[[0, 1],
213+
[np.nan, np.nan],
214+
[2, 1],
215+
[np.nan, np.nan]])
216+
aff_extra_row = np.zeros((5, 4))
217+
aff_extra_row[:3, :3] = mat
218+
aff_extra_row[:3, -1] = vec
219+
assert_array_equal(io_orientation(aff_extra_row, tol=1e-5),
220+
[[0, 1],
221+
[np.nan, np.nan],
222+
[2, 1]])
206223

207224

208225
def test_ornt_transform():

0 commit comments

Comments
 (0)