Skip to content

Commit

Permalink
normalize def, test, and add pylint to action
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-maris committed Sep 20, 2023
1 parent 468348e commit f048a0e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ jobs:
- name: Test with PyTest
run: |
python -m pytest --cov=inflammation.models tests/test_models.py
python -m pytest --cov=inflammation.models tests/test_models.py
- name: Check style with Pylint
run: |
python3 -m pylint --fail-under=0 --reports=y inflammation
10 changes: 10 additions & 0 deletions inflammation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ def daily_min(data):
"""

return np.min(data, axis=0)

def patient_normalise(data):
"""Normalise patient data from a 2D inflammation data array."""
max_val = np.nanmax(data, axis=1)
with np.errstate(invalid='ignore', divide='ignore'):
normalised = data / max_val[:, np.newaxis]
normalised[np.isnan(normalised)] = 0
normalised[normalised < 0] = 0

return normalised
15 changes: 14 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ def test_daily_min_string():
from inflammation.models import daily_min

with pytest.raises(TypeError):
error_expected = daily_min([['Hello', 'there'], ['General', 'Kenobi']])
error_expected = daily_min([['Hello', 'there'], ['General', 'Kenobi']])

@pytest.mark.parametrize(
"test, expected",
[
([[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]),
([[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]]),
([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[0.33, 0.67, 1], [0.67, 0.83, 1], [0.78, 0.89, 1]]),
])
def test_patient_normalise(test, expected):
"""Test normalisation works for arrays of one and positive integers.
Assumption that test accuracy of two decimal places is sufficient."""
from inflammation.models import patient_normalise
npt.assert_almost_equal(patient_normalise(np.array(test)), np.array(expected), decimal=2)

0 comments on commit f048a0e

Please sign in to comment.