[Mne_analysis] Evoked setno = 0 in MNE python
Martin Luessi
mluessi at nmr.mgh.harvard.edu
Wed Sep 12 14:12:50 EDT 2012
Kambiz,
See below for my response.
On 09/11/12 18:32, Kambiz Tavabi wrote:
> 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?
Yes, this looks correct to me, it will give you a .mat file with the
mean for each label. I guess this makes sense if you want to use Matlab
for the rest of your processing ;)
> 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?
I'm not sure what you mean by "traces", the mean of each label will just
be a single time series, do you mean averaging the label time series?
A problem is that the sign flip vector is computed for each label
separately and if you combine labels, the time series may still
partially cancel. What the best way is to average over a label is kind
of an open question, for small labels the sign flip trick works, but if
the label becomes very large it does not make much sense. In general, it
may not make much sense to try to represent the whole label by a single
time series..
Something you could try is to weight the time series of each label by
the number of vertices, i.e,
ts_comb = (n_vert_a * ts_label_a + n_vert_b * ts_label_b) / (n_vert_a +
n_vert_b)
where n_vert_a, ts_label_a, n_vert_b, ts_label_b, are the number of
vertices and the time series of label A and B, resp. This will be more
similar to the case where you computed the average over a larger label
with A and B combined (it will be the same if "flip" is all 1).
I hope this helps.
Best,
Martin
PS: There is currently work on the way that will make it easier to
extract label time series from stc's and also will allow you to combine
labels, see https://github.com/mne-tools/mne-python/pull/90
> 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.
>>>>
>>>
>>>
>>
>>
>>
>>
>>
>
>
>
2
More information about the Mne_analysis
mailing list