Skip to content

Commit

Permalink
FIX get_roi_surfs is now py3 compatible and accepts overlay_file (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdoc authored Oct 18, 2022
1 parent aab18d4 commit 8135f0e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cortex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def get_roi_verts(subject, roi=None, mask=False, overlay_file=None):
mask : bool
if True, return a logical mask across vertices for the roi
if False, return a list of indices for the ROI
overlay_file : None or str
Pass another overlays file instead of the default overlays.svg
Returns
-------
Expand Down Expand Up @@ -339,7 +341,7 @@ def get_roi_verts(subject, roi=None, mask=False, overlay_file=None):
return roidict


def get_roi_surf(subject, surf_type, roi):
def get_roi_surf(subject, surf_type, roi, overlay_file=None):
"""Similar to get_roi_verts, but gets both the points and the polys for an roi.
Parameters
Expand All @@ -351,27 +353,29 @@ def get_roi_surf(subject, surf_type, roi):
superinflated, flat)
roi : str
Name of ROI to get the surface geometry for.
overlay_file : None or str
Pass another overlays file instead of the default overlays.svg
Returns
-------
pts, polys : (array, array)
The points, specified in 3D space, as well as indices into pts specifying the polys.
"""
roi_verts_mask = get_roi_verts(subject, roi, mask=True)
roi_verts_mask = get_roi_verts(subject, roi, mask=True, overlay_file=overlay_file)
pts, polys = db.get_surf(subject, surf_type, merge=True, nudge=True)
vert_idx = np.where(roi_verts_mask[roi])[0]
vert_set = set(vert_idx)
roi_polys = []
for i in xrange(np.shape(polys)[0]):
if np.array(map(lambda x: x in vert_set, polys[i, :])).all():
for i in range(np.shape(polys)[0]):
if np.array(list(map(lambda x: x in vert_set, polys[i, :]))).all():
roi_polys.append(polys[i, :])
reindexed_polys = []
vert_rev_hash_idx = {}
for i, v in enumerate(vert_idx):
vert_rev_hash_idx[v] = i
for poly in roi_polys:
reindexed_polys.append(map(vert_rev_hash_idx.get, poly))
return (pts[vert_idx], np.array(reindexed_polys))
reindexed_polys.append(list(map(vert_rev_hash_idx.get, poly)))
return pts[vert_idx], np.array(reindexed_polys)


def get_roi_mask(subject, xfmname, roi=None, projection='nearest'):
Expand Down

0 comments on commit 8135f0e

Please # to comment.