Skip to content

Commit ebd999c

Browse files
committed
TST: add tests for io_orientations thresholding
Test the SVD and allclose thresholding for io_orientations
1 parent 2d7f298 commit ebd999c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

nibabel/tests/test_orientations.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,33 @@ def test_io_orientation():
176176
[np.nan, np.nan],
177177
[np.nan, np.nan],
178178
[np.nan, np.nan]])
179+
# Test behavior of thresholding
180+
def_aff = np.array([[1., 1, 0, 0],
181+
[0, 0, 0, 0],
182+
[0, 0, 1, 0],
183+
[0, 0, 0, 1]])
184+
fail_tol = np.array([[0, 1],
185+
[np.nan, np.nan],
186+
[2, 1]])
187+
pass_tol = np.array([[0, 1],
188+
[1, 1],
189+
[2, 1]])
190+
eps = np.finfo(float).eps
191+
# Test that a Y axis appears as we increase the difference between the first
192+
# two columns
193+
for y_val, has_y in ((0, False),
194+
(eps, False),
195+
(eps * 5, False),
196+
(eps * 10, True),
197+
):
198+
def_aff[1, 1] = y_val
199+
res = pass_tol if has_y else fail_tol
200+
assert_array_equal(io_orientation(def_aff), res)
201+
# Test tol input argument
202+
def_aff[1, 1] = eps
203+
assert_array_equal(io_orientation(def_aff, tol=0), pass_tol)
204+
def_aff[1, 1] = eps * 10
205+
assert_array_equal(io_orientation(def_aff, tol=1e-5), fail_tol)
179206

180207

181208
def test_ornt2axcodes():

0 commit comments

Comments
 (0)