Skip to content

Commit 0f56724

Browse files
committed
TEST Test slicing, percentiles
1 parent 6779205 commit 0f56724

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

nibabel/tests/test_spatialimages.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ def test_get_data(self):
335335
assert_false(rt_img.get_data() is out_data)
336336
assert_array_equal(rt_img.get_data(), in_data)
337337

338+
def test_orthoview(self):
339+
# Assumes all possible images support int16
340+
# See https://github.com/nipy/nibabel/issues/58
341+
arr = np.arange(24, dtype=np.int16).reshape((2, 3, 4))
342+
img = self.image_class(arr, None)
343+
img.orthoview().close()
344+
img.orthoview(vlim=(5, 10)).close()
345+
img.orthoview(slicer=Ellipsis).close()
346+
338347
def test_api_deprecations(self):
339348

340349
class FakeImage(self.image_class):

nibabel/tests/test_viewers.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy.testing.decorators import skipif
1818
from numpy.testing import assert_array_equal, assert_equal
1919

20-
from nose.tools import assert_raises, assert_true
20+
from nose.tools import assert_raises, assert_true, assert_false
2121

2222
# Need at least MPL 1.3 for viewer tests.
2323
matplotlib, has_mpl, _ = optional_package('matplotlib', min_version='1.3')
@@ -75,6 +75,15 @@ def test_viewer():
7575
for im in v._ims:
7676
assert_array_equal(im.get_clim(), vlim)
7777
assert_array_equal(v._axes[3].get_ylim(), vlim)
78+
v.close()
79+
v1 = OrthoSlicer3D(data)
80+
v2 = OrthoSlicer3D(data, vlim=('1%', '99%'))
81+
assert_array_equal(v1.clim, v2.clim)
82+
v2.close()
83+
v2 = OrthoSlicer3D(data, vlim=('2%', '98%'))
84+
assert_false(np.array_equal(v1.clim, v2.clim))
85+
v2.close()
86+
v1.close()
7887

7988
# non-multi-volume
8089
v = OrthoSlicer3D(data[:, :, :, 0])
@@ -102,3 +111,15 @@ def test_viewer():
102111
v2.link_to(v1) # shouldn't do anything
103112
v1.close()
104113
v2.close()
114+
115+
# Test various slicers
116+
OrthoSlicer3D(data, slicer=Ellipsis).close()
117+
# Slice time dimension
118+
OrthoSlicer3D(data, slicer=(Ellipsis, slice(None, None, 2))).close()
119+
OrthoSlicer3D(data, slicer=(Ellipsis, 0)).close()
120+
OrthoSlicer3D(data, slicer=(Ellipsis, [0])).close()
121+
# Slice spatial dimensions
122+
OrthoSlicer3D(data, slicer=(slice(0, 1), slice(0, 1), slice(0, 1))).close()
123+
OrthoSlicer3D(data, slicer=(slice(0, -1), slice(0, -1), slice(0, -1))).close()
124+
# Fail if we slice too thin
125+
assert_raises(ValueError, OrthoSlicer3D, data, slicer=(Ellipsis, 0, 0))

0 commit comments

Comments
 (0)