Hi everybody. I have annotations for EEG signal in .txt file. The signals annotate every 30-s with a sampling rate of 250. I extracted sample and Aux columns. Then I extracted the starting and ending sample of each event (‘H’, 'HA) to segment the signal. I used pandas to do that and then converted the dataframe to .txt file. Now I’m trying to read it by mne.read_annotations which can read .txt files, but it doesn’t work. What is the problem? Is there any other way to find events and epoch the signal?
I hope that I provide all the required informations. If not, please tell me to add more. Thank you.
By the way, I’m working on MIT-BIH Polysomnographic Database. If someone worked on it before, I’d appreciate it if help me to preprocess the signal.
You might want to check out SleepECG – we’re currently working on providing readers for various sleep database records, and it could be that the record you want to load is already implemented.
If this does not work, then the format of your .txt file is probably not what mne.read_annotations expects. You’d have to provide more details on how your file is structured, and what the exact error message is.
Thank you Clemens. I checked the link but I didn’t find the records I was looking for. The data I’m working on is: slpdb
The .txt file I extracted is like this:
index Sample # Aux
12 90000 3 HA
13 97500 3 H LA
14 105000
36 270000 4 LA HA
37 277500
46 345000 2 H
47 352500
49 367500 2 H
50 375000
163 1222500 2 HA
164 1230000
167 1252500 2 H LA
168 1260000
174 1305000 2 H
175 1312500
179 1342500 2 HA
180 1350000 2 LA HA
181 1357500 2 H LA
182 1365000
185 1387500 2 LA H
186 1395000
187 1402500 2 H
188 1410000 3 H
189 1417500 3 HA
... ... ...
And the error is:
ValueError: Invalid value for the ‘text header’ parameter. Allowed values are 3, and 4, but got 58 instead.
The wfdb package allows to read record and annotation files from PhysioNet. This minimal example shows how you could access annotations and annotation times. It requires the .hea,.dat and .st files for the desired record.
import wfdb
import mne
# change the path if necessary
# note that this path does _not_ include any file extension, as it's added automatically by `wfdb.rdrecord`
record_path = '../../datasets/slpdb/slp01a'
record = wfdb.rdrecord(record_path)
annotation = wfdb.rdann(record_path, 'st')
# annotation.sample contains the annotation's sample indices
# annotation.aux_note contains sleep stage, apnea and movement information
# slpdb doesn't provide annotation durations, so let's assume 30 seconds
annotation_mne = mne.Annotations(
onset=annotation.sample / record.fs,
duration=30,
description=annotation.aux_note
)