Skip to content

Commit b88d516

Browse files
RF: return CIFTI_MODEL_TYPE to distinguish surface and voxels
1 parent f7c47bb commit b88d516

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

nibabel/cifti2/cifti2_axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,15 @@ def get_element(self, index):
670670
Returns
671671
-------
672672
tuple with 3 elements
673-
- boolean, which is True if it is a surface element
673+
- str, 'CIFTI_MODEL_TYPE_SURFACE' for vertex or 'CIFTI_MODEL_TYPE_VOXELS' for voxel
674674
- vertex index if it is a surface element, otherwise array with 3 voxel indices
675675
- structure.BrainStructure object describing the brain structure the element was taken from
676676
"""
677-
is_surface = self.name[index] in self.nvertices.keys()
678-
struct = self.vertex if is_surface else self.voxel
679-
return is_surface, struct[index], self.name[index]
677+
element_type = 'CIFTI_MODEL_TYPE_' + (
678+
'SURFACE' if self.name[index] in self.nvertices.keys() else 'VOXELS'
679+
)
680+
struct = self.vertex if 'SURFACE' in element_type else self.voxel
681+
return element_type, struct[index], self.name[index]
680682

681683

682684
class Parcels(Axis):

nibabel/cifti2/tests/test_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_brain_models():
107107
assert len(bml[0]) == 3
108108
assert (bml[0].vertex == -1).all()
109109
assert (bml[0].voxel == [[0, 1, 2], [0, 4, 0], [0, 4, 2]]).all()
110-
assert bml[0][1][0] == False
110+
assert bml[0][1][0] == 'CIFTI_MODEL_TYPE_VOXELS'
111111
assert (bml[0][1][1] == [0, 4, 0]).all()
112112
assert bml[0][1][2] == axes.BrainModel.to_cifti_brain_structure_name('thalamus_right')
113113
assert len(bml[1]) == 4
@@ -116,11 +116,11 @@ def test_brain_models():
116116
assert len(bml[2]) == 3
117117
assert (bml[2].voxel == -1).all()
118118
assert (bml[2].vertex == [0, 5, 10]).all()
119-
assert bml[2][1] == (True, 5, 'CIFTI_STRUCTURE_CORTEX_LEFT')
119+
assert bml[2][1] == ('CIFTI_MODEL_TYPE_SURFACE', 5, 'CIFTI_STRUCTURE_CORTEX_LEFT')
120120
assert len(bml[3]) == 4
121121
assert (bml[3].voxel == -1).all()
122122
assert (bml[3].vertex == [0, 5, 10, 13]).all()
123-
assert bml[4][1] == (True, 9, 'CIFTI_STRUCTURE_CORTEX_RIGHT')
123+
assert bml[4][1] == ('CIFTI_MODEL_TYPE_SURFACE', 9, 'CIFTI_STRUCTURE_CORTEX_RIGHT')
124124
assert len(bml[4]) == 3
125125
assert (bml[4].voxel == -1).all()
126126
assert (bml[4].vertex == [2, 9, 14]).all()

0 commit comments

Comments
 (0)