tests: synthetic EDF+ builder (no patient data)

Step 3 of the plan. Spatially mixed pink noise, posterior rhythm in wake,
frontal slow waves and 13 Hz spindles in sleep, blinks, EKG, mains line,
channel faults (flat, frozen, clipped, bridge, loud, bursts) and
BAD_ACQ_SKIP gaps, written like ktlx2edf. Read by MNE and by the director's
edf_convert.leer_edf.
This commit is contained in:
AlbertoPMDM
2026-11-18 19:56:35 -06:00
parent 2b4bea0c7f
commit 04b314ed8b
2 changed files with 262 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
"""The synthetic EDF builder: readable by MNE and by the director's EDF reader."""
from __future__ import annotations
import sys
from pathlib import Path
import numpy as np
import pytest
from synth_edf import AUX, EARS, SCALP, make_edf
PREPROCESO = Path(__file__).resolve().parents[1] / "biomarcadores-tea" / "preproceso"
def test_mne_reads_it(tmp_path):
import mne
p = make_edf(tmp_path / "s.edf", minutes=2, gaps=[(30.0, 5.0)])
raw = mne.io.read_raw_edf(p, preload=True, verbose="error")
assert raw.ch_names == SCALP + list(EARS) + list(AUX)
assert raw.info["sfreq"] == 250.0
assert any(d == "BAD_ACQ_SKIP" for d in raw.annotations.description)
assert any("Dormido" in d for d in raw.annotations.description)
x = raw.get_data(picks="O1")[0] * 1e6
assert 10 < x.std() < 150
def test_neighbours_correlate_and_ears_follow_temporal(tmp_path):
import mne
raw = mne.io.read_raw_edf(make_edf(tmp_path / "s.edf", minutes=2), preload=True, verbose="error")
x = raw.copy().filter(1, 40, verbose="error").get_data()
i = {c: k for k, c in enumerate(raw.ch_names)}
r = np.corrcoef(x)
assert r[i["C3"], i["Cz"]] > 0.2
assert r[i["A1"], i["T3"]] > 0.2
@pytest.mark.skipif(not PREPROCESO.exists(), reason="biomarcadores-tea submodule absent")
def test_director_reader_reads_it(tmp_path):
sys.path.insert(0, str(PREPROCESO))
try:
import edf_convert
X, nombres, fs, h, desc = edf_convert.leer_edf(make_edf(tmp_path / "s.edf", minutes=1))
finally:
sys.path.remove(str(PREPROCESO))
assert fs == 250.0
assert set(SCALP) <= set(nombres) and "EKG" in nombres
assert any(txt == "Dormido" for _, _, txt in h["anotaciones"])