Skip to content

Commit 7bb3fe2

Browse files
committed
RF: Switch to spatial_axes_first
1 parent c18fef7 commit 7bb3fe2

File tree

3 files changed

+5
-46
lines changed

3 files changed

+5
-46
lines changed

nibabel/minc1.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -319,49 +319,6 @@ def from_file_map(klass, file_map):
319319
data = klass.ImageArrayProxy(minc_file)
320320
return klass(data, affine, header, extra=None, file_map=file_map)
321321

322-
@property
323-
def _spatial_dims(self):
324-
if len(self.shape) > 3:
325-
return slice(1, 4)
326-
return slice(0, 3)
327-
328-
def _check_slicing(self, slicer, return_spatial=False):
329-
''' Canonicalize slicers and check for scalar indices in spatial dims
330-
331-
Parameters
332-
----------
333-
slicer : object
334-
something that can be used to slice an array as in
335-
``arr[sliceobj]``
336-
return_spatial : bool
337-
return only slices along spatial dimensions (x, y, z)
338-
339-
Returns
340-
-------
341-
slicer : object
342-
Validated slicer object that will slice image's `dataobj`
343-
without collapsing spatial dimensions
344-
'''
345-
slicer = canonical_slicers(slicer, self.shape)
346-
try:
347-
all_slices = super(Minc1Image, self)._check_slicing(slicer, False)
348-
sp_dims = self._spatial_dims
349-
except IndexError:
350-
# Prepending a new axis for 3D images is valid in Minc
351-
if slicer[0] is None and self._spatial_dims == slice(0, 3):
352-
all_slices = (None,) + super(Minc1Image, self)._check_slicing(slicer[1:], False)
353-
sp_dims = slice(1, 4)
354-
else:
355-
raise
356-
# Added complications of first axis being time
357-
if self._spatial_dims == slice(1, 4) and all_slices[0] is None:
358-
raise IndexError("New temporal axis is not permitted in 4D Minc images")
359-
elif (self._spatial_dims == slice(0, 3) and len(all_slices) > 3 and
360-
all_slices[0] is not None):
361-
raise IndexError("New axes cannot be added to 3D Minc image "
362-
"without new temporal axis (first dimension)")
363-
return all_slices[sp_dims] if return_spatial else all_slices
364-
365322

366323
load = Minc1Image.load
367324

nibabel/parrec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,6 @@ class PARRECImage(SpatialImage):
12221222
header_class = PARRECHeader
12231223
valid_exts = ('.rec', '.par')
12241224
files_types = (('image', '.rec'), ('header', '.par'))
1225-
_spatial_dims = slice(0, 3)
12261225

12271226
makeable = False
12281227
rw = False

nibabel/spatialimages.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ class ImageDataError(Exception):
325325
class SpatialImage(DataobjImage):
326326
''' Template class for volumetric (3D/4D) images '''
327327
header_class = SpatialHeader
328-
_spatial_dims = None
329328

330329
class Slicer(object):
331330
''' Slicing interface that returns a new image with an updated affine
@@ -496,7 +495,7 @@ def _check_slicing(self, slicer, return_spatial=False):
496495
without collapsing spatial dimensions
497496
'''
498497
slicer = canonical_slicers(slicer, self.shape)
499-
spatial_slices = slicer[self._spatial_dims]
498+
spatial_slices = slicer[:3]
500499
for subslicer in spatial_slices:
501500
if subslicer is None:
502501
raise IndexError("New axis not permitted in spatial dimensions")
@@ -559,6 +558,10 @@ def slicer(self):
559558
560559
.. _aliasing: https://en.wikipedia.org/wiki/Aliasing
561560
"""
561+
from .imageclasses import spatial_axes_first
562+
if not spatial_axes_first(self):
563+
raise ValueError("Cannot predict position of spatial axes for "
564+
"Image type " + self.__class__.__name__)
562565
return self.Slicer(self)
563566

564567

0 commit comments

Comments
 (0)