Identifying adjacent sources

Hi,

I was reading this thread
<https://mail.nmr.mgh.harvard.edu/pipermail//mne_analysis/2013-May/001527.html>
from 2013 on identifying adjacent sources in mne. I'm also trying to find
sources adjacent to a particular vertex. However, the example

*http://martinos.org/mne/auto_examples/plot_read_forward.html#example-plot-read-forward-py
<http://martinos.org/mne/auto_examples/plot_read_forward.html#example-plot-read-forward-py>

This is the old script I was pointing to:

https://github.com/mne-tools/mne-python/blob/maint/0.4/examples/plot_read_forward.py

HTH
Alex

Hi Alex,

I'm still not sure how to get the adjacency matrix, based on the example.
It seems like lh_faces and rh_faces contain the faces from the original
cortical parcellation, before some sources are removed? I have an ico 3
source space. My leadfield matrix has 1162 sources in total. Thus
fwd['src'][0]['vertno'].shape = 581 and fwd['src'][1]['vertno'].shape =
581. However, fwd['src'][0]['usetris'].shape = 1280 and
fwd['src'][1]['usetris'].shape = 1280, so I'm not sure which faces
correspond to which vertices?

Thanks and Best,
Gladia

i suppose you mean use_tris with _

it's normal to have twice more triangles than vertices.

see for example here:

https://github.com/mne-tools/mne-python/blob/master/mne/viz/_3d.py#L1444

how we get the triangles in low resolution with vertices index that go
from 0 to 581 in your case.

HTH
Alex

Hi Alex,

Thanks for your reply! I did:

surf = fwd['src'][hemi_idx]
tris = surf['use_tris']

edges = mesh_edges(tris)

The dimensions of 'edges' are 642*642 in my case.

I'm not sure I understand how coo_matrix in the mesh_edges function works.

I saw that in the mesh_edges function,

npoints = np.max(tris) + 1

Which gives one extra point.

Then:

edges = coo_matrix((ones_ntris, (x, y)), shape=(npoints, npoints))

Which I interpreted as adding a '1' at element (x[i],y[i]) of 'edges' each
time (x[i],y[i]) appears in (x,y), like in this example on constructing a
matrix using ijv format
<https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html>
.

However, since the largest element of 'tris' is np.max(tris), why are
there nonzero entries for the (np.max(tris) + 1)th row/col in the
'edges' matrix?

Should I be using edges[0:npoints-1,0:npoints-1] as my adjacency matrix?

Thanks and Best,

Gladia

try:

tris = stats.rankdata(tris, 'dense').reshape(tris.shape).astype(int) - 1

before calling mesh_edges

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180305/693119e2/attachment.html

Hi Alex,

That gives the same shape for tris as before, and edges is still 642 by 642.

Best,
Gladia

Hi Alex,

To clarify, after calling stats.rankdata, I still have np.max(tris) = 641,
so mesh_edges adds one more point and the shape of edges is still 642 by
642. Does the extra row/column contain adjacency information for vertex
number 642? I'm still confused by this, since 642 is not an entry in tris.

Best,
Gladia

indexing starts at 0 in Python so np.max(tris) = 641 means 642 points.

does it help?

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180307/9f37b5d1/attachment.html

Hi Alex,

Oh right, got it! Thanks!

Best,
Gladia