ef2f3dbf39
- legacy: seleccion.seleccionar and candidatos_punta.de_estudio + indicadores vendored unchanged, run on the contract adapter with the sleep_state labels as the vigilancia table. - modern: the director's detector functions copied by name into _detector.py with three substitutions (MNE band-pass, channel lists from the study, a private port of the seleccion gate); a modern window_selection on the same port. - synthetic builder: optional focal spike-and-wave (the director's own _punta shape) with a field on the neighbours. Modern equals legacy exactly on window verdicts and spike indicators; the C3 focus is found; contract suites pass.
49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
"""Window selection and spikes: modern equals legacy; the focus is found."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from synth_edf import make_edf
|
|
from tea_modulo.contracts import Study
|
|
from tea_modulo.contracts.testing import check_biomarker, check_process
|
|
from tea_modulo.pipeline import Pipeline
|
|
from tea_modulo.preprocessing import DIRECTOR_CLUSTER
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def studies(tmp_path_factory):
|
|
p = make_edf(tmp_path_factory.mktemp("spk") / "s.edf", minutes=8, bad={"spikes": ["C3"]})
|
|
return (Pipeline.default("modern").study(p, plan=DIRECTOR_CLUSTER, age_months=28),
|
|
Pipeline.default("legacy").study(p, plan=DIRECTOR_CLUSTER, age_months=28))
|
|
|
|
|
|
def test_window_selection_equal(studies):
|
|
a = studies[0].label("window_selection").events
|
|
b = studies[1].label("window_selection").events
|
|
assert len(a) == len(b) and (a.apto.values == b.apto.values).all()
|
|
|
|
|
|
def test_spike_indicators_equal(studies):
|
|
im = Pipeline.default("modern").module("spikes").indicators(studies[0])
|
|
il = Pipeline.default("legacy").module("spikes").indicators(studies[1])
|
|
for k in ("n_total", "n_util", "canal_foco", "foco_frac", "lateralidad", "tasa_NREM", "tasa_despierto"):
|
|
a, b = im[k], il[k]
|
|
assert (isinstance(a, float) and np.isnan(a) and np.isnan(b)) or a == b, k
|
|
assert im["n_total"] > 100 and im["canal_foco"] == "C3"
|
|
|
|
|
|
def test_contracts(studies):
|
|
for impl, s in zip(("modern", "legacy"), studies):
|
|
base = Study(s.prep, {k: v for k, v in s.labels.items() if k == "annotation_mask"})
|
|
check_process(Pipeline.default(impl).module("window_selection"), base)
|
|
|
|
|
|
def test_biomarker_contract(tmp_path):
|
|
pipe = Pipeline.default("modern")
|
|
sts = [pipe.study(make_edf(tmp_path / f"s{i}.edf", minutes=5, seed=i, bad={"spikes": ["C3"]}),
|
|
plan=DIRECTOR_CLUSTER, age_months=20 + 4 * i) for i in range(3)]
|
|
from tea_modulo.biomarkers.spikes import Spikes
|
|
check_biomarker(Spikes(baseline="age_blocks"), sts, [20, 24, 28])
|