Skip to content

Commit b5f0f76

Browse files
committed
FIX split_lr in get_roi_masks did not split correctly between l/r hemispheres
1 parent eda09cd commit b5f0f76

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cortex/utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ def get_roi_verts(subject, roi=None, mask=False, overlay_file=None):
352352
extra_idx = set()
353353
for idx in roi_idx:
354354
extra_idx.update(ii for ii in neighbors_dict[idx] if ii not in goodpts)
355-
roi_idx = np.unique(np.concatenate((roi_idx, list(extra_idx)))).astype(int)
355+
if extra_idx:
356+
roi_idx = np.unique(np.concatenate((roi_idx, list(extra_idx)))).astype(int)
356357

357358
if mask:
358359
roidict[name] = np.zeros(pts.shape[:1], dtype=bool)
@@ -673,18 +674,20 @@ def get_roi_masks(subject, xfmname, roi_list=None, gm_sampler='cortical', split_
673674
for roi in roi_list:
674675
roi_voxels[roi][all_mask > 1] = False
675676
# Split left / right hemispheres if desired
676-
# There ought to be a more succinct way to do this - get_hemi_masks only does the cortical
677-
# ribbon, and is not guaranteed to have all voxels in the cortex_mask specified in this fn
678677
if split_lr:
679-
left_verts, right_verts = db.get_surf(subject, "flat", merge=False, nudge=True)
678+
# Use the fiducial surface because we need to have all vertices
679+
left_verts, _ = db.get_surf(subject, "fiducial", merge=False, nudge=True)
680680
left_mask = vox_idx < len(np.unique(left_verts[1]))
681681
right_mask = np.logical_not(left_mask)
682682
roi_voxels_lr = {}
683683
for roi in roi_list:
684-
roi_voxels_lr[roi+'_L'] = copy.copy(roi_voxels[roi]) # & left_mask
685-
roi_voxels_lr[roi+'_L'][right_mask] = False # ?
686-
roi_voxels_lr[roi+'_R'] = copy.copy(roi_voxels[roi]) # & right_mask
687-
roi_voxels_lr[roi+'_R'][left_mask] = False # ?
684+
# roi_voxels may contain float values if using a mapper, therefore we need
685+
# to manually set the voxels in the other hemisphere to False. Then we let
686+
# numpy do the conversion False -> 0.
687+
roi_voxels_lr[roi + '_L'] = copy.copy(roi_voxels[roi])
688+
roi_voxels_lr[roi + '_L'][right_mask] = False
689+
roi_voxels_lr[roi + '_R'] = copy.copy(roi_voxels[roi])
690+
roi_voxels_lr[roi + '_R'][left_mask] = False
688691
output = roi_voxels_lr
689692
else:
690693
output = roi_voxels

0 commit comments

Comments
 (0)