The tea_eeg job: analyse, score the age curves, relate ADOS-2, rebuild gold; a sensor starts it after an ingest

Analysis and the reference cohort's measuring run on execution.map; relate is the
Phase 2 seam. A LocalCluster starts inside a multiprocess Dagster step (checked on a
real run), so the ops keep the default executor.
This commit is contained in:
2026-11-27 18:02:28 -06:00
parent 9220b8c52c
commit cc95054a96
4 changed files with 289 additions and 34 deletions
+8 -10
View File
@@ -4,16 +4,15 @@ children of 16 to 36 months, recorded on 50 Hz mains.
`listing` pairs each EDF under a folder with its age from the cohort's table (first column the
file name, second the age in years; months = years x 12 to one decimal); keys are positions in
path order, never file names. `measure` analyses each study as a hospital EEG (at the cohort's
mains, with the table's age) in worker processes; `tables` gives each scenario's training table
mains, with the table's age) in the cluster's workers; `tables` gives each scenario's training table
from the valid studies.
"""
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
import pandas as pd
from models import execution
from models.tea.eeg.analysis import analyze
from models.tea.eeg.curves import SCENARIOS
@@ -34,9 +33,9 @@ def listing(folder: Path, ages_table: Path, ages=AGES) -> list[tuple[str, Path,
return [(f"{NAME}-{k:04d}", path, age) for k, (path, age) in enumerate(found, 1)]
def _one(study: tuple[str, Path, float]) -> dict:
key, path, age = study
a = analyze(Path(path).read_bytes(), age_months=age, mains_hz=MAINS_HZ)
def _one(study: tuple[str, Path, float, float]) -> dict:
key, path, age, mains_hz = study
a = analyze(Path(path).read_bytes(), age_months=age, mains_hz=mains_hz)
return {
"key": key,
"age_months": age,
@@ -46,11 +45,10 @@ def _one(study: tuple[str, Path, float]) -> dict:
}
def measure(studies, workers: int = 4) -> list[dict]:
def measure(studies, workers: int | None = None, mains_hz: float = MAINS_HZ) -> list[dict]:
"""Each study's verdict and features, in listing order."""
context = multiprocessing.get_context("spawn")
with ProcessPoolExecutor(workers, mp_context=context) as pool:
return list(pool.map(_one, studies))
items = [(k, p, a, mains_hz) for k, p, a in studies]
return execution.map(_one, items, phase="measuring_reference", workers=workers)
def tables(measured: list[dict]) -> dict[str, pd.DataFrame]: