3a409afcaa
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.
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
from models.tea.eeg import curves, signals
|
|
|
|
|
|
def test_score_without_value_or_coverage():
|
|
table = pd.DataFrame({"value": [1.0, 2.0, 3.0], "age_months": [20.0, 25.0, 30.0]})
|
|
baseline = curves.train(table, "eeg-gradient")["value"]
|
|
empty = dict.fromkeys(("z", "outside", "p5", "median", "p95"))
|
|
assert curves.score(baseline, None, 25.0) == {**empty, "reason": None}
|
|
assert curves.score(baseline, 2.0, 25.0) == {**empty, "reason": "age-out-of-range"}
|
|
|
|
|
|
def test_dominant_peak_recovers_a_posterior_rhythm_above_background():
|
|
frequencies = np.arange(1.0, 46.0, 0.5)
|
|
background = 1 / frequencies
|
|
power = background.copy()
|
|
power[frequencies == 8] *= 10
|
|
assert signals.dominant_peak(frequencies, power) == (8.0, pytest.approx(10), True)
|
|
assert not signals.dominant_peak(frequencies, background)[2]
|
|
|
|
|
|
def test_band_power_excludes_line_noise_and_rescales_clean_bins():
|
|
frequencies = np.arange(7.0, 14.0)
|
|
power = np.array([100.0, 2.0, 30.0, 40.0, 30.0, 4.0, 100.0])
|
|
assert signals.band_power(frequencies, power, 8, 13, lines=(10,)) == 15
|