[Mne_analysis] Finding nearest neighbors with 'use_tris'?

Eric Larson larson.eric.d at gmail.com
Wed May 12 07:20:44 EDT 2021
Search archives:

        External Email - Use Caution        

The distances between sources in a given hemisphere are computed along the
cortical surface (Dijkstra distances). Since the two hemispheres are not
connected, you have to use a different strategy across hemispheres. For
example you could use scipy.spatial.distance.cdist on the
src[0]['rr'][src[0]['vertno']] (left) and src[1]['rr'][src[1]['vertno']]
(right) to get Euclidean distances. I've used this previously for example
to say that any sources within 1 cm Euclidean distance between the hemis
would be considered adjacent/neighbors. For my data it didn't make much
difference that I remember, but for medial sources (since there is some
ambiguity there) it might help.

Given that you want something like this and I've used it before, feel free
to open an MNE-Python issue on GitHub about adding some new function to add
this cross-hemisphere connectivity since it seems like it might be useful
for others, too. And if you're up for making a PR to add it, that's even
better!

Eric


On Wed, May 12, 2021 at 12:12 AM Gladia Hotan <gladiach at gmail.com> wrote:

>         External Email - Use Caution
>
> Hi Eric,
>
> Thanks for your help! This function seems to add distances between sources
> in the same hemisphere. Is there a way to get the distances between sources
> in different hemispheres?
>
> Best,
> Gladia
>
> On Fri, Apr 23, 2021 at 10:32 PM Eric Larson <larson.eric.d at gmail.com>
> wrote:
>
>>         External Email - Use Caution
>>
>> Also, I'm using MNE 0.20.7. The function 'spatial_tris_connectivity'
>>> seems to be gone in the latest
>>>
>>> stable MNE (0.22.1). Is there an updated way of getting the nearest neighbors matrix?
>>>
>>> When versions change functions can be deprecated and renamed. For this
>> you'd want to look at the release notes, in this case for both 0.21 and
>> 0.22, to see if something changed, in this case this:
>>
>> *MailScanner has detected a possible fraud attempt from
>> "secure-web.cisco.com" claiming to be*
>> https://secure-web.cisco.com/1H46s6JmjM4BzA3FCwmACkfDaKkpBt44c5tJRdN_p5S5S4Yz8fcL4-FkuoXFY3ECg7SArPubdc1pc4Zh_e0b_t4IYighEoCvE3E8tuqgerdpfgTWiTa2bK4sjWIpIFcrOvnTkYb8GtaxuR3MK7stTUH33bS0N1pQ23_BJvAWST_MOEKsC7y7p-tOCe7eemazRBYVDxkFEpn6NPu7-ZC5so65I2qLfXTMRYTWkMHTOnLmjo1C6giESdm0PU8mf07RGrsKBRLFQi22bRRD_8svIug/https%3A%2F%2Fmne.tools%2Fdev%2Fwhats_new.html%23id6
>> <https://secure-web.cisco.com/1Edhzwz42XchQKf_0yIyY2MkV6nIV_igPALHq6GIBc0mh138b-w9G2oKnyxQt571p2TEGVTs-DwTxVJ2QwXyI0eyU7aK0UelYolh7GLByaoBOM2X7lR1urySDFkLlBYG2sMr_87qs1yJxzW6YHeFam6Ht98v2LrZ-lZ0Sa5OdNmPW8V2PW7JL7gwgPGwMQWCIVY5W_If8HGgHH5mF8F6R-EfLtMSHE3dm20G5mkkORTibBYvK3Nse5jwSMEIMwhJY3J_TZ6zz6UmI3W-vnQGufQ/https%3A%2F%2Fmne.tools%2Fdev%2Fwhats_new.html%23id6>
>>
>> Suggests you should do something like:
>>
>> >>> src = mne.setup_source_space('sample', spacing='ico3', subjects_dir='/home/larsoner/mne_data/MNE-sample-data/subjects', add_dist=False)
>> >>> mne.spatial_src_adjacency(src)
>> <1284x1284 sparse matrix of type '<class 'numpy.int64'>'
>>     with 8964 stored elements in COOrdinate format>
>>
>> Or you could use remap_vertices to use the tris function if you want (but
>> I find the above code to be cleaner):
>>
>> >>> mne.spatial_tris_adjacency(src[0]['use_tris'], remap_vertices=True)
>> <642x642 sparse matrix of type '<class 'numpy.int64'>'
>>     with 4482 stored elements in COOrdinate format>
>>
>> Eric
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> *MailScanner has detected a possible fraud attempt from
>> "secure-web.cisco.com" claiming to be*
>> https://secure-web.cisco.com/1S_979g4bUzOdpjoDHAJjlDgrEzGvVxZKuHamoJP-sO6F5fczrdL4OX7j-6m2zplYs5IrEhisfXH0n3FMqFUs7uftUUCNvoUGnL5FOuKqJ4SPm1gSnsaXPP28JDC6thPAQ6PmKGM-q47Am-7LS-Y9o2RI6rziER-GjX19IjXBqhjfKxKEH8oE7esc8rGJLz8tD5fI3MGyILD4O6UNQEi4BH_eoR2iEXttA3Hfiqb3RWCovTKbCb6nPpUJWow8MqTLpPA4Dhne3O-oUywve26lIw/https%3A%2F%2Fmail.nmr.mgh.harvard.edu%2Fmailman%2Flistinfo%2Fmne_analysis
>> <https://secure-web.cisco.com/1Y0U4QOZCNKFE0piEBTADI_l8_CUQZea1jEzuhIjy6JYgPGHcmxR40Co3AmGVlnTzdM7chDBPpZUN0Mk-a_Y38ZrtpG83n11c3wONbSp4yKaMJE_jkVUXklGRpHukxBo5LwY4-oHEpwgYASXMokFR-vcQYTVaGOfsIQb9vSSO7GuVdmr0Xc0ax4Pwl5IXJl_VWRNs7A-W7sJBsQP44UpYxgH0TtHRozkSZpDja67RrGiT1PeD-PuTzrHjeSUQLcJeh-5kGtg3b_85C9q4rRidGw/https%3A%2F%2Fmail.nmr.mgh.harvard.edu%2Fmailman%2Flistinfo%2Fmne_analysis>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://secure-web.cisco.com/1S_979g4bUzOdpjoDHAJjlDgrEzGvVxZKuHamoJP-sO6F5fczrdL4OX7j-6m2zplYs5IrEhisfXH0n3FMqFUs7uftUUCNvoUGnL5FOuKqJ4SPm1gSnsaXPP28JDC6thPAQ6PmKGM-q47Am-7LS-Y9o2RI6rziER-GjX19IjXBqhjfKxKEH8oE7esc8rGJLz8tD5fI3MGyILD4O6UNQEi4BH_eoR2iEXttA3Hfiqb3RWCovTKbCb6nPpUJWow8MqTLpPA4Dhne3O-oUywve26lIw/https%3A%2F%2Fmail.nmr.mgh.harvard.edu%2Fmailman%2Flistinfo%2Fmne_analysis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20210512/7da550ef/attachment-0001.html 


More information about the Mne_analysis mailing list