Grand average of evoked files?

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

Hi Maria,

I think you should make use of "evoked arithmetic". Simply doing

grand_ave = evoked1 + evoked2 + evoked3

should work. It takes into account the number of epochs while averaging.

Mainak

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/

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/

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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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/188e6210/attachment.html

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/

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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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/0423f84c/attachment.html

Hello Everybody,
During my experiment I recorded 2 blocs per subject. I am just started
with mne_python.

I have two questions in one ::
1) I would like to know how can I concatenate the blocs and above all
the events (corresponding to each bloc) to have just one bloc.
In brief, for each subject I have one bloc with its events and another
bloc with its events also.

raw_fname1= '...'
raw_fname2= '...'
event_fname1= '...'
event_fname2= '...'

raw1 = io.Raw(raw_fname1)
raw2 = io.Raw(raw_fname2)

events1 = mne.read_events(event_fname1)
events2 = mne.read_events(event_fname2)
events_list = [events1,events2]

raw_conc= concatenate_raws([raw1,raw2], events_list=events_list)

Until here I think these several code lines work correctly...

2) But when I try to extract the epochs from raw_conc I have some error
messages (concerning I think the events_list)

picks =
mne.pick_types(raw1.info,meg='mag',eeg=False,ecg=False,eog=False,stim=False,
exclude='bads')
epochs = mne.Epochs(raw, events_list, event_id, tmin, tmax, picks=picks,
baseline= baseline, reject=reject)

The aim of both questions is to use the tfr_morlet function which asks
in input the epochs.

power, itc = tfr_morlet(epochs, freqs=freqs, n_cycles=n_cycles,
use_fft=False, return_itc=True, decim=3,n_jobs=1)

Someone has an idea about this?

Bests,

Jonathan

Hi Jonathan,

When you read your raw file, you can pass the function a list of filenames
(instead of one filename) to automatically read all those files into a
single Raw object. Then you shouldn't need to worry about concatenating
later.

Best,
Steve

Stephen Politzer-Ahles
New York University, Abu Dhabi
Neuroscience of Language Lab
http://www.nyu.edu/projects/politzer-ahles/

Thank you Steve,

I suppose something like that:
raws = mne.io.Raw(['raw1_fname','raw2_fname'])

and what about the events??

Bests,
Jonathan

You should be able to read the events straight from the raw object.
(mne.find_events). This is the safest way to deal with events.

HTH
D

Hi,

Is there any function that returns the evoked data array? 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?

-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/

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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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/d899d9d7/attachment.html

Hi D,
I understand but the problem is that I modified manually some number in
the events file and now I not able to extract directly them. Tell me if
I make a mistake. I am a really beginner.

Thanks,
John

Hi John,

Can you explain in more detail what you are trying to do? The original
events are in the raw fif files. Do you want to change them or are you
worried you changed them, or have you already changed them?

(if you already have changed them, where did you change them: in the
raw file? how did you change them? etc.)

HTH,
D

Hi,

