F7c: one spindle metric over all NREM sleep

Spindles are measured once, over every window the state classifier labels
sleep, and each child's detection thresholds come from all NREM sleep
samples. The 75 uV slow-wave rule labelled 89 % of the epochs after N2
onset in Helsinki toddlers (16-36 months) as N3 and was never validated
against technician-scored stages (biomarcadores-tea E13, usar_n3 = false).

spindles_n2 and spindles_n3 become spindles; the four N2/N3 age scenarios
become eeg-spindles and eeg-spindle-topography. The director's flag for a
posterior rhythm near the sigma band is kept as the rhythm_near_sigma
feature. Reasons: no-sleep under one minute of sleep, else no-spindles.
This commit is contained in:
2026-12-03 20:47:28 -06:00
parent cb1c6bc7ee
commit ee9537b1f2
8 changed files with 130 additions and 94 deletions
+4 -6
View File
@@ -12,6 +12,7 @@ MIN_EFFECTIVE = 30
COUNT_AGES = (16.0, 37.0)
Z_MAX = 8.0
EXPOSURE = "minutes"
NOT_MEASURES = ("age_months", EXPOSURE, "rhythm_near_sigma")
SCORE_FIELDS = ("z", "outside", "p5", "median", "p95")
@@ -19,16 +20,13 @@ SCORE_FIELDS = ("z", "outside", "p5", "median", "p95")
class Scenario:
metric: str
parts: tuple[str, ...]
stage: str | None = None
counts: bool = False
SCENARIOS = {
"eeg-posterior-rhythm": Scenario("posterior_rhythm", ("value",)),
"eeg-spindles-n2": Scenario("spindles_n2", ("value", "zones"), "N2"),
"eeg-spindle-topography-n2": Scenario("spindles_n2", ("electrodes",), "N2"),
"eeg-spindles-n3": Scenario("spindles_n3", ("value", "zones"), "N3"),
"eeg-spindle-topography-n3": Scenario("spindles_n3", ("electrodes",), "N3"),
"eeg-spindles": Scenario("spindles", ("value", "zones")),
"eeg-spindle-topography": Scenario("spindles", ("electrodes",)),
"eeg-spikes": Scenario("paroxysmal_spikes", ("value", "electrodes", "zones"), counts=True),
"eeg-gradient": Scenario("anteroposterior_gradient", ("value",)),
}
@@ -85,7 +83,7 @@ def train(features: pd.DataFrame, scenario: str) -> dict:
counts = SCENARIOS[scenario].counts
ages = features["age_months"].to_numpy(float)
out = {}
for name in features.columns.drop(["age_months", EXPOSURE], errors="ignore"):
for name in features.columns.drop(list(NOT_MEASURES), errors="ignore"):
values = pd.to_numeric(features[name]).to_numpy(float)
if counts:
out[name] = _count_rate(values, ages, features[EXPOSURE].to_numpy(float))