Skip to content

Commit 7d2b9b3

Browse files
committed
TEST Test slicing, percentiles
1 parent 6779205 commit 7d2b9b3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

nibabel/tests/test_spatialimages.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from numpy.testing import assert_array_equal, assert_array_almost_equal
2525

2626
from .test_helpers import bytesio_round_trip
27+
from .test_viewers import needs_mpl
2728
from ..testing import (clear_and_catch_warnings, suppress_warnings,
2829
VIRAL_MEMMAP)
2930
from ..tmpdirs import InTemporaryDirectory
@@ -335,6 +336,16 @@ def test_get_data(self):
335336
assert_false(rt_img.get_data() is out_data)
336337
assert_array_equal(rt_img.get_data(), in_data)
337338

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

340351
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)