Skip to content

Commit 1d27aef

Browse files
Merge pull request #502 from matthew-brett/test-500
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.
2 parents c1269c0 + c20841b commit 1d27aef

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

nibabel/tests/test_orientations.py

Lines changed: 22 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,25 @@ 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[-1, -1] = 1 # Not strictly necessary, but for completeness
210+
aff_extra_col[:3, :3] = mat
211+
aff_extra_col[:3, -1] = vec
212+
assert_array_equal(io_orientation(aff_extra_col, tol=1e-5),
213+
[[0, 1],
214+
[np.nan, np.nan],
215+
[2, 1],
216+
[np.nan, np.nan]])
217+
aff_extra_row = np.zeros((5, 4))
218+
aff_extra_row[-1, -1] = 1 # Not strictly necessary, but for completeness
219+
aff_extra_row[:3, :3] = mat
220+
aff_extra_row[:3, -1] = vec
221+
assert_array_equal(io_orientation(aff_extra_row, tol=1e-5),
222+
[[0, 1],
223+
[np.nan, np.nan],
224+
[2, 1]])
206225

207226

208227
def test_ornt_transform():

0 commit comments

Comments
 (0)