Files
models/models
alberto f6a289e774 F7g: signal preparation as biomarcadores-tea (flat reference, symmetric Hann, mains, stable start, clamps)
Port the five F7f signal-preparation differences from biomarcadores-tea
23cafa4 and the read-only counterfactual source. Reference measurement
retains exactly one flat scalp electrode in the original channel order
and average reference, excluding it from QC. Patients default to dropping
bad flat channels. Periodograms remove the mean and use symmetric Hann
density. Preparation uses the requested mains frequency and raw-channel
IIR notch QC. Stable start masks setup windows and limits fixed-line
detection to the useful suffix. Sleep band sums recover the source FFT
scale before applying clamps.

Files changed (relative to the parent worktree):
- models/models/tea/eeg/preprocess.py
- models/models/tea/eeg/signals.py
- models/models/tea/eeg/sleep.py
- models/models/tea/eeg/analysis.py
- models/models/tea/eeg/reference.py
- models/models/tea/eeg/checks.py (coordinator-approved scope/signature)
- models/tests/test_eeg.py

Internal choices left open by the spec:
- Keep the IIR implementation private as preprocess._iir_notch and the
  annotation word lists private as _START_MARKS and _SETUP_MARKS. Stack
  the Q=30 sections and filter finite runs through signals.by_runs with
  the counterfactual minimum length and harmonic enumeration.
- Preserve the counterfactual flat predicate, not nanstd > 0.5, including
  its treatment of nonfinite standard deviations. Derive QC channels
  from raw scalp data excluding the retained flat electrode; filtering
  finite runs supplies the QC gap mask independently of that electrode.
- Calculate the symmetric Hann once per periodograms call. For odd FFT
  lengths double the final bin, since it has no Nyquist bin; for even
  lengths exclude both DC and Nyquist from doubling.
- Retain the exact stable-start finite-window count, median of channel
  standard deviations, second-half reference, suffix tolerance, sorted
  annotation precedence, accent removal and short-record return. Convert
  the selected annotation onset to a Python float.
- Use int(start_s * fs) for the fixed-line suffix. At thirty seconds or
  less remaining, use the full signal, as the tested counterfactual does.
- Add start_s to the existing rejected-minutes scalar dictionary after
  successful measurement. Recompute stable_start(rec) for reporting to
  keep Prepared's existing public shape. Invalid/error paths retain
  their existing result handling.
- Extend the existing test_eeg.py with deterministic seeded synthetic
  arrays, direct NumPy spectra and SciPy IIR comparisons. Exercise odd
  and even spectra, a 60-second setup prefix with the source's 90-percent
  suffix rule, accented and unordered annotations, the thirty-second
  fixed-line boundary, small-power clamps and analysis/reference calls.
  No real-data fixture or source repository was modified.

Validation from the parent worktree root with the requested shared venv:
- ruff check: passed.
- ruff format --check: passed, 152 files already formatted.
- lint-imports --no-cache: passed, 2 contracts kept, 0 broken.
- pytest -q -rs: 116 passed, 7 warnings, covering test_eeg,
  test_eeg_reasons, test_eeg_spikes, test_eeg_spindles, test_edf_header,
  test_tea_notes, test_tea_training_source, test_tea_preview, test_tea_job
  and test_curves. Run with flock /home/milk/tea-parity/heavy.lock
  nice -n 10 and worktree package roots on PYTHONPATH.
- git diff --check in models and the parent: passed.

All specified checks completed. Helsinki reference remeasurement is a
follow-up after the port, not part of this synthetic-array implementation.
2026-12-04 00:50:28 -06:00
..