Skip to content

Commit 2a7d951

Browse files
committed
Simplify extracting struct info
1 parent bb92d55 commit 2a7d951

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

cifti.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,16 @@ def __init__(self, img, full_surface=False):
172172
# Assign remaining args to class
173173
self.full_surface = full_surface
174174

175+
# Extract structure information into dict
176+
self.struct_info = {name:(slice_, model) for (name, slice_, model) \
177+
in self.axis1.iter_structures()}
178+
175179
def _get_struct_info(self, struct_name):
176180
"""
177-
Return structure indices and axis model for given structure
181+
Get slice, axis model, and resolved structure name for given structure
178182
"""
179-
# Check name
180183
struct_name = self.axis1.to_cifti_brain_structure_name(struct_name)
181-
182-
# Loop structures, return matching one
183-
for name, struct_indices, model in self.axis1.iter_structures():
184-
if name == struct_name:
185-
return struct_indices, model, struct_name
186-
187-
# If we reach here then structure doesn't exist - raise error
188-
raise Exception(f'No data found for structure: {struct_name}')
184+
return *self.struct_info[struct_name], struct_name
189185

190186
def _get_volume_mask(self):
191187
"""
@@ -398,8 +394,8 @@ class CiftiMasker(object):
398394
Arguments
399395
---------
400396
mask_img : str, Cifti2Image, or CiftiHandler
401-
Path to input mask (likely a dlabel CIFTI file), long or short name
402-
of a CIFTI structure (e.g. 'CIFTI_STRUCTURE_LEFT_HIPPOCAMPUS' or
397+
Path to input mask (likely a dlabel or dscalar CIFTI file), name of a
398+
CIFTI structure (e.g., 'CIFTI_STRUCTURE_LEFT_HIPPOCAMPUS' or
403399
'left hippocampus'), or Cifti2Image or CiftiHandler object containing
404400
mask data.
405401

0 commit comments

Comments
 (0)