File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ def __ne__(self, other):
178178class TransformBase :
179179 """Abstract image class to represent transforms."""
180180
181- __slots__ = ("_reference" ,)
181+ __slots__ = ("_reference" , "_ndim" , )
182182
183183 def __init__ (self , reference = None ):
184184 """Instantiate a transform."""
@@ -220,7 +220,7 @@ def reference(self, image):
220220 @property
221221 def ndim (self ):
222222 """Access the dimensions of the reference space."""
223- return self . reference . ndim
223+ raise TypeError ( "TransformBase has no dimensions" )
224224
225225 def apply (
226226 self ,
Original file line number Diff line number Diff line change @@ -143,6 +143,11 @@ def matrix(self):
143143 """Access the internal representation of this affine."""
144144 return self ._matrix
145145
146+ @property
147+ def ndim (self ):
148+ """Access the internal representation of this affine."""
149+ return self ._matrix .ndim + 1
150+
146151 def map (self , x , inverse = False ):
147152 r"""
148153 Apply :math:`y = f(x)`.
Original file line number Diff line number Diff line change @@ -94,7 +94,8 @@ def _to_hdf5(klass, x5_root):
9494 # Test identity transform
9595 xfm = TransformBase ()
9696 xfm .reference = fname
97- assert xfm .ndim == 3
97+ with pytest .raises (TypeError ):
98+ _ = xfm .ndim
9899 moved = xfm .apply (fname , order = 0 )
99100 assert np .all (
100101 imgdata == np .asanyarray (moved .dataobj , dtype = moved .get_data_dtype ())
@@ -103,12 +104,19 @@ def _to_hdf5(klass, x5_root):
103104 # Test identity transform - setting reference
104105 xfm = TransformBase ()
105106 xfm .reference = fname
106- assert xfm .ndim == 3
107+ with pytest .raises (TypeError ):
108+ _ = xfm .ndim
107109 moved = xfm .apply (str (fname ), reference = fname , order = 0 )
108110 assert np .all (
109111 imgdata == np .asanyarray (moved .dataobj , dtype = moved .get_data_dtype ())
110112 )
111113
114+ # Test ndim returned by affine
115+ assert nitl .Affine ().ndim == 3
116+ assert nitl .LinearTransformsMapping (
117+ [nitl .Affine (), nitl .Affine ()]
118+ ).ndim == 4
119+
112120 # Test applying to Gifti
113121 gii = nb .gifti .GiftiImage (
114122 darrays = [
You can’t perform that action at this time.
0 commit comments