[Mne_analysis] Evoked setno = 0 in MNE python

Kambiz Tavabi ktavabi at uw.edu
Tue Sep 11 18:32:19 EDT 2012
Search archives:

Hi Martin,
May we revisit the sign flip method of getting to the mean activation
in a label. I am trying compute & visualize the mean activation for a
set of labels (e.g., ['G_temp_sup-Lateral-lh',
'G_temporal_middle-lh']). Ideally I would like to use the sign flip to
compute the mean across all vertices in the set of labels, trying to
get at the effective number of averages across labels of differing
size. Is this possible? I cannot for the life of me figure the python
syntax to do this. I am pretty sure it is because I cannot concatenate
the various values(mxtimes) arrays from: values, times, vertices =
mne.label_time_courses(label_fname, stc_fname); in matlab I would do
this using a cell array, but I can't figure out the python equivalent.
The routine I am working with is:
fif_events = [1,2,3,5]
labels = ['G_temp_sup-Lateral-lh', 'G_temporal_middle-lh',
'G_front_inf-Opercular-lh', 'G_front_inf-Triangul-lh']
for m, n in enumerate(fif_events):
    print m, n
    stc_fname = cmd.getoutput('find . -type f -name
"*rawMove1-gave-20Hz_dSPM_set-%i*-lh.stc" -printf "%%f\n"' % (n))
#conditional stc files
    for j,k in enumerate(labels):
       label_fname = freesurfer_dir + x + '/label/' + k + '.label'
       values, times, vertices = mne.label_time_courses(label_fname, stc_fname)
       print "Number of vertices : %d" % len(vertices)
       label = mne.read_label(label_fname)
       flip = mne.label_sign_flip(label, inv['src'])
       label_mean = np.mean(flip[:, None] * values, axis=0)
       out_fname = (stc_fname[:-4] + "_%s.mat" % (k))
       scipy.io.savemat(out_fname, mdict={'label': k, 'data':
label_mean, 'times': times}) #output label_mean to matlab column
vector; IS THIS CORRECT?

At the moment, this routine computes label_mean and outputs matlab
file for each label in  ['G_temp_sup-Lateral-lh',
'G_temporal_middle-lh', 'G_front_inf-Opercular-lh',
'G_front_inf-Triangul-lh'] and condition in fif_events = [1,2,3,5].
Then I compute the mean activity across two (or more) labels by
averaging their traces, which I suppose is not optimal. Any
suggestions?

Thanks in advance
Kam


On Fri, Aug 10, 2012 at 1:50 PM, Martin Luessi
<mluessi at nmr.mgh.harvard.edu> wrote:
> Kam,
>
>
> On 08/10/12 16:32, Kambiz Tavabi wrote:
>>
>> Martin,
>>
>> Thanks for your response. In the past I have used the MNE command line
>> tools to work. I didn't recall the mne_do_inverse_operator program
>> requiring a setno argument. In any case, for the data in question I
>> computed the noise cov matrix using a cov description file defining all
>> the events in my dataset(s). I presume this is what you mean by using
>> all different sets to compute the noise cov matrix?
>
>
> Yes, this is what I meant.
>
>
>> I also recall that the MNE command line tools to create STC files
>> required specific set number arguments to compute and visualize
>> solutions. So I must loop through the different conditions to create STC
>> files. That makes sense.
>
>
> Correct.
>
>
>> What I still don't get is why the python tutorials use setno=0, and not
>> a number between 1 and 4 which corresponds to the conditions in the
>> sample_audvis-ave.fif dataset, as well as the category event definitions
>> in audvis.ave in the sample dataset. Does the numbering for setno
>> argument begin from 0 or 1?
>
>
> Its starts with 0. In Python, indices start with 0, so it makes sense.
>
>
>> Also, thanks for the flip trick code, I haven't tried it yet but you'll
>> likely be hearing from me again soon on the list.
>
>
> You're welcome. We should add some code to mne-python to simplify the
> averaging over labels. I add it to my todo list.
>
> Best,
>
> Martin
>
>
>> cheers
>> Kam
>>
>> On 08/10/2012 07:25 AM, Martin Luessi wrote:
>>>
>>> Kam,
>>>
>>> See my answers below.
>>> On 08/10/12 01:57, Kambiz Tavabi wrote:
>>>>
>>>> Hello list,
>>>> I am a bit confused about a couple instances of defining setno = 0 while
>>>> loading evoked data in the context of (1) computing an inverse operator
>>>> & (2) computing inverse solution on evoked data, using MNE-python. The
>>>> exact line is as follows; evoked = Evoked(fname_evoked, setno=0,
>>>> baseline=(None, 0)). What does this mean? Does setno = 0 in above (1)
>>>> default to an inverse operator for each condition in the evoked data
>>>> set; and similarly does setno=0 result in an stc file for all conditions
>>>> in (2). If I am wrong, then should I be looping through condition
>>>> numbers?
>>>
>>>
>>> The MNE command line tools can create .fif files with multiple evoked
>>> responses. If you look at the sample data set, there is is a file
>>> "audvis.ave", which specifies the averaging preferences. The resulting
>>> "sample_audvis-ave.fif" contains four evoked responses, one for each
>>> condition.
>>>
>>> In mne-python, an Evoked object can only contain a single evoked
>>> response. So when loading a .fif file produced with MNE that contains
>>> multiple responses (sets), you have to use "setno" to specify which
>>> one to load. At this point mne-python doesn't support writing evoked
>>> .fif files with multiple sets.
>>>
>>> This is not directly related to the inverse operator. Assuming you
>>> compute the inverse operator using a noise covariance matrix computed
>>> using all the different sets, you can use it for all the evoked
>>> responses in the same .fif file (as they all have the same measurement
>>> information).
>>>
>>>> And, in python for dummies lingo, how does one compute the mean
>>>> activation time series in a label?
>>>
>>>
>>> If you have a label file and an .stc file, you can use
>>> mne.label_time_courses() to get the time courses for a label, it will
>>> return the time courses for all vertices in the label. You then can
>>> simply average the time courses, or use the sign flip trick, i.e.,
>>>
>>> values, times, vertices = label_time_courses(label_fname, stc_fname)
>>>
>>> label = mne.read_label(label_fname)
>>> flip = mne.label_sign_flip(label, inv['src'])  # inv is the inverse op.
>>>
>>> label_mean = np.mean(flip[:, None] * values, axis=0)
>>>
>>> "flip" is a vector with +1 and -1 values, one for each time course in
>>> the label. It is computed using the orientation of the vertices. This
>>> is the same way MNE computes label averages.
>>>
>>> I hope this helps,
>>>
>>> Martin
>>>
>>>
>>>
>>>> FYI the argument setno=0 is used in tutorials found @:
>>>>
>>>> http://martinos.org/mne/auto_examples/inverse/plot_make_inverse_operator.html
>>>>
>>>>
>>>> http://martinos.org/mne/auto_examples/inverse/plot_compute_mne_inverse.html
>>>>
>>>>
>>>> Thanks in advance
>>>> Kam
>>>> _______________________________________________
>>>> Mne_analysis mailing list
>>>> Mne_analysis at nmr.mgh.harvard.edu
>>>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>>>
>>>>
>>>
>>>
>>> -
>>>
>>>
>>>
>>> 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.
>>>
>>
>>
>
>
>
>
>



-- 
------------------------------------------------------------
Kambiz Tavabi PhD
Institute for Learning & Brain Sciences
1715 Columbia Road N
Portage Bay Building
Box 357988
University of Washington
Seattle, WA 98195-7988
Tel: 206-221-6415
------------------------------------------------------------



More information about the Mne_analysis mailing list