# adding annotations to raw array

**URL:** <https://mne.discourse.group/t/adding-annotations-to-raw-array/7221>\
**Category:** Support & Discussions\
**Created:** [July 12, 2023, 6:02am UTC](https://mne.discourse.group/t/adding-annotations-to-raw-array/7221 "2023-07-12T06:02:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [July 12, 2023, 6:02am UTC](https://mne.discourse.group/t/adding-annotations-to-raw-array/7221/1 "2023-07-12T06:02:57Z")

</div>

I am looking at ecog data that has x channels. There is no stimulus channel. The data has events 1 – thumb movement, 2 – index finger movement. I have added these events as annotations (which are all numpy array) like below to the raw array.

```python
`annotations = mne.Annotations(onset, duration, stim_id.astype(str)) ) #stim_id is the id of event

raw.set_annotations(annotations)`

```

When I print the annotations, I get :  
`print(annotations)`  
\<Annotations | 60 segments: 1 (30), 2 (30)\>  
but when I print raw.annotations it is an empty array  
`print(raw.annotations)`  
\<Annotations | 0 segments\>

Wondering why the annotations are not getting added to the raw array?

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [July 12, 2023, 6:09am UTC](https://mne.discourse.group/t/adding-annotations-to-raw-array/7221/2 "2023-07-12T06:09:01Z")

</div>

And obviously when I tried to get events from annotations , it was an empty list as well

```python
events_from_annot, event_dict = mne.events_from_annotations(raw)

print(events_from_annot)

```

[]

---

<div class="post-metadata">

**Author:** ![mscheltienne](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mscheltienne/32/827_2.png) [@mscheltienne](https://mne.discourse.group/u/mscheltienne)\
**Post date:** [July 12, 2023, 8:18am UTC](https://mne.discourse.group/t/adding-annotations-to-raw-array/7221/3 "2023-07-12T08:18:05Z")

</div>

It’s probably an issue with the first\_samp/origin of time/measurement date. Basically, your annotation are likely “outside” of your recording. I think when you do `raw.set_annotations` you get a message close to “omitting 60 annotations outside of range”.

In the `Notes` of [Annotations](https://mne.tools/dev/generated/mne.Annotations.html#mne-annotations), you have a graph-like code block which details the different (and messy) interaction of those 3 parameters. Copy/pasting below:

```python
----------- meas_date=XX, orig_time=YY -----------------------------

     | +------------------+
     | ______________ | RAW |
     | | |
     | +------------------+
 meas_date first_samp
     .
     . | +------+
     . | _________ | ANOT |
     . | | |
     . | +------+
     . orig_time onset[0]
     .
     | +------+
     | ___________________ | |
     | | |
     | +------+
 orig_time onset[0]'

----------- meas_date=XX, orig_time=None ---------------------------

     | +------------------+
     | ______________ | RAW |
     | | |
     | +------------------+
     . N +------+
     . o _________ | ANOT |
     . n | |
     . e +------+
     .
     | +------+
     | ________________________ | |
     | | |
     | +------+
 orig_time onset[0]'

----------- meas_date=None, orig_time=YY ---------------------------

     N +------------------+
     o ______________ | RAW |
     n | |
     e +------------------+
               | +------+
               | _________ | ANOT |
               | | |
               | +------+

            [[[CRASH]]]

----------- meas_date=None, orig_time=None -------------------------

     N +------------------+
     o ______________ | RAW |
     n | |
     e +------------------+
     . N +------+
     . o _________ | ANOT |
     . n | |
     . e +------+
     .
     N +------+
     o ________________________ | |
     n | |
     e +------+
 orig_time onset[0]'

```

Have a look at `raw.info["meas_date"]` which should be None or a datetime and have a look at `raw.first_samp`. Then you will need to modify your onsets accordingly.

Mathieu

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [July 12, 2023, 4:34pm UTC](https://mne.discourse.group/t/adding-annotations-to-raw-array/7221/4 "2023-07-12T16:34:41Z")

</div>

Just to second that, you should just have to add `raw.first_samp` to your variable `onset`
