Skip to content

Commit

Permalink
test for BF viwers non RSA matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
gjpcbecq authored Sep 13, 2024
1 parent e1f28f3 commit 5d89d2f
Showing 1 changed file with 64 additions and 69 deletions.
133 changes: 64 additions & 69 deletions nibabel/tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,19 @@ def test_viewer_nonRAS():
assert_array_equal(axi, data1[:, 13, :].T)



@needs_mpl
def test_viewer_nonRAS_on_mouse():
"""
test on_mouse selection on non RAS matrices
"""
# This affine simulates an acquisition on a quadruped subject that is in a prone position.
# This corresponds to an acquisition with:
# This affine simulates an acquisition on a quadruped subject that is in a prone position.
# This corresponds to an acquisition with:
# - LR inverted on scanner x (i)
# - IS on scanner y (j)
# - PA on scanner z (k)
# This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.
# This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.

(I, J, K) = (10, 20, 40)
data1 = np.random.rand(I, J, K)
(i_target, j_target, k_target) = (2, 14, 12)
Expand All @@ -159,68 +158,65 @@ def test_viewer_nonRAS_on_mouse():
j2 = j_target + 3
k1 = k_target - 4
k2 = k_target + 4
data1[i1: i2 + 1, j1: j2 + 1, k1: k2 + 1] = 0
data1[i1 : i2 + 1, j1 : j2 + 1, k1 : k2 + 1] = 0
data1[i_target, j_target, k_target] = 1
valp1 = 1.5
valm1 = 0.5
data1[i_target - 1, j_target, k_target] = valp1 # x flipped
data1[i_target + 1, j_target, k_target] = valm1 # x flipped
data1[i_target - 1, j_target, k_target] = valp1 # x flipped
data1[i_target + 1, j_target, k_target] = valm1 # x flipped
data1[i_target, j_target - 1, k_target] = valm1
data1[i_target, j_target + 1, k_target] = valp1
data1[i_target, j_target, k_target - 1] = valm1
data1[i_target, j_target, k_target + 1] = valp1

Check warning on line 170 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L152-L170

Added lines #L152 - L170 were not covered by tests

aff1 = np.array([[-1, 0, 0, 5],
[0, 0, 1, -10],
[0, 1, 0, -30],
[0, 0, 0, 1]])


aff1 = np.array([[-1, 0, 0, 5], [0, 0, 1, -10], [0, 1, 0, -30], [0, 0, 0, 1]])

Check warning on line 172 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L172

Added line #L172 was not covered by tests

o1 = OrthoSlicer3D(data1, aff1)

Check warning on line 174 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L174

Added line #L174 was not covered by tests
class Event:
def __init__(self):
self.name = "simulated mouse event"

class Event:
def __init__(self):
self.name = 'simulated mouse event'
self.button = 1

Check warning on line 179 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L176-L179

Added lines #L176 - L179 were not covered by tests

event = Event()
event.xdata = k_target
event.ydata = j_target
event.inaxes = o1._ims[0].axes
o1._on_mouse(event)

Check warning on line 185 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L181-L185

Added lines #L181 - L185 were not covered by tests

event.inaxes = o1._ims[1].axes
event.xdata = (I - 1) - i_target # x flipped
event.xdata = (I - 1) - i_target # x flipped
event.ydata = j_target
o1._on_mouse(event)

Check warning on line 190 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L187-L190

Added lines #L187 - L190 were not covered by tests

event.inaxes = o1._ims[2].axes
event.xdata = (I - 1) - i_target # x flipped
event.xdata = (I - 1) - i_target # x flipped
event.ydata = k_target
o1._on_mouse(event)

Check warning on line 195 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L192-L195

Added lines #L192 - L195 were not covered by tests

sag = o1._ims[0].get_array()
cor = o1._ims[1].get_array()
axi = o1._ims[2].get_array()

Check warning on line 199 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L197-L199

Added lines #L197 - L199 were not covered by tests
assert_array_equal(sag, data1[i_target, :, :]) #
assert_array_equal(cor, data1[::-1, :, k_target].T) # x flipped
assert_array_equal(axi, data1[::-1, j_target, :].T) # x flipped

