Skip to content

Commit fd8593e

Browse files
RF: renamed is_surface to surface_mask and added volume_mask
1 parent b88d516 commit fd8593e

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

nibabel/cifti2/cifti2_axes.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
284284
if name not in self.name:
285285
del self.nvertices[name]
286286

287-
is_surface = self.is_surface
288-
if is_surface.all():
287+
surface_mask = self.surface_mask
288+
if surface_mask.all():
289289
self.affine = None
290290
self.volume_shape = None
291291
else:
@@ -295,9 +295,9 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
295295
self.affine = affine
296296
self.volume_shape = volume_shape
297297

298-
if np.any(self.vertex[is_surface] < 0):
298+
if np.any(self.vertex[surface_mask] < 0):
299299
raise ValueError('Undefined vertex indices found for surface elements')
300-
if np.any(self.voxel[~is_surface] < 0):
300+
if np.any(self.voxel[~surface_mask] < 0):
301301
raise ValueError('Undefined voxel indices found for volumetric elements')
302302

303303
for check_name in ('name', 'voxel', 'vertex'):
@@ -523,12 +523,19 @@ def to_cifti_brain_structure_name(name):
523523
return proposed_name
524524

525525
@property
526-
def is_surface(self):
526+
def surface_mask(self):
527527
"""
528528
(N, ) boolean array which is true for any element on the surface
529529
"""
530530
return np.vectorize(lambda name: name in self.nvertices.keys())(self.name)
531531

532+
@property
533+
def volume_mask(self):
534+
"""
535+
(N, ) boolean array which is true for any element on the surface
536+
"""
537+
return np.vectorize(lambda name: name not in self.nvertices.keys())(self.name)
538+
532539
_affine = None
533540

534541
@property
@@ -586,13 +593,13 @@ def __eq__(self, other):
586593
if xor(self.affine is None, other.affine is None):
587594
return False
588595
return (
589-
(self.affine is None or
596+
(self.affine is None or
590597
np.allclose(self.affine, other.affine) and
591598
self.volume_shape == other.volume_shape) and
592-
self.nvertices == other.nvertices and
593-
np.array_equal(self.name, other.name) and
594-
np.array_equal(self.voxel[~self.is_surface], other.voxel[~other.is_surface]) and
595-
np.array_equal(self.vertex[self.is_surface], other.vertex[other.is_surface])
599+
self.nvertices == other.nvertices and
600+
np.array_equal(self.name, other.name) and
601+
np.array_equal(self.voxel[~self.surface_mask], other.voxel[~other.surface_mask]) and
602+
np.array_equal(self.vertex[self.surface_mask], other.vertex[other.surface_mask])
596603
)
597604

598605
def __add__(self, other):
@@ -763,7 +770,7 @@ def from_brain_models(cls, named_brain_models):
763770
for idx_parcel, (parcel_name, bm) in enumerate(named_brain_models):
764771
all_names.append(parcel_name)
765772

766-
voxels = bm.voxel[~bm.is_surface]
773+
voxels = bm.voxel[~bm.surface_mask]
767774
if voxels.shape[0] != 0:
768775
if affine is None:
769776
affine = bm.affine

nibabel/cifti2/tests/test_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def test_brain_models():
127127

128128
for bm, label, is_surface in zip(bml, ['ThalamusRight', 'Other', 'cortex_left', 'Other'],
129129
(False, False, True, True)):
130+
assert np.all(bm.surface_mask == ~bm.volume_mask)
130131
structures = list(bm.iter_structures())
131132
assert len(structures) == 1
132133
name = structures[0][0]

nibabel/cifti2/tests/test_cifti2io_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def check_Conte69(brain_model):
6666
structures = list(brain_model.iter_structures())
6767
assert len(structures) == 2
6868
assert structures[0][0] == 'CIFTI_STRUCTURE_CORTEX_LEFT'
69-
assert structures[0][2].is_surface.all()
69+
assert structures[0][2].surface_mask.all()
7070
assert structures[1][0] == 'CIFTI_STRUCTURE_CORTEX_RIGHT'
71-
assert structures[1][2].is_surface.all()
71+
assert structures[1][2].surface_mask.all()
7272
assert (brain_model.voxel == -1).all()
7373

7474
assert (brain_model.vertex[:5] == np.arange(5)).all()

0 commit comments

Comments
 (0)