Vertices

External Email - Use Caution

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?

Best,
Karin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180930/99153e92/attachment.html

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)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1386 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180930/0fb2640f/attachment.bin
-------------- next part --------------
        External Email - Use Caution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180930/0fb2640f/attachment.html

External Email - Use Caution

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180930/83e7c7b2/attachment.html

Hi Karin,

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()

fwd = mne.read_forward_solution(
    data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif')

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

Thanks

Sheraz