<div dir="ltr">Hello Maria,<div><br></div><div>I haven&#39;t done this with evoked sensor data, only with STCs. However, as long as evoked data also have an &#39;add&#39; 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[&#39;SAMPLE&#39;] + &#39;/stcs_ica/&#39; + condition</div><div><br></div><div><span class="" style="white-space:pre">        </span># template for the names of the STCs (I&#39;m only doing left hemi here)</div><div><span class="" style="white-space:pre">        </span>fname = os.path.join( stcdir, &#39;%s-&#39; + condition + &#39;-free-lh.stc&#39; )</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 = &#39;fsaverage&#39;</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&#39;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">&lt;<a href="mailto:maria.hakonen@gmail.com" target="_blank">maria.hakonen@gmail.com</a>&gt;</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(&quot;filename-ave.fif&quot;)<br><br>and loaded as:<br><br>evoked = mne.read_evokeds(&quot;filename-ave.fif&quot;)<br><br>evoked doesn&#39;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/&lt;ipython-input-65-f6e26a212f6a&gt; in &lt;module&gt;()<br>----&gt; 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>-&gt; 2373         return _wrapit(a, &#39;mean&#39;, 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>---&gt; 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 /: &#39;Evoked&#39; and &#39;float&#39;<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>