spindle phases (N2/N3), README, registry test for the full module set

- spindle_detection (legacy and modern): phase='N2'|'N3' searches only the
  sleep windows of that stage (husos --fase); requires slow_wave_staging then.
- README: modules, requirements, use, tests and cluster verification.
- test_pipeline: both implementations register the same 5 processes and 9
  biomarkers.
This commit is contained in:
AlbertoPMDM
2026-11-18 22:12:02 -06:00
parent ef2f3dbf39
commit 5da1921c69
5 changed files with 125 additions and 10 deletions
+7 -3
View File
@@ -43,9 +43,13 @@ def test_order_is_topological():
def test_legacy_pipeline_is_registered():
pipe = Pipeline.default(impl="legacy")
assert {"validation", "preprocessing", "annotation_mask", "sleep_state", "posterior_rhythm"} <= set(pipe.modules)
assert pipe.biomarker_names() == ["posterior_rhythm"]
for impl in ("legacy", "modern"):
pipe = Pipeline.default(impl=impl)
assert set(pipe.process_names()) == {"annotation_mask", "window_selection", "sleep_state",
"slow_wave_staging", "spindle_detection"}, impl
assert set(pipe.biomarker_names()) == {"posterior_rhythm", "spindles", "gradient", "slow_waves",
"aperiodic", "mse", "coupling", "spindle_topography",
"spikes"}, impl
def test_legacy_loop_rows_and_errors(edfs):
+16
View File
@@ -101,3 +101,19 @@ def test_biomarker_contract(tmp_path):
age_months=20 + 4 * i) for i in range(3)]
from tea_modulo.biomarkers.spindles import Spindles
check_biomarker(Spindles(baseline="age_blocks"), sts, [20, 24, 28])
@pytest.mark.parametrize("impl", ["modern", "legacy"])
def test_phase_restricts_the_search(studies, impl):
"""phase='N3' searches only N3 sleep windows (none in this study: no spindles, no minutes)."""
s = studies[0] if impl == "modern" else studies[1]
pipe = Pipeline.default(impl)
det = type(pipe.module("spindle_detection"))(phase="N3")
assert det.requires == ("sleep_state", "slow_wave_staging")
ev = det.predict(s).events
n3 = (s.label("slow_wave_staging").per_window == "N3").sum()
assert n3 == 0 and len(ev) == 0 and ev.attrs["minutes"] == 0
det2 = type(pipe.module("spindle_detection"))(phase="N2")
assert len(det2.predict(s).events) == len(s.label("spindle_detection").events) # all sleep is N2 here
with pytest.raises(ValueError, match="phase"):
type(pipe.module("spindle_detection"))(phase="REM")