[Mne_analysis] Grand average of evoked files?

Stephen Politzer-Ahles spa268 at nyu.edu
Thu Sep 11 07:58:32 EDT 2014
Search archives:

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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140911/d5bff4bd/attachment.html 


More information about the Mne_analysis mailing list