<div dir="ltr">Hello Maria,<div><br></div><div>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:</div><div><br></div><div><br></div><div><div><br></div><div>stc_avgs = dict()</div><div><br></div><div><br></div><div># get a grand average for each condition (I defined a dictionary of conditions earlier)</div><div>for condition in conditions.keys():</div><div><br></div><div><span class="" style="white-space:pre">        </span># where all my STCs for each participant in this condition are stored</div><div><span class="" style="white-space:pre">        </span>stcdir = os.environ['SAMPLE'] + '/stcs_ica/' + condition</div><div><br></div><div><span class="" style="white-space:pre">        </span># template for the names of the STCs (I'm only doing left hemi here)</div><div><span class="" style="white-space:pre">        </span>fname = os.path.join( stcdir, '%s-' + condition + '-free-lh.stc' )</div><div><br></div><div><span class="" style="white-space:pre">        </span># use a list comprehension to read in the STC for each subject; I defined a list of participants earlier)</div><div><span class="" style="white-space:pre">        </span>stcs = [mne.read_source_estimate(fname % subject) for subject in participants]</div><div><br></div><div><span class="" style="white-space:pre">        </span># math out the grand average</div><div><span class="" style="white-space:pre">        </span>stc_avg = reduce(add, stcs)</div><div><span class="" style="white-space:pre">        </span>stc_avg /= len(stcs)</div><div><br></div><div><span class="" style="white-space:pre">        </span># put the grand average for this condition into a dictionary of all the conditions</div><div><span class="" style="white-space:pre">        </span>stc_avg.subject = 'fsaverage'</div><div><span class="" style="white-space:pre">        </span>stc_avgs[condition] = stc_avg</div></div><div><br></div><div><br></div><div><br></div><div>(however, Mainak's solution, if it works, looks much simpler!)</div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><div><br><br></div>Stephen Politzer-Ahles<br>New York University, Abu Dhabi<br>Neuroscience of Language Lab<br><a href="http://www.nyu.edu/projects/politzer-ahles/" target="_blank">http://www.nyu.edu/projects/politzer-ahles/</a><br></div></div>
<br><div class="gmail_quote">On Thu, Sep 11, 2014 at 3:47 PM, Maria Hakonen <span dir="ltr"><<a href="mailto:maria.hakonen@gmail.com" target="_blank">maria.hakonen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<br><br>I would like to compute a grand average of evoked files.<br><br>It seems to work as: grand_ave = np.mean([evoked1.data, evoked2.data, evoked3.data],1)<br><br>However, the problem is that if the evoked data is saved as: <br><br>evoked.save("filename-ave.fif")<br><br>and loaded as:<br><br>evoked = mne.read_evokeds("filename-ave.fif")<br><br>evoked doesn't have attribute data.<br><br>I also tried:<br>grand_ave = np.mean([evoked1, evoked2, evoked3],1)<br><br>but this gives an error:<br><br>TypeError Traceback (most recent call last)<br>/scratch/braindata/mhhakone/intell/<ipython-input-65-f6e26a212f6a> in <module>()<br>----> 1 grand_ave = np.mean([evoked1, evoked2, evoked3],1)<br><br>/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in mean(a, axis, dtype, out)<br> 2371 mean = a.mean<br> 2372 except AttributeError:<br>-> 2373 return _wrapit(a, 'mean', axis, dtype, out)<br> 2374 return mean(axis, dtype, out)<br> 2375 <br><br>/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in _wrapit(obj, method, *args, **kwds)<br> 35 except AttributeError:<br> 36 wrap = None<br>---> 37 result = getattr(asarray(obj),method)(*args, **kwds)<br> 38 if wrap:<br> 39 if not isinstance(result, mu.ndarray):<br><br>TypeError: unsupported operand type(s) for /: 'Evoked' and 'float'<br><br><br><br>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.)<br>Or is there some better way to calculate the grand average of -ave.fif files?<br><br>Thanks already in advance!<br><br>Regards,<br>Maria <br></div>
<br>_______________________________________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu">Mne_analysis@nmr.mgh.harvard.edu</a><br>
<a href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis" target="_blank">https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis</a><br>
<br>
<br>
The information in this e-mail is intended only for the person to whom it is<br>
addressed. If you believe this e-mail was sent to you in error and the e-mail<br>
contains patient information, please contact the Partners Compliance HelpLine at<br>
<a href="http://www.partners.org/complianceline" target="_blank">http://www.partners.org/complianceline</a> . If the e-mail was sent to you in error<br>
but does not contain patient information, please contact the sender and properly<br>
dispose of the e-mail.<br>
<br></blockquote></div><br></div>