I would like, for all the MEG processing, to work only on one big raw
file (that's to say bloc 1 + bloc 2). Concerning the events, I extracted
the events (events.txt) from mne_browse and I modified manually some
values in these files (with Matlab).

So actually, I have 2 blocs with 1 events.txt file each corresponding.
raw_fname1= '...' with event_fname1= '...'
raw_fname2= '...' with event_fname2= '...'

Cheers,
John

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/

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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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

quick question: why np.sum(.) and not np.mean(.)?

2014-09-11 17:49 GMT+02:00 Hari Bharadwaj <hari at nmr.mgh.harvard.edu>:

quick question: why np.sum(.) and not np.mean(.)?

np.sum accesses the evoked.__iadd__ and eovked.__add__ magic methods.

a sum is a reduction function, the same as

reduce(operator.add, [a, b, c, d, e])

if you think of it in terms of iteration,
at each step two evokeds are added as specified by their __add__ method.

Btw. the same logic applies to Label objects,

huge_mega_label = np.sum(label_list)

2014-09-11 17:52 GMT+02:00 Denis-Alexander Engemann <
denis.engemann at gmail.com>:

2014-09-11 17:49 GMT+02:00 Hari Bharadwaj <hari at nmr.mgh.harvard.edu>:

quick question: why np.sum(.) and not np.mean(.)?

np.sum accesses the evoked.__iadd__ and eovked.__add__ magic methods.

a sum is a reduction function, the same as

reduce(operator.add, [a, b, c, d, e])

if you think of it in terms of iteration,
at each step two evokeds are added as specified by their __add__ method.

> 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/
>>>>>
>>>>>
>>>>>> 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
>>>>>> Mne_analysis Info Page
>>>>>>
>>>>>>
>>>>>> 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
>>>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>>>> Mne_analysis Info Page
>>>>>
>>>>>
>>>>> 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
>>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>>> Mne_analysis Info Page
>>>>
>>>>
>>>> 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
>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>> Mne_analysis Info Page
>>>
>>>
>>> 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
>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>> Mne_analysis Info Page
>>
>>
>> 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
>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
> Mne_analysis Info Page

--
Hari Bharadwaj
Post-doctoral Associate,
Center for Computational Neuroscience
  and Neural Technology (CompNet),
Boston University
677 Beacon St.,
Boston, MA 02215

Martinos Center for Biomedical Imaging,
Massachusetts General Hospital
149 Thirteenth Street,
Charlestown, MA 02129

hari at nmr.mgh.harvard.edu
Ph: 734-883-5954
www.haribharadwaj.com

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
Mne_analysis Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140911/b8131469/attachment.html

.... Hari, sorry, I was misreading your question. Of course you will need
to devide by the number of subjects if you use sum.
I was just refering to the functional way to add together a list of evokeds.
np.mean will try to devide the summed evoked by an int, which is not
implemented for evoked types.
To complete the operation, what you have to do is this:

grand_ave = np.sum(evokeds)
grand_ave.data /= len(evokeds)

2014-09-11 17:58 GMT+02:00 Denis-Alexander Engemann <
denis.engemann at gmail.com>:

Btw. the same logic applies to Label objects,

huge_mega_label = np.sum(label_list)

2014-09-11 17:52 GMT+02:00 Denis-Alexander Engemann <
denis.engemann at gmail.com>:

2014-09-11 17:49 GMT+02:00 Hari Bharadwaj <hari at nmr.mgh.harvard.edu>:

quick question: why np.sum(.) and not np.mean(.)?

np.sum accesses the evoked.__iadd__ and eovked.__add__ magic methods.

a sum is a reduction function, the same as

reduce(operator.add, [a, b, c, d, e])

if you think of it in terms of iteration,
at each step two evokeds are added as specified by their __add__ method.

> 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/
>>>>>
>>>>>
>>>>>> 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
>>>>>> Mne_analysis Info Page
>>>>>>
>>>>>>
>>>>>> 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
>>>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>>>> Mne_analysis Info Page
>>>>>
>>>>>
>>>>> 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
>>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>>> Mne_analysis Info Page
>>>>
>>>>
>>>> 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
>>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>>> Mne_analysis Info Page
>>>
>>>
>>> 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
>>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
>> Mne_analysis Info Page
>>
>>
>> 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
>> MyComplianceReport.com: Compliance and Ethics Reporting . 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
> Mne_analysis Info Page

--
Hari Bharadwaj
Post-doctoral Associate,
Center for Computational Neuroscience
  and Neural Technology (CompNet),
Boston University
677 Beacon St.,
Boston, MA 02215

Martinos Center for Biomedical Imaging,
Massachusetts General Hospital
149 Thirteenth Street,
Charlestown, MA 02129

hari at nmr.mgh.harvard.edu
Ph: 734-883-5954
www.haribharadwaj.com

_______________________________________________
Mne_analysis mailing list
Mne_analysis at nmr.mgh.harvard.edu
Mne_analysis Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140911/d2d1adfc/attachment.html

You have many options,

My recommendation is to just epoch each run separately (read don't
create one big raw file) and then average the epochs together.

option 2
figure out how much you need to add to the second events file add it
and then use the big raw file.

option 3
run find_events on your big raw file, then save those events, run your
matlab script on those events then use the new event file to average

HTH,
D

Hi Maria,

The simplest solution here is to do:

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.

grand_ave = evoked1[0] + evoked2[0] + evoked3[0]

so that you extract the first element of the list. Or you can read in your
evoked object using:

evoked = mne.read_evokeds('filename-ave.fif', 0)

and then do grand_ave = evoked1 + evoked2 + evoked3

This should be ok if you know that your files contain only one condition.
Is that the case?

Mainak

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/

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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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
Mne_analysis Info Page

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
MyComplianceReport.com: Compliance and Ethics Reporting . 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/8f6cb8ec/attachment.html