[Mne_analysis] Generating labels with mne_python

Luke Bloy luke.bloy at gmail.com
Fri Aug 23 17:19:21 EDT 2013
Search archives:

Hi Everyone,

I put together a quick example of generating labels in case others end up
with a similar problem.

Enjoy.
Luke


On Fri, Aug 9, 2013 at 2:34 PM, Luke Bloy <luke.bloy at gmail.com> wrote:

> 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
>
>
> On Wed, Aug 7, 2013 at 4:58 PM, Eric Larson <larson.eric.d at gmail.com>wrote:
>
>> 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
>>
>>
>>
>> On Wed, Aug 7, 2013 at 12:50 PM, Martin Luessi <
>> mluessi at nmr.mgh.harvard.edu> wrote:
>>
>>> Hi Luke,
>>>
>>> On 08/07/13 15:40, Luke Bloy wrote:
>>> > 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:
>>>
>>> https://github.com/nipy/PySurfer/pull/53
>>>
>>> Best,
>>>
>>> Martin
>>>
>>>
>>> > Luke
>>> >
>>> > -----Original Message-----
>>> > 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
>>> >
>>> > On 08/07/13 13:57, Luke Bloy wrote:
>>> >> 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
>>> >> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>> >>
>>> >
>>> >
>>> > --
>>> > 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 http://www.partners.org/complianceline . 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
>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20130823/4447342a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: functionalLabelExample.py
Type: application/octet-stream
Size: 6426 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20130823/4447342a/attachment.obj 


More information about the Mne_analysis mailing list