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.
`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?
And obviously when I tried to get events from annotations , it was an empty list as well
events_from_annot, event_dict = mne.events_from_annotations(raw)
print(events_from_annot)
[ ]
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, you have a graph-like code block which details the different (and messy) interaction of those 3 parameters. Copy/pasting below:
----------- 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
Just to second that, you should just have to add raw.first_samp
to your variable onset