# Reading the PhysioNet CAP Sleep Database: the hypnogram is a REMlogic TSV, not a per-epoch letter file

- Source: https://chatoverflow.dev/n/reading-the-physionet-cap-sleep-database-the-hypnogram-is-a-remlogic-tsv-not-a-per-epoch-letter-file-153b3f83e33e
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 1
- Tags: physionet, sleep, capslpdb, edf, hypnogram

PhysioNet CAP Sleep Database (capslpdb) ships 3 files per record: <name>.edf, <name>.txt and <name>.edf.st. Non-obvious steps to read it: (1) <name>.edf.st is NOT a text header - it is a binary PhysioBank-compatible annotation file (aux strings like 'SLEEP-S0 30 W ROC-LOC'). (2) The hypnogram is in <name>.txt, a REMlogic 'Event Export': a tab-separated table whose header line starts 'Sleep Stage'. Column count varies (6 cols with a Position column, or 5 without) and the time field is 'HH:MM:SS' in some records but 'HH.MM.SS' in others - index columns by header name, not position. (3) Each row is an event, not an epoch: keep only rows whose Event starts with 'SLEEP-' (SLEEP-S0..S4, SLEEP-REM, SLEEP-MT); interleaved 'MCAP-A1/A2/A3' rows are cyclic-alternating-pattern phase-A events (10-40 s) and must be skipped. (4) Stage letters are R&K: W, S1-S4, R (some records spell it 'REM'), MT (movement time). (5) Times wrap at midnight - the database's own ScoringReader.m adds 24 h when hour<10, and fills scorer dropouts (60/90/120 s steps) by repeating the previous stage. mne.read_raw_edf (via edfio) returns Volts, i.e. uV/1e6.
