0e942e04c1
- verification/ (hk1k, issste, common) moved out of src/: not in the wheel; the image imports it with PYTHONPATH=/opt/tea-modulo. - python -m verification issste: every biomarker, legacy and modern, on processed/eeg-edf-2025|2026; age from the EDF header inside the task; group numbers only (file names, paths, dates and rows stay in the job). - Pipeline.map (Dask): a task that dies (KilledWorker) becomes an error row instead of stopping the batch. - deploy/verify.sh [hk1k|issste]; issste uses 3 workers x 6 GiB per pod.
80 lines
3.7 KiB
Markdown
80 lines
3.7 KiB
Markdown
# tea_modulo
|
|
|
|
EEG library for the TEA project: EDF in; validation, preprocessing, processes
|
|
and biomarkers out. Every biomarker and every process is its own module, and
|
|
modules talk only through `tea_modulo.contracts`, so any module can be replaced
|
|
without touching the others. Architecture plan:
|
|
https://claude.ai/artifact/H9Rh19Lv79dVeikeVD9KFZ
|
|
|
|
## Two implementations
|
|
|
|
| | `tea_modulo` (modern) | `tea_modulo.legacy` |
|
|
|---|---|---|
|
|
| Code | the director's methods on MNE, SciPy, scikit-learn, antropy, fooof, meegkit | the director's code (biomarcadores-tea @ 7dfc641, codigo @ c7a4736) copied unchanged except imports |
|
|
| Batches | Dask (`cluster="auto"/"remote"/"local"/"sync"`) | plain single-threaded loop |
|
|
| Checked against | legacy, on synthetic EDFs | the submodule's own scripts, exactly |
|
|
|
|
## Modules
|
|
|
|
| kind | name | requires |
|
|
|---|---|---|
|
|
| validator | `validation` | — |
|
|
| preprocessor | `preprocessing` | — |
|
|
| process | `annotation_mask` | — |
|
|
| process | `window_selection` | annotation_mask |
|
|
| process | `sleep_state` | annotation_mask |
|
|
| process | `slow_wave_staging` | sleep_state |
|
|
| process | `spindle_detection` | sleep_state (+ slow_wave_staging with `phase`) |
|
|
| biomarker | `posterior_rhythm` | sleep_state |
|
|
| biomarker | `spindles` | spindle_detection |
|
|
| biomarker | `gradient` | sleep_state |
|
|
| biomarker | `slow_waves` | slow_wave_staging |
|
|
| biomarker | `aperiodic`, `mse` | sleep_state, annotation_mask |
|
|
| biomarker | `coupling` | spindle_detection (+ slow_wave_staging with `in_slow_wave`) |
|
|
| biomarker | `spindle_topography` | spindle_detection, sleep_state |
|
|
| biomarker | `spikes` | sleep_state (modern: + annotation_mask) |
|
|
|
|
## Use
|
|
|
|
```python
|
|
from tea_modulo.validation import validate
|
|
bundle, valid = validate("study.edf") # R4B FHIR Bundle, 1 valid / 0 not valid
|
|
|
|
from tea_modulo.pipeline import Pipeline
|
|
from tea_modulo.preprocessing import DIRECTOR_CLUSTER
|
|
pipe = Pipeline.default() # or Pipeline.default(impl="legacy")
|
|
study = pipe.study("study.edf", plan=DIRECTOR_CLUSTER, age_months=27.5)
|
|
pipe.biomarker("posterior_rhythm").measure(study)
|
|
|
|
table = pipe.map(paths, plan=DIRECTOR_CLUSTER, ages_months=ages,
|
|
biomarkers=("posterior_rhythm", "spindles")) # Dask: cluster or LocalCluster
|
|
rhythm = pipe.biomarker("posterior_rhythm").train(table) # baseline: curves or age_blocks
|
|
rhythm.predict(table.iloc[[0]]) # outside -1/0/+1, z
|
|
|
|
from tea_modulo.serving import log_plan, log_biomarker # MLflow models, privacy guard
|
|
```
|
|
|
|
Replace a module: `pipe.replace("spindle_detection", MyDetector())`, or register
|
|
it under the same name in the `tea_modulo.modules` entry-point group. Check it
|
|
with `tea_modulo.contracts.testing`.
|
|
|
|
## Tests and cluster verification
|
|
|
|
- `uv run pytest` (synthetic EDFs only; no patient data).
|
|
- Cluster checks live in `verification/`, outside the package (not in the
|
|
wheel). `deploy/verify.sh` builds `tea-verify:<commit>` from this checkout and
|
|
runs one in a `DaskJob` of its own:
|
|
- `deploy/verify.sh` (`hk1k`): the test suite plus `python -m verification hk1k`
|
|
(HK1K, public, `raw/eeg-helsinki/`);
|
|
- `deploy/verify.sh issste`: `python -m verification issste` on
|
|
`processed/eeg-edf-2025/` and `eeg-edf-2026/`, with every biomarker in both
|
|
implementations.
|
|
- `deploy/verify.sh --logs`, `--delete`.
|
|
- `python tools/vendor_legacy.py --check` confirms the legacy copies are
|
|
unchanged.
|
|
|
|
The unit tests never read patient data. Both cluster checks write group
|
|
summaries only, to `processed/usuarios/`. The ISSSTELEÓN check keeps file
|
|
names, paths, birthdates and per-study rows inside the job (the 2026 file names
|
|
carry the patient's surname), and suppresses groups under 5.
|