window_selection and spikes, legacy and modern
- legacy: seleccion.seleccionar and candidatos_punta.de_estudio + indicadores vendored unchanged, run on the contract adapter with the sleep_state labels as the vigilancia table. - modern: the director's detector functions copied by name into _detector.py with three substitutions (MNE band-pass, channel lists from the study, a private port of the seleccion gate); a modern window_selection on the same port. - synthetic builder: optional focal spike-and-wave (the director's own _punta shape) with a field on the neighbours. Modern equals legacy exactly on window verdicts and spike indicators; the C3 focus is found; contract suites pass.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
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()
|
||||
Reference in New Issue
Block a user