Assign spike candidates and accepted gate midpoints to the inherited 0.5 s
state grid, with a 30 s reach, no state before the first labelled window,
and transitions between different surrounding labels. Count useful sleep
and awake discharges separately. Export awake_rate, awake_minutes and each
zone's electrode count as features without adding metrics or baselines.
Train zone count baselines from value times minutes over minutes times
present electrodes. Keep observed counts and reported zone rates in their
existing units while scaling expected counts by the child's electrodes.
Carry the optional electrodes argument through curves.score, deviations,
Baseline.predict and saved-study scoring as specified by the coordinator.
Internal choices:
- Use a private NumPy grid helper, preserve labelled-window input order,
and look up times by flooring into half-open 0.5 s cells. Keep the
existing internal unlabelled sentinel. Apply the 30 s limit before
assigning either an inherited label or transition.
- Append the three required fields to Spikes. Use integer zone electrode
counts, including zero for absent zones. The few-electrode fallback
reports available zone members, zero awake minutes and a NaN awake rate.
- Divide rates by accumulated minutes before rounding. Round overall
sleep and awake rates to three decimals, minutes to four, and retain
four decimals for electrode and zone rates. Missing state exposure
produces NaN rates.
- Preserve rounded event reconstruction and the existing count-law fit.
Missing or null training electrode counts default to one; scoring
normalizes nonfinite counts to the same default. Nonpositive electrode
exposure yields no-exposure when scoring and is excluded when training.
Score centiles remain counts divided by minutes.
- Use invented intervals, counts and deterministic candidate fixtures;
keep the quality gate, candidate extraction and merging rules unchanged.
Validation from the worktree root using the shared virtualenv, with local
package roots on PYTHONPATH:
- ruff check models: passed.
- ruff format --check models: passed, 56 files.
- ruff format --check: passed, 152 files.
- lint-imports: passed, both contracts kept.
- pytest test_eeg_spikes, test_curves, test_eeg, test_eeg_reasons,
test_eeg_spindles and test_tea_job: 46 passed; run under
flock /home/milk/tea-parity/heavy.lock nice -n 10.
- git diff --check: passed.
Whole-repository ruff check also ran and found the pre-existing E501 at
tests/test_dbt_tea_follow_up.py:35, confirmed in HEAD. That file is outside
this task's allowed scope and is unchanged.
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.
Study level: Validation.reasons, built from the three gates that decide
validity (triage-not-analyzable, few-clean-minutes, few-electrodes; the
library's run_study reasons plus its usable-electrode gate) and
invalid-file for an unreadable file. Analysis.reasons sits next to
valid, level and clean_fraction.
Window level: the spike detector's 2 s gate now records every reason a
window is rejected (gap, state, mixed-states, muscle, frozen) and the
minutes rejected by each, kept in Spikes.rejected. A window can count
under more than one reason, as in the library. The platform has no
transient rejection, so there is no transient reason.
Metric level: biomarkers.measure returns a Measured result with the
reason per unmeasured metric: few-wake-windows and no-dominant-peak
(posterior rhythm), no-n2 and no-n3 (under one minute of the stage or no
events), no-sleep and few-electrodes (gradient, spikes). A study that is
not valid now returns its five metrics with no value, each carrying
invalid-eeg. Curve scoring returns a reason next to z: no-age,
age-out-of-range and no-exposure, because only scoring knows the
baseline's age coverage.
The reasons and the rejected minutes travel in the features JSON under
metric-reasons and rejected-minutes, outside the scenario keys so the
reference tables and curve training do not see them.
Remove 212 Python docstrings and 118 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files.
Preserve the existing executable statements and lint pragmas. Use pass for class bodies that previously consisted of only a docstring.
1. No prose in code
- Remove parity-added comments and docstrings from TEA jobs, analysis and
scoring helpers, execution, definitions, and tests. Keep base prose and
Ruff and type-checker directives.
2. No hacks, no glued code
- Delegate both association cohort queries to persistance.eeg. Keep the
predictor mapping and DataFrame shaping in the job, sharing biomarker
codes and EEG study IDs with Core. Preserve column names and order, row
selection, score filtering, and earliest fitting study.
- Use the existing MODELS registry for curve scoring in place of CURVES.
Keep GOLD because the generic score job reads it.
- Catch lookup, database, and validation failures when loading a preview
pipeline, preserving the existing warning. Keep execution-boundary
exception handling for submitted tasks, telemetry and shutdown.
- Name the association test for the missing-champion case. Preserve its
assertion and the other test assertions.
3. Everything in its place
- Keep SQL in Persistance, cohort shaping in models, and tests in their
existing testpaths. Keep the association fits together with their
shared design and result machinery.
Share log-age interpolation with scoring and preserve nulls outside coverage. Use a synthetic geometric midpoint and values on both sides of the median to check numeric parity.