Hi!
I'm trying to find closest neighbors of vertices, and found this code
snippet in a previous question on the same subject:
import mne
from mne.source_estimate import spatial_tris_connectivity
import numpy as np
surf = mne.surface._get_ico_surface(5)
connectivity = spatial_tris_connectivity(surf['tris'])
connectivity = connectivity.todense()
neighbours_list = [np.where(row==1)[1] for row in connectivity] #neighbours_list contains the list of the neighbours of each vertex
However, if I try to plot ( using .add foci()) the arrays containing the
vertices of interest, I get 6 foci scattered all over the brain. So now my
question is how to interpret the output of neighbors_list?
Well then there's one explanation anyway... I'm using the subject's own
reconstructed MR.
Plotting using brain.add_foci(vertex, coords_as_verts=True, hemi='lh',
color=(1,0,0)) where brain = stc.plot().
Karin
Den s?n 30 sep. 2018 kl 18:10 skrev Marijn van Vliet <w.m.vanvliet at gmail.com
:
Hi karin,
How are you plotting the result exactly? This line:
surf = mne.surface._get_ico_surface(5)
only works for the fsaverage brain.
best,
Marijn.
>
> surf = mne.surface._get_ico_surface(5)
External Email - Use Caution
_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu Mne_analysis Info Page
Please find below, code snippet for finding neighbors for the individual
subject.
Its much more efficient version of the previous code and does not requires
casting sparse matrix to dense. You can find neighbors for ico5 even on a
conventional laptop.
import mne
from mne.source_estimate import spatial_tris_connectivity
import numpy as np
from mne.datasets import sample
# Only for fsaverage
surf = mne.surface._get_ico_surface(5)
connectivity = spatial_tris_connectivity(surf['tris'])
connectivity = connectivity.asformat('csr')
neighbours_list = np.split(connectivity.indices, connectivity.indptr)[1:-1]
# list of neighbours of each vertex
# for individual subjects having forward operator
data_path = sample.data_path()
lh = fwd['src'][0] # Visualize the left hemisphere
tris = lh['tris'] # Groups of three vertices that form triangles
connectivity = spatial_tris_connectivity(tris)
connectivity = connectivity.asformat('csr')
neighbours_list = np.split(connectivity.indices, connectivity.indptr)[1:-1]
# list of neighbours of each vertex