assert_array_equal(sag, data1[i_target, :, :]) #
assert_array_equal(cor, data1[::-1, :, k_target].T) # x flipped
assert_array_equal(axi, data1[::-1, j_target, :].T) # x flipped
return None

Check warning on line 204 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L201-L204

Added lines #L201 - L204 were not covered by tests


@needs_mpl
def test_viewer_nonRAS_on_scroll():
"""
test scrolling on non RAS matrices
"""
# This affine simulates an acquisition on a quadruped subject that is in a prone position.
# This corresponds to an acquisition with:
# This affine simulates an acquisition on a quadruped subject that is in a prone position.
# This corresponds to an acquisition with:
# - LR inverted on scanner x (i)
# - IS on scanner y (j)
# - PA on scanner z (k)
# This example enables to test also OrthoSlicer3D properties `_flips` and `_order`.

(I, J, K) = (10, 20, 40)
data1 = np.random.rand(I, J, K)
(i_target, j_target, k_target) = (2, 14, 12)
Expand All @@ -230,40 +226,35 @@ def test_viewer_nonRAS_on_scroll():
j2 = j_target + 3
k1 = k_target - 4
k2 = k_target + 4
data1[i1: i2 + 1, j1: j2 + 1, k1: k2 + 1] = 0
data1[i1 : i2 + 1, j1 : j2 + 1, k1 : k2 + 1] = 0
data1[i_target, j_target, k_target] = 1
valp1 = 1.5
valm1 = 0.5
data1[i_target - 1, j_target, k_target] = valp1 # x flipped
data1[i_target + 1, j_target, k_target] = valm1 # x flipped
data1[i_target - 1, j_target, k_target] = valp1 # x flipped
data1[i_target + 1, j_target, k_target] = valm1 # x flipped
data1[i_target, j_target - 1, k_target] = valm1
data1[i_target, j_target + 1, k_target] = valp1
data1[i_target, j_target, k_target - 1] = valm1
data1[i_target, j_target, k_target + 1] = valp1

Check warning on line 238 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L220-L238

Added lines #L220 - L238 were not covered by tests

aff1 = np.array([[-1, 0, 0, 5],
[0, 0, 1, -10],
[0, 1, 0, -30],
[0, 0, 0, 1]])


aff1 = np.array([[-1, 0, 0, 5], [0, 0, 1, -10], [0, 1, 0, -30], [0, 0, 0, 1]])

Check warning on line 240 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L240

Added line #L240 was not covered by tests

o1 = OrthoSlicer3D(data1, aff1)

Check warning on line 242 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L242

Added line #L242 was not covered by tests
class Event:
def __init__(self):
self.name = "simulated mouse event"

class Event:
def __init__(self):
self.name = 'simulated mouse event'
self.button = None
self.key = None

Check warning on line 248 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L244-L248

Added lines #L244 - L248 were not covered by tests

i_last = data1.shape[0] - 1


[x_t, y_t, z_t] = list(aff1.dot(np.array([i_target, j_target, k_target, 1]))[:3])

Check warning on line 250 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L250

Added line #L250 was not covered by tests
# print(x_t, y_t, z_t)
# scanner positions are x_t=3, y_t=2, z_t=16

event = Event()

Check warning on line 254 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L254

Added line #L254 was not covered by tests

# Sagittal plane - one scroll up
# x coordinate is flipped so index decrease by 1
# x coordinate is flipped so index decrease by 1
o1.set_position(x_t, y_t, z_t)
event.inaxes = o1._ims[0].axes
event.button = 'up'
Expand All @@ -272,10 +263,10 @@ def __init__(self):
cor = o1._ims[1].get_array()
axi = o1._ims[2].get_array()
assert_array_equal(sag, data1[i_target - 1, :, :])
assert_array_equal(cor, data1[::-1, :, k_target].T) # ::-1 because the array is flipped in x
assert_array_equal(axi, data1[::-1, j_target, :].T) # ::-1 because the array is flipped in x
# Sagittal plane - one scrolled down
assert_array_equal(cor, data1[::-1, :, k_target].T) # ::-1 because the array is flipped in x
assert_array_equal(axi, data1[::-1, j_target, :].T) # ::-1 because the array is flipped in x

