EESM19-Processed / README.md
Zachary1150's picture
Expand README: detail source-corrupt sessions (.set/.fdt truncation) and out-of-bounds epochs
7346d3e verified
|
Raw History Blame Contribute Delete
10.7 kB
metadata
license: cc0-1.0
tags:
  - eeg
  - sleep-staging
  - in-ear-eeg
  - scalp-eeg
  - hdf5

EESM19-Processed

Processed HDF5 export of the EESM19 OpenNeuro dataset ("Ear-EEG Sleep Monitoring 2019", Mikkelsen et al., Aarhus University). It contains paired in-ear EEG and scalp EEG sleep-staging samples from the four home-sleep nights (ses-001–ses-004) of all 20 subjects — the nights recorded with simultaneous partial PSG and ear-EEG on one amplifier.

Preprocessing

Generated with Ear-EEG-FM-Benchmark/dataset/preprocess_eesm19.py using schema/eegfm version 0.5.0:

  • 0.1–100 Hz band-pass and 50 Hz notch filtering on each continuous recording
  • no re-referencing, resampling, or channel renaming
  • each labeled 30-second AASM scoring event is stored as one 30-second window (one sample = one epoch = one label = one prediction — the canonical sleep-staging unit)
  • classes: Wake, N1, N2, N3, REM; Artefact/Movement/Unscored events are dropped
  • real sensor/data-loss NaN/Inf samples are preserved and recorded in overall and per-channel quality fields
  • all signal values are stored as float32 microvolts at 500 Hz (15,000 samples per window)

Why 30-second windows (and how to get 4-second windows)

The 30-second epoch is the unit at which sleep is scored (AASM) and evaluated: the benchmark's reference foundation models (BENDR, EEGPT, CBraMod, REVE, and the EEGPT comparison implementations of LaBraM/BIOT) all ingest full 30-second epochs downstream and emit one stage prediction per epoch. EEGPT in particular shows a 4-second-pretrained backbone fine-tunes directly on 30-second sleep inputs. We therefore store the full epoch rather than splitting one label into several independently-scored short windows.

Storing 30 s loses nothing relative to a shorter export: it is a strict superset. The benchmark loader (dataset/loader.py) accepts an epoch_sec argument and crops a shorter window from each stored sample at load time, so a 4-second (or any ≤30 s) view is available from these files without re-exporting. The reverse — reconstructing a 30 s epoch from stored 4 s slices — is not possible, which is why the 4-second layout used by EESM23-Processed is not used here.

Brief device data-loss gaps are interpolated before filtering to prevent FIR-kernel contamination, after which the original NaN positions are restored before window selection. A fully-dead channel (all-NaN for a night, e.g. sub-001/ses-004 F3) is left NaN and flagged in the per-channel quality fields.

Notes specific to EESM19 (differences from EESM23-Processed)

