Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow return of labelids in find_parcel_centroids #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions netneurotools/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def _decode_list(vals):


def find_parcel_centroids(*, lhannot, rhannot, method='surface',
version='fsaverage', surf='sphere', drop=None):
version='fsaverage', surf='sphere', drop=None,
get_labelids=False):
"""
Returns vertex coords corresponding to centroids of parcels in annotations

Expand Down Expand Up @@ -144,6 +145,8 @@ def find_parcel_centroids(*, lhannot, rhannot, method='surface',
Specifies regions in {lh,rh}annot for which the parcel centroid should
not be calculated. If not specified, centroids for parcels defined in
`netneurotools.freesurfer.FSIGNORE` are not calculated. Default: None
get_labelids: boolean, optional
If True, return a list of label ids corresponding to each centroid

Returns
-------
Expand All @@ -153,6 +156,9 @@ def find_parcel_centroids(*, lhannot, rhannot, method='surface',
hemiid : (N,) numpy.ndarray
Array denoting hemisphere designation of coordinates in `centroids`,
where `hemiid=0` denotes the left and `hemiid=1` the right hemisphere
labelid : (N,) numpy.ndarray
Only returned if get_labelids == True. Array denoting label of coordinates in
`centroids`

Notes
-----
Expand Down Expand Up @@ -189,7 +195,7 @@ def find_parcel_centroids(*, lhannot, rhannot, method='surface',

surfaces = fetch_fsaverage(version)[surf]

centroids, hemiid = [], []
centroids, hemiid, labelid = [], [], []
for n, (annot, surf) in enumerate(zip([lhannot, rhannot], surfaces)):
vertices, faces = read_geometry(surf)
labels, ctab, names = read_annot(annot)
Expand All @@ -207,8 +213,14 @@ def find_parcel_centroids(*, lhannot, rhannot, method='surface',
roi = _geodesic_parcel_centroid(vertices, faces, inds)
centroids.append(roi)
hemiid.append(n)
if get_labelids:
labelid.append(lab)

return np.row_stack(centroids), np.asarray(hemiid)
main = np.row_stack(centroids), np.asarray(hemiid),
if get_labelids:
return *main, np.asarray(labelid)

return main


def _geodesic_parcel_centroid(vertices, faces, inds):
Expand Down