<div dir="ltr"><div>Hi Maria,<br><br></div>The simplest solution here is to do:<br><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 11, 2014 at 5:31 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>Thank you for answers!</div><div><br></div><div>I tried Mainak's solution but it gives</div><div><br></div><div>grand_ave = evoked1+evoked2 +evoked3 <br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div>grand_ave:</div><div>[<Evoked | comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs : 160, n_channels x n_times : 306 x 721>,</div><div> <Evoked | comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs : 160, n_channels x n_times : 306 x 721>,</div><div> <Evoked | comment : 'Unknown', time : [-0.099994, 0.499968], n_epochs : 160, n_channels x n_times : 306 x 721>]</div><div><br></div><div>I think that I should get only one evoked if this works correctly.</div></div></blockquote><div><br>grand_ave = evoked1[0] + evoked2[0] + evoked3[0]<br><br><div>so
that you extract the first element of the list. Or you can read in
your evoked object using:<br><br>evoked = mne.read_evokeds('filename-ave.fif', 0)<br><br></div><div>and then do grand_ave = evoked1 + evoked2 + evoked3<br></div><br> This should be ok if
you know that your files contain only one condition. Is that the case?<br><br>Mainak<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div>Maybe I should try Stephen's solution if there is no simpler ones.</div><span class=""><font color="#888888"><div><br></div><div>-Maria</div></font></span></div><div class=""><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2014-09-11 14:58 GMT+03:00 Stephen Politzer-Ahles <span dir="ltr"><<a href="mailto:spa268@nyu.edu" target="_blank">spa268@nyu.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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 style="white-space:pre-wrap">        </span># where all my STCs for each participant in this condition are stored</div><div><span style="white-space:pre-wrap">        </span>stcdir = os.environ['SAMPLE'] + '/stcs_ica/' + condition</div><div><br></div><div><span style="white-space:pre-wrap">        </span># template for the names of the STCs (I'm only doing left hemi here)</div><div><span style="white-space:pre-wrap">        </span>fname = os.path.join( stcdir, '%s-' + condition + '-free-lh.stc' )</div><div><br></div><div><span style="white-space:pre-wrap">        </span># use a list comprehension to read in the STC for each subject; I defined a list of participants earlier)</div><div><span style="white-space:pre-wrap">        </span>stcs = [mne.read_source_estimate(fname % subject) for subject in participants]</div><div><br></div><div><span style="white-space:pre-wrap">        </span># math out the grand average</div><div><span style="white-space:pre-wrap">        </span>stc_avg = reduce(add, stcs)</div><div><span style="white-space:pre-wrap">        </span>stc_avg /= len(stcs)</div><div><br></div><div><span style="white-space:pre-wrap">        </span># put the grand average for this condition into a dictionary of all the conditions</div><div><span style="white-space:pre-wrap">        </span>stc_avg.subject = 'fsaverage'</div><div><span style="white-space:pre-wrap">        </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><span><font color="#888888"><div><br></div><div><br></div></font></span></div><div class="gmail_extra"><span><font color="#888888"><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></font></span><div class="gmail_quote"><span>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></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><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></div></div><span>_______________________________________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">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></span></blockquote></div><br></div>
<br>_______________________________________________<br>
Mne_analysis mailing list<br>
<a href="mailto:Mne_analysis@nmr.mgh.harvard.edu" target="_blank">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>
</div></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></div></div></div>