From fe36d5d85921f0b6e9e3d14aac2e417168d7d0d3 Mon Sep 17 00:00:00 2001 From: AlbertoPMDM Date: Thu, 19 Nov 2026 04:09:48 -0600 Subject: [PATCH] =?UTF-8?q?EDF=20annotation=20texts=20not=20in=20UTF-8=20(?= =?UTF-8?q?ISSSTELE=C3=93N):=20legacy=20reads=20them=20as=20edf=5Fconvert?= =?UTF-8?q?=20does,=20modern=20retries=20latin1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tea_modulo/contracts/data.py | 7 ++++++- src/tea_modulo/legacy/preprocessing/api.py | 20 ++++++++++++++++++-- src/tea_modulo/preprocessing/api.py | 7 ++++++- src/tea_modulo/validation/api.py | 9 +++++++-- tests/test_pipeline.py | 17 +++++++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/tea_modulo/contracts/data.py b/src/tea_modulo/contracts/data.py index 529b7c3..4cb23fb 100644 --- a/src/tea_modulo/contracts/data.py +++ b/src/tea_modulo/contracts/data.py @@ -69,7 +69,12 @@ class Recording: import mne path = Path(path) - raw = mne.io.read_raw_edf(path, preload=True, verbose="error") + try: + raw = mne.io.read_raw_edf(path, preload=True, verbose="error") + except Exception as e: # annotation texts in a Windows code page + if "latin1" not in str(e): + raise + raw = mne.io.read_raw_edf(path, preload=True, verbose="error", encoding="latin1") return cls(raw=raw, age_months=age_months, source_sha256=sha256_of(path), source_name=path.stem) diff --git a/src/tea_modulo/legacy/preprocessing/api.py b/src/tea_modulo/legacy/preprocessing/api.py index 84e1e4d..09991a0 100644 --- a/src/tea_modulo/legacy/preprocessing/api.py +++ b/src/tea_modulo/legacy/preprocessing/api.py @@ -183,8 +183,24 @@ def _annotations(edf_path): """Every EDF+ annotation with its exact onset and duration, as edf_convert reads them (the director keeps BAD_ACQ_SKIP among his events too).""" import mne - a = mne.read_annotations(edf_path) - return mne.Annotations(list(a.onset), list(a.duration), list(a.description)) + from ._director import edf_convert + out = [] + with open(edf_path, "rb") as f: # edf_convert.leer_edf, annotation channels only + h = edf_convert.leer_cabecera(f) + idx = [i for i, e in enumerate(h["etiquetas"]) if e.strip().upper() == "EDF ANNOTATIONS"] + if idx: + n_reg, por_reg = h["n_registros"], sum(h["n_muestras"]) + if n_reg < 0: + f.seek(0, 2) + n_reg = (f.tell() - h["bytes_cabecera"]) // (por_reg * 2) + f.seek(h["bytes_cabecera"]) + crudo = np.fromfile(f, dtype="