Skip to content

Commit 08faad6

Browse files
committed
RF/TEST: Purge _spatial_dims and related tests
1 parent 7bb3fe2 commit 08faad6

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

nibabel/analyze.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ class AnalyzeImage(SpatialImage):
911911
files_types = (('image', '.img'), ('header', '.hdr'))
912912
valid_exts = ('.img', '.hdr')
913913
_compressed_suffixes = ('.gz', '.bz2')
914-
_spatial_dims = slice(0, 3)
915914

916915
makeable = True
917916
rw = True

nibabel/ecat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ class EcatImage(SpatialImage):
740740
valid_exts = ('.v',)
741741
_subheader = EcatSubHeader
742742
files_types = (('image', '.v'), ('header', '.v'))
743-
_spatial_dims = slice(0, 3)
744743

745744
ImageArrayProxy = EcatImageArrayProxy
746745

nibabel/freesurfer/mghformat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ class MGHImage(SpatialImage):
507507
ImageOpener.compress_ext_map['.mgz'] = ImageOpener.gz_def
508508
files_types = (('image', '.mgh'),)
509509
_compressed_suffixes = ()
510-
_spatial_dims = slice(0, 3)
511510

512511
makeable = True
513512
rw = True

nibabel/tests/test_spatialimages.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from io import BytesIO
1818
from ..spatialimages import (SpatialHeader, SpatialImage, HeaderDataError,
1919
Header, ImageDataError)
20+
from ..imageclasses import spatial_axes_first
2021

2122
from unittest import TestCase
2223
from nose.tools import (assert_true, assert_false, assert_equal,
@@ -422,19 +423,19 @@ def test_slicer(self):
422423
in_data = in_data_template.copy().reshape(dshape)
423424
img = img_klass(in_data, base_affine.copy())
424425

425-
# Detect time axis on first loop (4D image)
426-
if t_axis is None and img._spatial_dims is not None:
427-
t_axis = 3 if img._spatial_dims.start == 0 else 0
426+
if not spatial_axes_first(img):
427+
with assert_raises(ValueError):
428+
img.slicer
429+
continue
428430

429431
assert_true(hasattr(img.slicer, '__getitem__'))
430432

431433
# Note spatial zooms are always first 3, even when
432434
spatial_zooms = img.header.get_zooms()[:3]
433435

434436
# Down-sample with [::2, ::2, ::2] along spatial dimensions
435-
sliceobj = [slice(None)] * len(dshape)
436-
if img._spatial_dims is not None:
437-
sliceobj[img._spatial_dims] = [slice(None, None, 2)] * 3
437+
sliceobj = [slice(None, None, 2)] * 3 + \
438+
[slice(None)] * (len(dshape) - 3)
438439
downsampled_img = img.slicer[tuple(sliceobj)]
439440
assert_array_equal(downsampled_img.header.get_zooms()[:3],
440441
np.array(spatial_zooms) * 2)
@@ -443,19 +444,10 @@ def test_slicer(self):
443444
'dims' in img.header._structarr.dtype.fields and
444445
img.header._structarr['dims'].shape == (4,))
445446
# Check newaxis and single-slice errors
446-
if t_axis == 3:
447-
with assert_raises(IndexError):
448-
img.slicer[None]
449-
with assert_raises(IndexError):
450-
img.slicer[0]
451-
elif len(img.shape) == 4:
452-
with assert_raises(IndexError):
453-
img.slicer[None]
454-
# 4D Minc to 3D
455-
assert_equal(img.slicer[0].shape, img.shape[1:])
456-
elif t_axis is not None:
457-
# 3D Minc to 4D
458-
assert_equal(img.slicer[None].shape, (1,) + img.shape)
447+
with assert_raises(IndexError):
448+
img.slicer[None]
449+
with assert_raises(IndexError):
450+
img.slicer[0]
459451
# Axes 1 and 2 are always spatial
460452
with assert_raises(IndexError):
461453
img.slicer[:, None]
@@ -465,12 +457,7 @@ def test_slicer(self):
465457
img.slicer[:, :, None]
466458
with assert_raises(IndexError):
467459
img.slicer[:, :, 0]
468-
if t_axis == 0:
469-
with assert_raises(IndexError):
470-
img.slicer[:, :, :, None]
471-
with assert_raises(IndexError):
472-
img.slicer[:, :, :, 0]
473-
elif len(img.shape) == 4:
460+
if len(img.shape) == 4:
474461
if max4d:
475462
with assert_raises(ValueError):
476463
img.slicer[:, :, :, None]
@@ -481,7 +468,7 @@ def test_slicer(self):
481468
# 4D to 3D using ellipsis or slices
482469
assert_equal(img.slicer[..., 0].shape, img.shape[:-1])
483470
assert_equal(img.slicer[:, :, :, 0].shape, img.shape[:-1])
484-
elif t_axis is not None:
471+
else:
485472
# 3D Analyze/NIfTI/MGH to 4D
486473
assert_equal(img.slicer[:, :, :, None].shape, img.shape + (1,))
487474
if len(img.shape) == 3:
@@ -496,17 +483,10 @@ def test_slicer(self):
496483
img.shape + (1,))
497484

498485
# Crop by one voxel in each dimension
499-
if len(img.shape) == 3 or t_axis == 3:
500-
sliced_i = img.slicer[1:]
501-
sliced_j = img.slicer[:, 1:]
502-
sliced_k = img.slicer[:, :, 1:]
503-
sliced_ijk = img.slicer[1:, 1:, 1:]
504-
elif t_axis is not None:
505-
# 4D Minc
506-
sliced_i = img.slicer[:, 1:]
507-
sliced_j = img.slicer[:, :, 1:]
508-
sliced_k = img.slicer[:, :, :, 1:]
509-
sliced_ijk = img.slicer[:, 1:, 1:, 1:]
486+
sliced_i = img.slicer[1:]
487+
sliced_j = img.slicer[:, 1:]
488+
sliced_k = img.slicer[:, :, 1:]
489+
sliced_ijk = img.slicer[1:, 1:, 1:]
510490

511491
# No scaling change
512492
assert_array_equal(sliced_i.affine[:3, :3], img.affine[:3, :3])

0 commit comments

Comments
 (0)