Skip to content

Commit 4f36bc7

Browse files
committed
test: Add regression test for rotated data
1 parent 5203368 commit 4f36bc7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

nibabel/tests/test_viewers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,35 @@ def test_viewer():
102102
v2.link_to(v1) # shouldn't do anything
103103
v1.close()
104104
v2.close()
105+
106+
107+
@needs_mpl
108+
def test_viewer_nonRAS():
109+
data1 = np.random.rand(10, 20, 40)
110+
data1[5, 10, :] = 0
111+
data1[5, :, 30] = 0
112+
data1[:, 10, 30] = 0
113+
# RSA affine
114+
aff1 = np.array([[1, 0, 0, -5], [0, 0, 1, -30], [0, 1, 0, -10], [0, 0, 0, 1]])
115+
o1 = OrthoSlicer3D(data1, aff1)
116+
sag = o1._ims[0].get_array()
117+
cor = o1._ims[1].get_array()
118+
axi = o1._ims[2].get_array()
119+
120+
# Sagittal view: [0, I->S, P->A], so data is transposed, matching plot array
121+
assert_array_equal(sag, data1[5, :, :])
122+
# Coronal view: [L->R, I->S, 0]. Data is not transposed, transpose to match plot array
123+
assert_array_equal(cor, data1[:, :, 30].T)
124+
# Axial view: [L->R, 0, P->A]. Data is not transposed, transpose to match plot array
125+
assert_array_equal(axi, data1[:, 10, :].T)
126+
127+
o1.set_position(1, 2, 3) # R, A, S coordinates
128+
129+
sag = o1._ims[0].get_array()
130+
cor = o1._ims[1].get_array()
131+
axi = o1._ims[2].get_array()
132+
133+
# Shift 1 right, 2 anterior, 3 superior
134+
assert_array_equal(sag, data1[6, :, :])
135+
assert_array_equal(cor, data1[:, :, 32].T)
136+
assert_array_equal(axi, data1[:, 13, :].T)

0 commit comments

Comments
 (0)