# events lost in epoching ?

**URL:** <https://mne.discourse.group/t/events-lost-in-epoching/943>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [January 6, 2016, 11:54am UTC](https://mne.discourse.group/t/events-lost-in-epoching/943 "2016-01-06T11:54:18Z")\
**Posts on this page:** 8\
**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:** [January 6, 2016, 11:54am UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/1 "2016-01-06T11:54:18Z")

</div>

Dear list,

When epoching data based on a given trigger, it seems that all other  
events that were present in the epochs are lost.

Below an example: in the raw data, I have three type of events, coded  
'1', '10', and '101'. I epoch on event '1'. Events '10' and '101' are  
close enough from event '1' and should fall on the epoched data.  
However, the event list of the epoch object only contains the events  
that were used to epoch ('1').

Am I using mne.Epochs in a wrong way? Is it an intended feature? If so,  
this is unfortunate since, for example, if even '101' is the response  
(and '1' the stimulus), I completely loose the Reaction Time.

Is there a way to keep all events in the epoched data?

&nbsp;&nbsp;Thanks in advance for your help,  
&nbsp;&nbsp;&nbsp;&nbsp;B.

In [67]: raw.\_events  
Out[67]:  
array([[1001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1763, 1, 10],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1845, 1, 101],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[526001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[526401, 1, 10],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[526485, 1, 101]])

In [68]: event\_id  
Out[68]:  
{'EMG': 10,  
&nbsp;&nbsp;'Left\_Resp': 1,  
&nbsp;&nbsp;'PC\_CompLeft': 1,  
&nbsp;&nbsp;'PC\_CompRight': 2,  
&nbsp;&nbsp;'PC\_IncompLeft': 3,  
&nbsp;&nbsp;'PC\_IncompRight': 4,  
&nbsp;&nbsp;'Right\_Resp': 2}

In [69]: t0  
Out[69]: {'PC\_CompLeft': 1}

In [70]: epochs = mne.Epochs(raw,raw.\_events,t0,-.5,1.5)  
211 matching events found  
Adding average EEG reference projection.  
Created an SSP operator (subspace dimension = 1)  
1 projection items activated

