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="