-
Notifications
You must be signed in to change notification settings - Fork 2
/
manual_event_marking.py
43 lines (32 loc) · 1.38 KB
/
manual_event_marking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
#from datetime import timedelta
import mne
# load raw data
data_dir = 'C:/Users/mq43606024/Downloads/epilepsy_MEG/'
raw_fname = data_dir + '0001_JC_ME200_11022022_resting_B1_TSPCA-raw.fif'
raw = mne.io.read_raw_fif(raw_fname, verbose=False)
# filter the data
raw.filter(l_freq=1, h_freq=None)
# browse data to mark the events manually
fig = raw.plot(start=0) #, duration=6)
#fig.fake_keypress('a') # press 'a' to toggle annotations mode
# always save straight after interactive session (as these annotations
# can be easily lost in any subsequent calls to set_annotations())
raw.annotations.save(data_dir + 'saved-annotations.csv', overwrite=True)
# sanity check - print out the time span of each event
for ann in raw.annotations:
descr = ann['description']
start = ann['onset']
end = ann['onset'] + ann['duration']
print("'{}' goes from {} to {}".format(descr, start, end))
# send the csv file to us, we can then load it
my_annot = mne.read_annotations(data_dir + 'saved-annotations.csv')
print(my_annot)
# convert annotations to events array
raw.set_annotations(my_annot)
events_from_annot, event_dict = mne.events_from_annotations(raw)
print(event_dict)
print(events_from_annot)
# For more info:
# https://mne.tools/dev/auto_tutorials/raw/30_annotate_raw.html
# https://mne.tools/dev/auto_tutorials/intro/20_events_from_raw.html#the-events-and-annotations-data-structures