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.
27 lines
806 B
Python
27 lines
806 B
Python
import pytest
|
|
|
|
from models.tea.eeg import curves
|
|
|
|
|
|
def test_centile_interpolation_preserves_scoring():
|
|
baseline = {
|
|
"kind": "curves",
|
|
"curve": {
|
|
"age_months": [16, 36],
|
|
"p5": [1, 3],
|
|
"p25": [2, 4],
|
|
"median": [3, 5],
|
|
"p75": [5, 7],
|
|
"p95": [7, 9],
|
|
},
|
|
}
|
|
assert curves.centiles(baseline, 24) == pytest.approx(
|
|
{"p5": 2, "p25": 3, "median": 4, "p75": 6, "p95": 8}
|
|
)
|
|
for value, z, outside in ((0, -3.29, -1), (3, -0.8225, 0), (6, 0.8225, 0), (10, 2.4675, 1)):
|
|
scored = curves.score(baseline, value, 24)
|
|
assert scored.pop("reason") is None
|
|
assert scored == pytest.approx(
|
|
{"z": z, "outside": outside, "p5": 2, "median": 4, "p95": 8}, rel=1e-9
|
|
)
|