Expose TEA baseline centiles by age
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.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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],
|
||||
},
|
||||
}
|
||||
# At the geometric midpoint, the original log-age interpolation gives the means.
|
||||
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)):
|
||||
assert curves.score(baseline, value, 24) == pytest.approx(
|
||||
{"z": z, "outside": outside, "p5": 2, "median": 4, "p95": 8}, rel=1e-9
|
||||
)
|
||||
Reference in New Issue
Block a user