- legacy: medidas_director.gradiente on gradiente.analizar (vendored), in
the 'sueno' and 'somnolencia' windows as analizar_director does.
- modern: Hann periodograms per window (MNE), median band power, Theil-Sen
slope (scipy.stats.theilslopes) on the director's front-back coordinates.
- 8 features gradient_<band>_<state>, one baseline each.
Legacy equals the submodule's cluster route exactly; modern within 0.01 of
legacy on the synthetic study.
- legacy: husos.detectar / husos.resumen vendored unchanged, run on the
'sueno' windows as medidas_director does; the wake rhythm that sets the
'rhythm near sigma' flag is computed inside the process (no biomarker
dependency).
- modern: the same detector on MNE (sigma band-pass) and SciPy (Hilbert,
Welch narrowness, phase stability); summary with the director's
definitions; one baseline per feature.
- privacy.group_size understands per-feature baseline dicts.
Legacy equals the submodule's cluster route exactly (spindle count and the
six summary measures); modern equals legacy on the synthetic study.
- processes.annotation_mask: the director's state words and interval rules
on the EDF+ annotations (MNE), window dominant state and 'mixta'.
- processes.sleep_state: vigilancia's features from batched Hann
periodograms (mne psd_array_welch), depth index, HK1K cut-offs or cohort
reference + KMeans (scikit-learn) after train().
- biomarkers.posterior_rhythm: Welch of the wake windows (MNE), 1/f-fitted
dominant peak, median of O1 O2 P3 P4; private copy of the baselines.
- Registered as the modern modules; Pipeline.default("modern") now runs
the full slice.
On a synthetic study: annotation states and sleep-state labels identical to
legacy, rhythm equal (6.5 Hz); contract suites and cohort cut-offs tested.
Executes a PreprocessPlan with MNE: EDF read and label normalisation, plan
bads dropped, line removal on the raw signal (interpolated notch when the
line is >= min_db on the kept scalp channels, or ZapLine via meegkit),
Raw.filter (IIR Butterworth order 4, zero phase, run by run between
BAD_ACQ_SKIP), set_eeg_reference (average of kept scalp / linked ears),
EOG/ECG filtered only. Window grid and quality spans from a private copy of
the window QC.
Within 0.25 uV of legacy.preprocessing on every channel of both default
plans away from the filter edges (max(5 s, 3/highpass)).
The director's rules (validacion.validar, preproceso.canales_malos,
lote.qc_estudio window QC, triaje.triar, cluster gates) rebuilt on MNE
(EDF reading, IIR filtering run by run, Welch PSD), SciPy and antropy (DFA).
All thresholds in rules.ValidationConfig with their sources; edfio header
checks (no silent resampling); R4B FHIR Bundle (private copy of the builder).
Agrees with legacy.validation on dropped channels, triage level and verdict
in every synthetic case; accepted differences (gaps as NaN, one notch, MNE
filter edges, no set-up detection) are documented and tested.
- Modules are looked up by name through entry points (tea_modulo.modules,
tea_modulo.legacy_modules) and checked against their protocol.
- run_study: one EDF to one small row (key, verdict, features, plan hash,
module versions; failures become error rows with paths removed).
- Modern batches are Dask-native: a dask.delayed graph under
annotate(priority=-10, retries=1), run on cluster='remote'|'local'|'sync'|
'auto'. Remote: Client(direct_to_workers=False), get_versions(check=True),
only close(). Local: processes, 1 thread, BLAS threads 1, closed by us.
- Legacy batches: tea_modulo.legacy.executor.run_serial, a plain loop.
- storage.local_copy fetches s3:// objects to a temp file inside the task.
Tests: legacy loop, Dask sync and a 2-worker LocalCluster give the same
table; error rows; positive priority refused; remote never shut down.
Step 2 of the plan. src/eeg/utils copied into tea_modulo.export with only the
imports changed; outside the EDF pipeline (extra `export`, script ktlx2edf).
Synthetic tests (ktlx_synth, edf export, patient) carried over: 43 pass.
Step 1 of the tea_modulo plan: Recording (MNE Raw from EDF), ValidationSummary,
Preprocessed, Labels, Study, the Validator/Preprocessor/Process/Biomarker
protocols with check_module(), reusable contract suites in contracts.testing,
and an AST test that enforces the module boundary rule.