# combining events with mne-python

**URL:** <https://mne.discourse.group/t/combining-events-with-mne-python/569>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [April 6, 2013, 10:14pm UTC](https://mne.discourse.group/t/combining-events-with-mne-python/569 "2013-04-06T22:14:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 6, 2013, 10:14pm UTC](https://mne.discourse.group/t/combining-events-with-mne-python/569/1 "2013-04-06T22:14:20Z")

</div>

Hi,

I have a situation where I would like individual trials to be able to belong to multiple events in the same evoked file. In other words I would like to be able to look at something like

Auditory1 = 1  
Auditory2 = 2  
AllAuditory =1,2

in the \*same\* evoked file. This is easy to do with regular mne. Can I also do this with mne-python? I was trying to use the combine\_event\_ids function for this, but it seems to remove the original two condition codes from the structure so that I'm only left with AllAuditory. I can see that I could create two separate evoked files splitting the data up in different ways, but that would be annoying for my pipeline. I tried to be clever and create doubles of the conditions in my original event\_id:

event\_id = dict{Auditory1 =1, Auditory1b=1, Auditory 2=2 ...}

and then use the b conditions for combine\_event\_ids, but I see that fails because even though the Auditory1 conditions nominally remain in the data structure, all their events get deleted (I'm assuming because the event code gets changed).

thanks,  
Ellen

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 6, 2013, 11:12pm UTC](https://mne.discourse.group/t/combining-events-with-mne-python/569/2 "2013-04-06T23:12:41Z")

</div>

Hi Ellen,

if I understand you correctly, your intent is to create averages including both conditions combined but also averages for each of the conditions. In that case just create your epochs with a dict, e.g. dict(aud\_l=1, aud\_r=2) as event\_id parameter.

To have averages of 1, 2 and 1 + 2,  
create a list including all three evoked objects and save them to a fiff.

e.g.

evokeds = [epochs[k].average() for k in event\_id]

to create the separate evoked objects for each condition and then

evokeds += [epochs.average()]

to append the combined average to the previously created list.

then save the list of evokeds to a file using the mne.fiff.write\_evoked function.

Also the following two examples might help:

[http://martinos.org/mne/auto\_examples/plot\_from\_raw\_to\_multiple\_epochs\_to\_evoked.html](http://martinos.org/mne/auto_examples/plot_from_raw_to_multiple_epochs_to_evoked.html)

[http://martinos.org/mne/auto\_examples/plot\_topo\_compare\_conditions.html#example-plot-topo-compare-conditions-py](http://martinos.org/mne/auto_examples/plot_topo_compare_conditions.html#example-plot-topo-compare-conditions-py)

I hope that helps,  
Denis

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [April 7, 2013, 7:56am UTC](https://mne.discourse.group/t/combining-events-with-mne-python/569/3 "2013-04-07T07:56:31Z")

</div>

hi Ellen,

with the new patch from Eric :

[https://github.com/mne-tools/mne-python/pull/556](https://github.com/mne-tools/mne-python/pull/556)

you should be able to do:

events = mne.event.merge\_events(events, [1, 2], 3, replace\_events=False)  
event\_id = dict(Auditory1 =1, Auditory2=2, AuditoryAll=3)  
epochs = Epochs(...)

mne.fiff.write\_evoked('auditory-ave.fif',  
[epochs['Auditory1'].average(), epochs['Auditory2].average(),  
epochs['AuditoryAll'].average()])

HTH  
Alex