Check warning on line 267 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L258-L267

Added lines #L258 - L267 were not covered by tests

# Sagittal plane - one scrolled down
o1.set_position(x_t, y_t, z_t)
event.button = 'down'
o1._on_scroll(event)
Expand All @@ -285,9 +276,9 @@ def __init__(self):
assert_array_equal(sag, data1[i_target + 1, :, :])
assert_array_equal(cor, data1[::-1, :, k_target].T)
assert_array_equal(axi, data1[::-1, j_target, :].T)

Check warning on line 278 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L270-L278

Added lines #L270 - L278 were not covered by tests

# Coronal plane - one scroll up
# y coordinate is increase by 1
# y coordinate is increase by 1
o1.set_position(x_t, y_t, z_t)
event.inaxes = o1._ims[1].axes
event.button = 'up'
Expand All @@ -296,10 +287,12 @@ def __init__(self):
cor = o1._ims[1].get_array()
axi = o1._ims[2].get_array()
assert_array_equal(sag, data1[i_target, :, :])
assert_array_equal(cor, data1[::-1, :, k_target + 1].T) # ::-1 because the array is flipped in x
assert_array_equal(axi, data1[::-1, j_target, :].T) # ::-1 because the array is flipped in x

# Coronal plane - one scrolled down
assert_array_equal(

Check warning on line 290 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L282-L290

Added lines #L282 - L290 were not covered by tests
cor, data1[::-1, :, k_target + 1].T
) # ::-1 because the array is flipped in x
assert_array_equal(axi, data1[::-1, j_target, :].T) # ::-1 because the array is flipped in x

Check warning on line 293 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L293

Added line #L293 was not covered by tests

# Coronal plane - one scrolled down
o1.set_position(x_t, y_t, z_t)
event.button = 'down'
o1._on_scroll(event)
Expand All @@ -309,9 +302,9 @@ def __init__(self):
assert_array_equal(sag, data1[i_target, :, :])
assert_array_equal(cor, data1[::-1, :, k_target - 1].T)
assert_array_equal(axi, data1[::-1, j_target, :].T)

Check warning on line 304 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L296-L304

Added lines #L296 - L304 were not covered by tests

# Axial plane - one scroll up
# y is increase by 1
# y is increase by 1
o1.set_position(x_t, y_t, z_t)
event.inaxes = o1._ims[2].axes
event.button = 'up'
Expand All @@ -320,10 +313,12 @@ def __init__(self):
cor = o1._ims[1].get_array()
axi = o1._ims[2].get_array()
assert_array_equal(sag, data1[i_target, :, :])
assert_array_equal(cor, data1[::-1, :, k_target].T) # ::-1 because the array is flipped in x
assert_array_equal(axi, data1[::-1, j_target + 1, :].T) # ::-1 because the array is flipped in x

# Axial plane - one scrolled down
assert_array_equal(cor, data1[::-1, :, k_target].T) # ::-1 because the array is flipped in x
assert_array_equal(

Check warning on line 317 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L308-L317

Added lines #L308 - L317 were not covered by tests
axi, data1[::-1, j_target + 1, :].T
) # ::-1 because the array is flipped in x

# Axial plane - one scrolled down
o1.set_position(x_t, y_t, z_t)
event.button = 'down'
o1._on_scroll(event)
Expand All @@ -333,4 +328,4 @@ def __init__(self):
assert_array_equal(sag, data1[i_target, :, :])
assert_array_equal(cor, data1[::-1, :, k_target].T)
assert_array_equal(axi, data1[::-1, j_target - 1, :].T)
return None
return None

Check warning on line 331 in nibabel/tests/test_viewers.py

View check run for this annotation

Codecov / codecov/patch

nibabel/tests/test_viewers.py#L322-L331

Added lines #L322 - L331 were not covered by tests

0 comments on commit 5d89d2f

Please sign in to comment.