Commit Graph

10 Commits

Author SHA1 Message Date
AlbertoPMDM acfd3a70d4 preprocessing: modern Preprocessor on MNE, agreeing with the director's output
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)).
2026-11-18 20:50:33 -06:00
AlbertoPMDM fcd0f76d76 validation: modern validation on MNE/SciPy, agreeing with the director's
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.
2026-11-18 20:47:07 -06:00
AlbertoPMDM 4956f36d80 serving (MLflow), HK1K verification command and the tea-verify DaskJob
- serving: plans and biomarkers as MLflow "models from code" (standalone
  wrapper files), code_paths = only the module's package + contracts;
  plan.json artifact and plan params; biomarker models pin plan_uri and
  plan_hash. privacy: no study codes / dates / paths, binary artifacts
  refused, baselines from fewer than 5 children refused.
- verify: python -m tea_modulo.verify hk1k lists HK1K in a worker task, runs
  the pipeline remotely (line 50 Hz), checks the remote run equals a plain
  sequential run in one task, summarizes the posterior rhythm by age group
  (groups < 5 suppressed) and writes the summary under processed/usuarios/.
  Any input prefix but raw/eeg-helsinki/ is refused.
- deploy: Dockerfile.verify (dask:1.1 + antropy, fhir.resources, meegkit,
  pytest; tea-modulo from the local checkout), .dockerignore keeping .venv,
  eeg/ and any signal or patient file out, dask-verify.yaml (own 2x4-worker
  cluster, no eeg-data PVC, keys only on workers), verify.sh.

Tests: MLflow round trips on sqlite, model loads with only its own code in
a fresh interpreter, privacy refusals, verify guards.
2026-11-18 20:24:03 -06:00
AlbertoPMDM 038836a701 pipeline: module registry, run_study, Dask runner and legacy serial executor
- 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.
2026-11-18 20:18:07 -06:00
AlbertoPMDM 441113c7b7 legacy: annotation_mask, sleep_state and posterior_rhythm on the director's code
- contracts: Preprocessed.quality_spans (QC-unclean stretches at the QC's
  own resolution), so the director's state mask can be rebuilt exactly.
- legacy.preprocessing: annotations straight from the EDF (exact onsets, as
  edf_convert), quality_spans from his 4 s QC.
- legacy processes annotation_mask (intervalos_estado, estado_de_ventana) and
  sleep_state (vigilancia.rasgos with senal._mascara_excluir's mask,
  clasificar with the HK1K cut-offs or cohort cut-offs after train()).
- legacy biomarker posterior_rhythm (medidas_director.ritmo on
  ritmo.psd_de_ventanas + pico_dominante) with a private _baseline.py holding
  curvas.py and perfil_alteraciones' age-block z, copied verbatim.
- Each legacy module owns its adapter, which writes the study in the
  director's preprocessed format and opens it with his eeg_io.Estudio.

Identical to the submodule's cluster route on a synthetic study (window
labels and rhythm); contract suites pass.
2026-11-18 20:12:47 -06:00
AlbertoPMDM 02a885dc10 PreprocessPlan, default plans and legacy.preprocessing
preprocessing.plan: frozen PreprocessPlan (steps, variants, state, gates,
bads, reasons) with checks, to_dict/from_dict (schema 1, unknown keys
refused) and a content hash; defaults DIRECTOR_CLUSTER and DIRECTOR_CLI
turn the route differences into data.

legacy.preprocessing maps the plan dict onto the director's
preproceso.procesar (vendored unchanged), refuses what his code cannot do
(zapline, other notch threshold, manual bads), returns MNE Raw variants and
the window grid flagged from his 4 s QC. Identical to the submodule for
both default plans.
2026-11-18 20:04:18 -06:00
AlbertoPMDM 25dd95a8ad legacy.validation: director's validation behind the Validator protocol
The director's scripts (biomarcadores-tea/preproceso @ 7dfc641) are vendored
unchanged except imports by tools/vendor_legacy.py, one copy per legacy
module; --check re-derives them from the pinned submodule.

LegacyValidation runs steps 1-4 of un_estudio.procesar for an EDF
(edf_convert, lote.excluidos_para_qc + qc_estudio + veredicto, triaje.triar,
60% clean windows) plus preproceso.MIN_CUERO, and returns an R4B FHIR Bundle
and 0/1. Tests: identical to the submodule on a synthetic EDF, contract
suite, not-valid case, vendor check.
2026-11-18 20:00:46 -06:00
AlbertoPMDM 2b4bea0c7f export: optional KTLX -> EDF+ exporter vendored from eeg@92bc2a0
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.
2026-11-18 19:54:48 -06:00
AlbertoPMDM 449acf8b44 contracts: shared data classes, protocols and contract test suites
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.
2026-11-18 19:54:15 -06:00
AlbertoPMDM fbfad83861 Initialize uv library project 2026-11-18 14:21:36 -06:00