Two things differ from the EESM23 export and are worth reading before use:

  1. Single source file → inherently paired. On these nights the ear and scalp channels are recorded together in one file, *_task-sleep_acq-PSG_eeg.set (there is no separate acq-earEEG file — that only exists on the ear-only nights ses-005+, which are excluded here). Both modalities are sliced from the same continuous recording on one shared timeline, so every window is present in both — no cross-file pairing/intersection is needed and none is dropped for lack of a partner.

  2. Integer sleep-stage codes with a non-standard mapping. The scoring column Scoring1 holds an integer code, not a string stage name, and the mapping (from the dataset's task-sleep_events.json) is not the usual AASM digit order — note 2 = REM and 5 = N3:

    code 1 2 3 4 5 6 7 8
    stage Wake REM N1 N2 N3 A (movement/arousal) Artefact Unscored

    Codes 6/7/8 are dropped. Labels are re-emitted in the EESM23 class order (Wake, N1, N2, N3, REM) so class indices line up across datasets. Only the first scorer (acq-scoring1) is used; the second scorer's labels are ignored.

Channel groups are selected by name (the EEGLAB .set marks every channel as eeg, so EOG/EMG cannot be told apart by type): 12 ear channels (ELA ELB ELC ELT ELE ELI ERA ERB ERC ERT ERE ERI) and 8 scalp channels (M1 F3 C3 O1 M2 F4 C4 O2); EOG/EMG are dropped.

Files

File Channels Shape (N, C, T) Size
eesm19-in-ear-eeg.h5 ELA, ELB, ELC, ELT, ELE, ELI, ERA, ERB, ERC, ERT, ERE, ERI (73,780, 12, 15000) 49.50 GiB
eesm19-scalp-eeg.h5 M1, F3, C3, O1, M2, F4, C4, O2 (73,780, 8, 15000) 33.01 GiB

T = 15000 is one 30-second epoch at 500 Hz. N is the number of scored epochs, not a multiple of it — one sample per 30-second AASM epoch.

Label distribution (identical for both modalities — the samples are row-aligned):

Wake N1 N2 N3 REM
11,084 5,421 31,508 12,497 13,270

Retained and discarded epochs

Scorer 1 labels 79,058 30-second epochs across the 80 nights (20 subjects × ses-001–ses-004). Of these, 76,054 carry one of the five retained sleep-stage labels and 3,004 are labeled Artefact (codes 6 and 8 — Movement/Unscored — do not occur in this dataset). Each retained epoch becomes exactly one 30-second sample, so the final files contain 73,780 strictly paired samples per modality. The exclusions from the 76,054 five-class candidates are:

Reason Epochs
Two source-corrupt sessions with unreadable .set/.fdt (see below) 2,119
30-second epoch not fully inside the recording bounds 155
Total excluded 2,274

(The 3,004 Artefact epochs are outside the five-class task and are never candidates, so they are listed separately from the table above.)

Source-corrupt sessions (2 dropped, 2,119 epochs)

Each EEGLAB recording is a pair: a .set header (metadata — how long the recording is, how many channels) and a .fdt binary holding the raw signal. Two sessions are dropped because the .set header and the .fdt binary disagree on the recording length: the .fdt is truncated and contains far fewer samples than the header declares, so the data matrix cannot be reconstructed and MNE refuses to load it (RuntimeError: Incorrect number of samples).

Session .set header declares (pnts = len(times) = xmax·srate) .fdt actually contains Missing
sub-011/ses-004 17,403,870 samples/ch = 9.67 h 3,098,150 = 1.72 h ~8.0 h
sub-013/ses-001 14,515,050 samples/ch = 8.06 h 9,094,592 = 5.05 h ~3.0 h

For comparison, every intact session matches exactly (e.g. sub-001/ses-001: header 14,255,560 = .fdt 14,255,560 = 7.92 h). The truncated samples are simply absent from the .fdt on OpenNeuro — the local files are byte-identical to the S3 source, so this is source-level corruption, not a download error, and it cannot be repaired. (The intact prefix of each truncated .fdt is technically recoverable by bypassing MNE, but that is ~1% of the data and is not attempted here.) This is the same failure class as EESM23's known-corrupt sub-006/ses-002. The other 78 sessions (all 20 subjects) load cleanly.

Out-of-bounds epochs (155 dropped)

These are benign, not corruption. A scoring epoch is annotated by an onset time plus a 30-second duration, and a sample is only written when the full 30 s (15,000 points) lies inside the recording. For the last one or two epochs of some nights, onset + 30 s runs slightly past the end of the .fdt (the recording stops before the final annotated epoch fully elapses), so those epochs are dropped — about two per night across the 78 intact sessions. This is expected: scoring files routinely annotate a little beyond the end of the signal.

Because both modalities are sliced from one file on a shared timeline, no sample is excluded for lack of a cross-modality partner. No sample is excluded for containing NaN/Inf: the files retain 38,155 in-ear and 11,399 scalp samples with at least one non-finite value (e.g. a dead channel for a whole night, such as sub-001/ses-004 F3); their indices remain paired even when quality differs between modalities.

HDF5 schema (v0.5)

/data                 (N, C, 15000) float32
/durations            (N,)         int64
/nan_fraction         (N,)         float32
/channel_nan_fraction (N, C)       float32
/labels               (N,)         int64
/sample_id            (N,)         int64
/subject              (N,)         string
/session              (N,)         string
/task                 (N,)         string
/acquisition          (N,)         string
/run                  (N,)         string
/recording_id         (N,)         string
/trial_id             (N,)         int64
/event_id             (N,)         int64
/split_group_id       (N,)         int64
/window_start_sample  (N,)         int64
/window_stop_sample   (N,)         int64
/ch_names             (C,)         string

event_id and split_group_id both identify the source 30-second scoring row; here each sample is one epoch, so there is one sample per split group (unlike a 4-second export, where seven windows share a group). For sequence-model sleep staging that needs adjacent-epoch context, group by subject+session and order by window_start_sample.

Important attributes include sfreq, class_names, unit, eegfm_version, preprocess_config_json, split_group_kind, and window_reference.

Storage format

The signal is stored uncompressed as float32 microvolts at the native 500 Hz, with /data chunked one sample per chunk — chunks = (1, C, 15000). This layout is chosen for map-style DataLoader training: each __getitem__(i) reads exactly one contiguous chunk (one 30-second epoch with its channels), so random access across the whole file costs one chunk read and no wasted I/O. When the loader crops a shorter epoch_sec window it reads only that slice of the chunk.

Compression is intentionally not applied. EEG windows are high-entropy signals that gzip/lzf shrink only ~1.2–1.5×, and decompression would add CPU cost on every sample fetched by the DataLoader workers; at this scale (tens of GB on local disk) the trade is not worth it. The files are therefore ≈ the raw array size (N × C × 15000 × 4 bytes).

Note on sample rate: this export keeps the native 500 Hz (unlike EESM23-Processed, which is 250 Hz). Every model in the benchmark resamples to its own expected rate at load time (200 Hz for most; 256 Hz for EEGPT/BENDR), so the stored rate does not affect model inputs — 500 Hz is retained purely to preserve the recording as acquired. Downsampling to 250 Hz would roughly halve the file size with no effect on any model.