# Error mapping values and descriptions for events\_id

**URL:** <https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849>\
**Category:** Support & Discussions\
**Tags:** meg, mne-bids\
**Created:** [March 17, 2021, 7:16am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849 "2021-03-17T07:16:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![duanchiheihei](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@duanchiheihei](https://mne.discourse.group/u/duanchiheihei)\
**Post date:** [March 17, 2021, 7:16am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/1 "2021-03-17T07:16:09Z")

</div>

Hi MNE experts!

I was trying to generate BIDS-format events.tsv files for my meg data. However, I always found a mismatch between the events data I retrieved from the stim\_channel and from the annotations.

- MNE-Python version: 0.22.0
- operating system: Ubuntu 16.04.5 LTS

the code was

```python
import numpy as np
import mne
import mne_bids

# load raw data
sub_path = mne_bids.BIDSPath(subject='01', run=1, task='movie', session='movie', root=bids_dir)
raw = mne_bids.read_raw_bids(sub_path)

# get event data from stim channel
event_raw = mne.find_events(raw, stim_channel='UPPT001', min_duration=2/raw.info['sfreq'])

# save annot event data from stim channel
events_id = {'desp_{0}'.format(i) : i for i in np.unique(event_raw[:,-1])}
annot = mne.annotations_from_events(event_raw, raw.info['sfreq'], 
                                    event_desc={v: k for k, v in events_id.items()}, first_samp=raw.first_samp)
raw.set_annotations(annot)

# get event data from annot
event_from_annot = mne.events_from_annotations(raw)

# compare event data from stim channel and annotation
event_raw == event_from_annot

```

It turns out that the third column (marker value) of [event\_raw] and [event\_from\_annot] are not identical. Output details please see the pic blow. It seems to be related to the sorting somewhere.

 ![mne_event](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/7a8818d595b21851627f98cb07ec3d649ac4d4f6.jpeg)

Could you guys help me with this problem?

Thanks!

Best,  
Xingyu

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 18, 2021, 7:31am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/2 "2021-03-18T07:31:04Z")

</div>

Hello, thank you for your report! This has actually been fixed in the latest development version of MNE-BIDS, and the fix will be included in MNE-BIDS 0.7, which we hope will be released within the next few days.

If you are impatient, you can install the development version via:

```python
pip install -U https://github.com/mne-tools/mne-bids/archive/master.zip

```

Best wishes,

Richard

---

<div class="post-metadata">

**Author:** ![duanchiheihei](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@duanchiheihei](https://mne.discourse.group/u/duanchiheihei)\
**Post date:** [March 19, 2021, 4:10am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/3 "2021-03-19T04:10:14Z")

</div>

Thanks! Perfect, I’ll update it to the latest dev version.  
Best,  
Xingyu

---

<div class="post-metadata">

**Author:** ![duanchiheihei](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@duanchiheihei](https://mne.discourse.group/u/duanchiheihei)\
**Post date:** [March 19, 2021, 5:06am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/4 "2021-03-19T05:06:29Z")

</div>

Hi Richard,

Thanks for your suggestions!

I tried it out with mne==0.23.dev0, mne\_bids==0.7.dev0. It really works.  
But it turned out that the bug was fixed with writing specifying events data in write\_raw\_bids:

```python
raw.set_annotations(None)
write_raw_bids(raw, bids_path=bids_path, overwrite=True
               events_data=events, event_id=events_id)

```

but the bug remained when using annotations to write events data automatically:

```python
raw.set_annotations(annot_new)
write_raw_bids(raw, bids_path=bids_path, overwrite=True)

```

Hope with could help.

Best,  
Xingyu

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 19, 2021, 5:52am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/5 "2021-03-19T05:52:23Z")

</div>

The annotations themselves don’t contain any event IDs we could use during writing, so this is actually to be expected. This is a limitation in MNE-Python.

What we probably **could** do, however, is: if the data contains annotations **and** you pass an `event_id` dict that maps event types (which, in this case, would be annotation names) to IDs, we can use this information to retain the correct event IDs. This would need to be discussed first, though…

Another thing we could do is extend MNE’s Annotations to gain an “event ID” field, but I’m not sure how difficult this would be

@sappelhoff @agramfort @larsoner WDYT?

---

<div class="post-metadata">

**Author:** ![duanchiheihei](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@duanchiheihei](https://mne.discourse.group/u/duanchiheihei)\
**Post date:** [March 19, 2021, 8:31am UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/6 "2021-03-19T08:31:48Z")

</div>

Oh I see, it explains everything.  
Thanks you very much!  
Best,  
Xingyu

---

<div class="post-metadata">

**Author:** ![larsoner](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/larsoner/32/3_2.png) [@larsoner](https://mne.discourse.group/u/larsoner)\
**Post date:** [March 22, 2021, 5:51pm UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/7 "2021-03-22T17:51:12Z")

</div>

> Another thing we could do is extend MNE’s Annotations to gain an “event ID” field, but I’m not sure how difficult this would be

From the I/O end I would say it’s pretty easy to expand `mne.Annotations` to have this field.

I don’t really like it conceptually, though, since it’s storing something related to and specific to epoching _in MNE-Python_ (the `event_id` str-\>int dict mapping, really having `int` in there at all) in the raw object, so I’m -1 on adding it.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 22, 2021, 8:45pm UTC](https://mne.discourse.group/t/error-mapping-values-and-descriptions-for-events-id/2849/8 "2021-03-22T20:45:34Z")

</div>

Yes I agree, it’s not a good idea. I’ve started working on something in MNE-BIDS to make it easier to assign event IDs to existing annotations upon BIDS conversion. Nothing we need to solve in MNE-Python.
