""" Legacy window_selection: seleccion.seleccionar (vendored unchanged) on the contract adapter: 2 s windows with a 1 s step, each usable or not for spike search (excluded state, mixed states, transient, muscle, frozen signal). events: one row per 2 s window (onset_s, duration_s, apto, motivo, estado, ...). """ from __future__ import annotations import contextlib import io import json from pathlib import Path import pandas as pd from tea_modulo.contracts import CONTRACT_VERSION, Labels from . import _adapter DIRECTOR_COMMIT = "7dfc641" class LegacyWindowSelection: name = "window_selection" version = f"0.1.0+director.{DIRECTOR_COMMIT}" contract_version = CONTRACT_VERSION requires: tuple[str, ...] = () impl = "legacy" def __init__(self, variant: str = "hp05_prom", window_s: float = 2.0, step_s: float = 1.0): self.variant, self.window_s, self.step_s = variant, window_s, step_s def train(self, studies): return self def predict(self, study) -> Labels: from ._director import eeg_io, seleccion with _adapter.estudio(study.prep, self.variant, eeg_io) as est, contextlib.redirect_stdout(io.StringIO()): t = seleccion.seleccionar(est, vent_s=self.window_s, paso_s=self.step_s) t = t.assign(onset_s=t.t_ini_s.astype(float), duration_s=(t.t_fin_s - t.t_ini_s).astype(float)) return Labels(self.name, events=t.reset_index(drop=True)) def save(self, path): Path(path, "params.json").write_text(json.dumps( {"variant": self.variant, "window_s": self.window_s, "step_s": self.step_s})) @classmethod def load(cls, path): return cls(**json.loads(Path(path, "params.json").read_text())) MODULE = LegacyWindowSelection()