[Mne_analysis] Grand average of evoked files?

Denis-Alexander Engemann denis.engemann at gmail.com
Thu Sep 11 11:47:40 EDT 2014
Search archives:

Hi,

2014-09-11 17:14 GMT+02:00 Maria Hakonen <maria.hakonen at gmail.com>:

> Hi,
>
> Is there any function that returns the evoked data array?
>

If you have evokeds saved in a fiff you can just read them.
If you know the exact condition you want you can pass it to the condition
parameter in mne.read_evokeds and the evoked will be returned without the
list.

You can also compute the grand average on a list of evokeds

grand_evoked = np.sum(evokeds)


> I have made ica on epochs, evoked them and saved the evoked data. Can I
> use the evoked files in mne python analyses (I would like to try for
> example permutation t-test on source data with spatio-temporal clustering
> and plot grand averages) or should I make ica on raw data?
>

I would compute ICA on raw data which you can then apply at any later stage
(raw, epochs, evoked).

-Denis


>
> -Maria
>
>
> 2014-09-11 17:36 GMT+03:00 Denis-Alexander Engemann <
> denis.engemann at gmail.com>:
>
>> Maria,
>>
>> I think your trouble is related to the fact that you add together lists,
>> not evokeds.
>> The read_evokeds function returns a list by default. This is because it
>> assumes to find multiple evokeds in one file.
>>
>> HTH,
>> Denis
>>
>> 2014-09-11 16:31 GMT+02:00 Maria Hakonen <maria.hakonen at gmail.com>:
>>
>>> Hi,
>>>
>>> Thank you for answers!
>>>
>>> I tried Mainak's solution but it gives
>>>
>>> grand_ave = evoked1+evoked2 +evoked3
>>>
>>> grand_ave:
>>> [<Evoked  |  comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs
>>> : 160, n_channels x n_times : 306 x 721>,
>>>  <Evoked  |  comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs
>>> : 160, n_channels x n_times : 306 x 721>,
>>>  <Evoked  |  comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs
>>> : 160, n_channels x n_times : 306 x 721>]
>>>
>>> I think that I should get only one evoked if this works correctly.
>>>
>>> Maybe I should try Stephen's solution if there is no simpler ones.
>>>
>>> -Maria
>>>
>>>
>>> 2014-09-11 14:58 GMT+03:00 Stephen Politzer-Ahles <spa268 at nyu.edu>:
>>>
>>>> Hello Maria,
>>>>
>>>> I haven't done this with evoked sensor data, only with STCs. However,
>>>> as long as evoked data also have an 'add' method, I imagine something like
>>>> this should work for you as well:
>>>>
>>>>
>>>>
>>>> stc_avgs = dict()
>>>>
>>>>
>>>> # get a grand average for each condition (I defined a dictionary of
>>>> conditions earlier)
>>>> for condition in conditions.keys():
>>>>
>>>> # where all my STCs for each participant in this condition are stored
>>>> stcdir = os.environ['SAMPLE'] + '/stcs_ica/' + condition
>>>>
>>>> # template for the names of the STCs (I'm only doing left hemi here)
>>>> fname = os.path.join( stcdir, '%s-' + condition + '-free-lh.stc' )
>>>>
>>>> # use a list comprehension to read in the STC for each subject; I
>>>> defined a list of participants earlier)
>>>> stcs = [mne.read_source_estimate(fname % subject) for subject in
>>>> participants]
>>>>
>>>> # math out the grand average
>>>> stc_avg = reduce(add, stcs)
>>>> stc_avg /= len(stcs)
>>>>
>>>> # put the grand average for this condition into a dictionary of all the
>>>> conditions
>>>> stc_avg.subject = 'fsaverage'
>>>> stc_avgs[condition] = stc_avg
>>>>
>>>>
>>>>
>>>> (however, Mainak's solution, if it works, looks much simpler!)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Stephen Politzer-Ahles
>>>> New York University, Abu Dhabi
>>>> Neuroscience of Language Lab
>>>> http://www.nyu.edu/projects/politzer-ahles/
>>>>
>>>> On Thu, Sep 11, 2014 at 3:47 PM, Maria Hakonen <maria.hakonen at gmail.com
>>>> > wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I would like to compute a grand average of evoked files.
>>>>>
>>>>> It seems to work as: grand_ave = np.mean([evoked1.data, evoked2.data,
>>>>> evoked3.data],1)
>>>>>
>>>>> However, the problem is that if the evoked data is saved as:
>>>>>
>>>>> evoked.save("filename-ave.fif")
>>>>>
>>>>> and loaded as:
>>>>>
>>>>> evoked = mne.read_evokeds("filename-ave.fif")
>>>>>
>>>>> evoked doesn't have attribute data.
>>>>>
>>>>> I also tried:
>>>>> grand_ave = np.mean([evoked1, evoked2, evoked3],1)
>>>>>
>>>>> but this gives an error:
>>>>>
>>>>> TypeError                                 Traceback (most recent call
>>>>> last)
>>>>> /scratch/braindata/mhhakone/intell/<ipython-input-65-f6e26a212f6a> in
>>>>> <module>()
>>>>> ----> 1 grand_ave = np.mean([evoked1, evoked2, evoked3],1)
>>>>>
>>>>> /usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in mean(a,
>>>>> axis, dtype, out)
>>>>>    2371         mean = a.mean
>>>>>    2372     except AttributeError:
>>>>> -> 2373         return _wrapit(a, 'mean', axis, dtype, out)
>>>>>    2374     return mean(axis, dtype, out)
>>>>>    2375
>>>>>
>>>>> /usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in
>>>>> _wrapit(obj, method, *args, **kwds)
>>>>>      35     except AttributeError:
>>>>>      36         wrap = None
>>>>> ---> 37     result = getattr(asarray(obj),method)(*args, **kwds)
>>>>>      38     if wrap:
>>>>>      39         if not isinstance(result, mu.ndarray):
>>>>>
>>>>> TypeError: unsupported operand type(s) for /: 'Evoked' and 'float'
>>>>>
>>>>>
>>>>>
>>>>> How can I get data from -ave.fif files? (The -ave.fif files I have
>>>>> saved seems to open correctly in xFit, Matlab and mne_analyze.)
>>>>> Or is there some better way to calculate the grand average of -ave.fif
>>>>> files?
>>>>>
>>>>> Thanks already in advance!
>>>>>
>>>>> Regards,
>>>>> Maria
>>>>>
>>>>> _______________________________________________
>>>>> 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.
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> 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.
>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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.
>>>
>>>
>>
>> _______________________________________________
>> 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.
>>
>>
>
> _______________________________________________
> 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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140911/5f79f4e1/attachment.html 


More information about the Mne_analysis mailing list