I am interested in generating a label from an stc. What I would like is to
be able to supply a seed and a threshold, and to get as output a label
consisting of the source points connected to the seed and above threshold.
Basically I'd like to be able to compute connected components on stcs. Has
this been implemented? If not could someone maybe help me out by pointing to
how I could get neighborhood information from the src space? Alternatively,
can someone think of a way to combine thresholding stc.data with
mne.label.grow_label to do what I want?
A second easier question. Is there an simple way to show labels on a
pysurfer plot. At the moment I'm generating the label, then saving it to
disk and using 'brain.add_label' to load the label from disk. Is there a
more straight forward way that I'm missing.
MNE-Python currently doesn't have a function that does exactly what you
want, but it should be possible to put something together to get the
desired result. I would do something like this:
1) Use mne.spatial_src_connectivity to get a connectivity matrix that
describes the neighbor relations in source space. The "src" parameter is
the source space, e.g., "inv['src']", where inv is your inverse operator.
2) Use mne.stats._find_clusters and pass in "stc.data[:, idx]" where idx
selects a single time point. This function will return a list of
clusters (connected components)
3) For each cluster, generate a SourceEstimate using the original source
space (so stc_cluster.vertices is the same as in stc). Set the data of
stc_cluster to all-zero except inside the cluster (use e.g. 1.0). Pass
stc_cluster to mne.stc_to_label to generate a Label from it. Save the
labels, add it to a list, etc.
What's the best way to expose mne.stats._find_clusters to my code. I'd
rather not fiddle with ../stats/__init.py if I can avoid it.
use
from mne.stats.cluster_level import _find_clusters
what I wrote below (mne.stats._find_clusters) doesn't work because the
function is not directly visible from mne.stats. Also, not that the
leading "_" indicates that this is a "private function", i.e., it is
only used internally in MNE-Python and the API may change from one
release to the next without notification. But this code is fairly
stable, so this shouldn't be a problem.
Also, I forgot to answer your second question. You currently have to
save the label as a file to show it in PySurfer. There is work in the
pipeline to make it possible to pass labels directly, see:
FYI, the branch for PySurfer to handle mne-python's label objects has
actually already been merged, the linked PR is for a different (much
bigger) can of worms... you should be able to do Brain.add_label(label)
once you've loaded
If you don't want to deal with the private _find_clusters functions, you
should also be able to use the standard statistical clustering functions,
but just use a dummy stat_fun (instead of e.g., ttest_1samp). If you can't
figure it out, give me a shout and I can probably write a few lines of code
for it.
I put together a quick example of generating labels in case others end up
with a similar problem.
Enjoy.
Luke
Thank you both for the help. I got it working reasonably well.
I might throw together an example, and send it to the list, if i get some
time.
Thanks again,
Luke
FYI, the branch for PySurfer to handle mne-python's label objects has
actually already been merged, the linked PR is for a different (much
bigger) can of worms... you should be able to do Brain.add_label(label)
once you've loaded
If you don't want to deal with the private _find_clusters functions, you
should also be able to use the standard statistical clustering functions,
but just use a dummy stat_fun (instead of e.g., ttest_1samp). If you can't
figure it out, give me a shout and I can probably write a few lines of code
for it.
Eric
Hi Luke,
> Thanks Martin,
>
> What's the best way to expose mne.stats._find_clusters to my code. I'd
> rather not fiddle with ../stats/__init.py if I can avoid it.
use
from mne.stats.cluster_level import _find_clusters
what I wrote below (mne.stats._find_clusters) doesn't work because the
function is not directly visible from mne.stats. Also, not that the
leading "_" indicates that this is a "private function", i.e., it is
only used internally in MNE-Python and the API may change from one
release to the next without notification. But this code is fairly
stable, so this shouldn't be a problem.
Also, I forgot to answer your second question. You currently have to
save the label as a file to show it in PySurfer. There is work in the
pipeline to make it possible to pass labels directly, see:
> Luke
>
> From: Martin Luessi [mailto:mluessi at nmr.mgh.harvard.edu]
> Sent: Wednesday, August 07, 2013 2:24 PM
> To: Luke Bloy
> Cc: mne_analysis at nmr.mgh.harvard.edu
> Subject: Re: [Mne_analysis] Generating labels with mne_python
>
> Hi Luke,
>
> MNE-Python currently doesn't have a function that does exactly what you
> want, but it should be possible to put something together to get the
desired
> result. I would do something like this:
>
> 1) Use mne.spatial_src_connectivity to get a connectivity matrix that
> describes the neighbor relations in source space. The "src" parameter
is the
> source space, e.g., "inv['src']", where inv is your inverse operator.
>
> 2) Use mne.stats._find_clusters and pass in "stc.data[:, idx]" where
idx
> selects a single time point. This function will return a list of
clusters
> (connected components)
>
> 3) For each cluster, generate a SourceEstimate using the original
source
> space (so stc_cluster.vertices is the same as in stc). Set the data of
> stc_cluster to all-zero except inside the cluster (use e.g. 1.0). Pass
> stc_cluster to mne.stc_to_label to generate a Label from it. Save the
> labels, add it to a list, etc.
>
> I hope this helps,
>
> Martin
>
>> Hi all,
>>
>> I am interested in generating a label from an stc. What I would like
>> is to be able to supply a seed and a threshold, and to get as output a
>> label consisting of the source points connected to the seed and above
>> threshold. Basically I'd like to be able to compute connected
>> components on stcs. Has this been implemented? If not could someone
>> maybe help me out by pointing to how I could get neighborhood
>> information from the src space? Alternatively, can someone think of a
>> way to combine thresholding stc.data with mne.label.grow_label to do
what
> I want?
>>
>> A second easier question. Is there an simple way to show labels on a
>> pysurfer plot. At the moment I'm generating the label, then saving it
>> to disk and using 'brain.add_label' to load the label from disk. Is
>> there a more straight forward way that I'm missing.
>>
>> Thanks
>>
>> Luke
>>
>>
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> Mne_analysis Info Page
>>
>
>
> --
> Martin Luessi, Ph.D.
>
> Research Fellow
>
> Department of Radiology
> Athinoula A. Martinos Center for Biomedical Imaging Massachusetts
General
> Hospital Harvard Medical School
> 149 13th Street
> Charlestown, MA 02129
>
> Fax: +1 617 726-7422
>
>
> The information in this e-mail is intended only for the person to whom
it is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail contains patient information, please contact the Partners
Compliance
> HelpLine at MyComplianceReport.com: Compliance and Ethics Reporting . If the e-mail
was sent
> to you in error but does not contain patient information, please
contact the
> sender and properly dispose of the e-mail.
>
>
>
--
Martin Luessi, Ph.D.
Research Fellow
Department of Radiology
Athinoula A. Martinos Center for Biomedical Imaging
Massachusetts General Hospital
Harvard Medical School
149 13th Street
Charlestown, MA 02129
Fax: +1 617 726-7422
_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu Mne_analysis Info Page
It sounds like you want to do spatial clustering based on the functional
data. I recently had a similar issue, and I found that I could create a
neighborhood structure using the 'use_tris' information from the source
space (I did this in MATLAB, but I think it can also be done in Python).
Each row of use_tris is three columns long, indicating the vertex numbers
of the three vertices that form a triangle (and thus are adjacent), so it's
possible to go through use_tris and create a dictionary (or similar
structure) listing, for each used vertex in the source space, the vertices
that are adjacent to it. From there it's probably straightforward to make
clusters of adjacent vertices that exceed your threshold based on the stc
data, although I haven't done it myself; what I did for my analysis is just
put that neighbor structure and the source data into a Fieldtrip [ http://fieldtrip.fcdonders.nl/] timelock data structure (just treating the
source vertices as "channels" of sensor data), and used Fieldtrip's
built-in spatiotemporal clustering algorithm to do statistics. (This
somewhat roundabout way may not be strictly necessary--I've seen some
example Python code on mne-python for temporal-spectral clustering of
source data, for example, but haven't used it myself.)