In [71]: epochs.events  
Out[71]:  
array([[1001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[3501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[6001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[8501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[11001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[13501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[16001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[18501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[21001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[23501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[26001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[28501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[31001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[33501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[36001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[38501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[41001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[43501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[46001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[48501, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[51001, 1, 1],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[53501, 1, 1],  
&nbsp;&nbsp;...

---

<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:** [January 6, 2016, 12:47pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/2 "2016-01-06T12:47:33Z")

</div>

Hi,

I'm not sure I fully understand it, but I respond with a comment on the  
semantics of epoching in MNE.  
The Epochs are based on the events passed to the the events id parameter.  
The idea is that the length of the first dimension of the data array and  
the events is the same.  
In other words, `epochs.events` is only regarding the events that you  
epoched on in chronological order.  
What you describe is thus consistent with the API design.  
This being said, we have discussed for some time already adding an API for  
annotations to support describing events that are inside the time window of  
interest used for epoching.

I hope this helps.  
Cheers,  
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:** [January 6, 2016, 1:08pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/3 "2016-01-06T13:08:46Z")

</div>

Hi,

> In other words, `epochs.events` is only regarding the events that you  
> epoched on in chronological order.  
> What you describe is thus consistent with the API design.

I understand, but that severely limits the manipulation one can do on  
the epochs. As said in my previous mail, There is no way to get, for  
example, the Reaction Times of those epochs: they need to be computed  
and store somewhere else... But this is the kind of information one very  
usually use to manipulate data.

> This being said, we have discussed for some time already adding an API  
> for annotations to support describing events that are inside the time  
> window of interest used for epoching.

I would find such a feature extremely useful !! If I can  
help/contribute, I would be happy to !

&nbsp;&nbsp;All the best,  
&nbsp;&nbsp;&nbsp;&nbsp;B.

---

<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:** [January 6, 2016, 1:16pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/4 "2016-01-06T13:16:13Z")

</div>

Note. You can compute all latencies solely based on the events array using the differences between the values in the first column, after transforming to time via sampling frequency.  
Then there is 'epoch.selection' which gives you the indices of the epochs selected with respect to the original epochs. So you can easily map your eeg trials to external information. I am on my phone now, so I cannot give you a nice example unfortunately.

> Hi,
> 
> > In other words, `epochs.events` is only regarding the events that you  
> > epoched on in chronological order.  
> > What you describe is thus consistent with the API design.
> 
> I understand, but that severely limits the manipulation one can do on  
> the epochs. As said in my previous mail, There is no way to get, for  
> example, the Reaction Times of those epochs: they need to be computed  
> and store somewhere else... But this is the kind of information one very  
> usually use to manipulate data.
> 
> > This being said, we have discussed for some time already adding an API  
> > for annotations to support describing events that are inside the time  
> > window of interest used for epoching.
> 
> I would find such a feature extremely useful !! If I can  
> help/contribute, I would be happy to !

Cool we already have an open issue for that on github.

---

<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:** [January 6, 2016, 1:28pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/5 "2016-01-06T13:28:38Z")

</div>

Sure, but that less convenient, and somehow more fragile: if I drop an  
epoch, and forget to delete the corresponding RT in the list, there is  
mismatch. This cannot append if I extract the RT directly from the epoch.

Beside computing RT, there are many other occasion where one needs to  
sort trials based on the presence of other events in the epoch.

&nbsp;&nbsp;Thanks anyway for your help,  
&nbsp;&nbsp;&nbsp;&nbsp;B.

---

<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:** [January 6, 2016, 1:35pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/6 "2016-01-06T13:35:28Z")

</div>

Disclaimer: I'm not arguing against annotations, I'm trying to share some  
practices that were good enough for me over the last years, in the hope  
that you can find a solution before we eventually have proper annotations.

> \> Note. You can compute all latencies solely based on the events array  
> using the differences between the values in the first column, after  
> transforming to time via sampling frequency.  
> \> Then there is 'epoch.selection' which gives you the indices of the  
> epochs selected with respect to the original epochs. So you can easily map  
> your eeg trials to external information. I am on my phone now, so I cannot  
> give you a nice example unfortunately.  
> \>
> 
> Sure, but that less convenient, and somehow more fragile: if I drop an  
> epoch, and forget to delete the corresponding RT in the list, there is  
> mismatch. This cannot append if I extract the RT directly from the epoch.

This actually not the case. Look at .selection, it will be insensitive to  
what you drop, it gives you just the position in the array from where the  
epoch was initially taken, if you re-order epochs, you can also re-order  
.selection.

> Beside computing RT, there are many other occasion where one needs to  
> sort trials based on the presence of other events in the epoch.

you can also do this in a few lines of code based on the initial events  
array.  
Or am I missing something?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks anyway for your help,

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B.
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Mne\_analysis mailing list  
> Mne\_analysis at nmr.mgh.harvard.edu  
> [Mne\_analysis Info Page](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)
> 
> 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](http://www.partners.org/complianceline) . 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/20160106/cf832e82/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160106/cf832e82/attachment.html)

---

<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:** [January 6, 2016, 5:12pm UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/7 "2016-01-06T17:12:38Z")

</div>

boris,

point taken. What do you suggest in terms of API to address your use case?  
what would be convenient to manipulate?

Best,  
A  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20160106/b6117180/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160106/b6117180/attachment.html)

---

<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:** [January 7, 2016, 10:22am UTC](https://mne.discourse.group/t/events-lost-in-epoching/943/8 "2016-01-07T10:22:20Z")

</div>

Hi,

Thank you very much Denis and Jona for your suggestions, and I will  
certainly have a close look at your propositions

> point taken. What do you suggest in terms of API to address your use case?  
> what would be convenient to manipulate?

I have to think about it, and come back to you very soon !!!

&nbsp;&nbsp;Best,  
&nbsp;&nbsp;&nbsp;&nbsp;B.
