""" Modern = legacy on a gap-free recording: since the modern modules use the director's own filter (scipy sosfiltfilt) and spectra (DPSS multitaper with demeaned windows, symmetric Hann periodogram), every biomarker agrees with legacy to float32 precision (legacy stores its variants as float32). With gaps they differ by design: modern keeps gaps as NaN. """ from __future__ import annotations import numpy as np import pytest from synth_edf import make_edf from tea_modulo.pipeline import Pipeline from tea_modulo.preprocessing import DIRECTOR_CLUSTER TOL = 1e-4 @pytest.fixture(scope="module") def tables(tmp_path_factory): d = tmp_path_factory.mktemp("prec") st = [("vigilia", 0, 150), ("sueno", 150, 600)] paths = [make_edf(d / f"p{i}.edf", minutes=10, states=st, seed=i, rhythm_hz=6.5 + i) for i in range(2)] bios = tuple(Pipeline.default(impl="legacy").biomarker_names()) kw = dict(plan=DIRECTOR_CLUSTER, ages_months=[24, 30], biomarkers=bios) return (Pipeline.default(impl="legacy").map(paths, **kw), Pipeline.default(impl="modern").map(paths, cluster="sync", **kw)) def test_every_feature_matches_legacy_without_gaps(tables): legacy, modern = tables assert (legacy.error == "").all() and (modern.error == "").all() skip = {"key", "age_months", "valid", "level", "reasons", "plan_hash", "error", "versions", "seconds", "clean_fraction", "n_bad_channels"} feats = [c for c in legacy.columns if c in modern.columns and c not in skip] assert len(feats) > 60 bad = {} for f in feats: a, b = legacy[f].astype(float).to_numpy(), modern[f].astype(float).to_numpy() if (np.isfinite(a) != np.isfinite(b)).any(): bad[f] = "NaN in one only" continue ok = np.isfinite(a) if ok.any(): tol = TOL * max(1.0, float(np.abs(a[ok]).max())) if f == "coupling_angle_deg": d = np.abs((a[ok] - b[ok] + 180) % 360 - 180) else: d = np.abs(a[ok] - b[ok]) if d.max() > tol: bad[f] = float(d.max()) assert not bad, bad