Read keeps the file and says its format; extract takes fields from columns; EEG batches carry their recording, on Dask where it is installed

This commit is contained in:
Roberto Treviño
2026-11-27 16:25:01 -06:00
parent 3546269eaf
commit 385cc5b80b
7 changed files with 103 additions and 28 deletions
+10 -10
View File
@@ -8,12 +8,12 @@ mains, with the table's age) in worker processes; `tables` gives each scenario's
from the valid studies.
"""
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
import pandas as pd
from joblib import Parallel, delayed
from models import cluster
from models.tea.eeg.analysis import analyze
from models.tea.eeg.curves import SCENARIOS
@@ -34,9 +34,8 @@ 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(key: str, edf: bytes, age: float) -> dict:
a = analyze(edf, age_months=age, mains_hz=MAINS_HZ)
return {
"key": key,
"age_months": age,
@@ -46,11 +45,12 @@ def _one(study: tuple[str, Path, float]) -> dict:
}
def measure(studies, workers: int = 4) -> 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))
def measure(studies) -> list[dict]:
"""Each study's verdict and features, in listing order, each a task on the cluster
(models.cluster)."""
with cluster.batch(): # each task carries its recording: workers see no local folder
return Parallel(n_jobs=cluster.jobs())(delayed(_one)(key, Path(path).read_bytes(), age)
for key, path, age in studies) # fmt: skip
def tables(measured: list[dict]) -> dict[str, pd.DataFrame]: