Skip to content

Commit 8f0f3aa

Browse files
committed
last commit
1 parent 93032a4 commit 8f0f3aa

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

inflammation/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ def daily_min(data):
3232
"""Calculate the daily min of a 2D inflammation data array."""
3333
return np.min(data, axis=0)
3434

35+
def patient_normalise(data):
36+
"""Normalise patient data from a 2D inflammation data array."""
37+
max = np.max(data, axis=0)
38+
return data / max[:, np.newaxis]

tests/test_models.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import pytest
66

77
from inflammation.models import daily_mean, daily_max, daily_min
8+
from inflammation.models import patient_normalise
9+
810

911

1012
def test_daily_mean_zeros():
@@ -94,4 +96,17 @@ def test_daily_min_string():
9496
])
9597
def test_daily_mean(test, expected):
9698
"""Test mean function works for array of zeroes and positive integers."""
97-
npt.assert_array_equal(daily_mean(np.array(test)), np.array(expected))
99+
npt.assert_array_equal(daily_mean(np.array(test)), np.array(expected))
100+
101+
102+
@pytest.mark.parametrize(
103+
"test, expected",
104+
[
105+
([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[0.33, 0.67, 1], [0.67, 0.83, 1], [0.78, 0.89, 1]])
106+
])
107+
def test_patient_normalise(test, expected):
108+
"""Test normalisation works for arrays of one and positive integers.
109+
Test with a relative and absolute tolerance of 0.01."""
110+
111+
result = patient_normalise(np.array(test))
112+
npt.assert_allclose(result, np.array(expected), rtol=1e-2, atol=1e-2)

0 commit comments

Comments
 (0)