File tree Expand file tree Collapse file tree 3 files changed +55
-5
lines changed Expand file tree Collapse file tree 3 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ def main(args):
1313 - selecting the necessary models and views for the current task
1414 - passing data between models and views
1515 """
16- InFiles = args .infiles
17- if not isinstance (InFiles , list ):
18- InFiles = [args .infiles ]
16+ infiles = args .infiles
17+ if not isinstance (infiles , list ):
18+ infiles = [args .infiles ]
1919
2020
21- for filename in InFiles :
21+ for filename in infiles :
2222 inflammation_data = models .load_csv (filename )
2323
2424 view_data = {'average' : models .daily_mean (inflammation_data ), 'max' : models .daily_max (inflammation_data ), 'min' : models .daily_min (inflammation_data )}
Original file line number Diff line number Diff line change @@ -32,3 +32,30 @@ 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 ]
39+
40+ def patient_normalise (data ):
41+ """
42+ Normalise patient data between 0 and 1 of a 2D inflammation data array.
43+
44+ Any NaN values are ignored, and normalised to 0
45+
46+ :param data: 2D array of inflammation data
47+ :type data: ndarray
48+
49+ """
50+ if not isinstance (data , np .ndarray ):
51+ raise TypeError ('data input should be ndarray' )
52+ if len (data .shape ) != 2 :
53+ raise ValueError ('inflammation array should be 2-dimensional' )
54+ if np .any (data < 0 ):
55+ raise ValueError ('inflammation values should be non-negative' )
56+ max = np .nanmax (data , axis = 1 )
57+ with np .errstate (invalid = 'ignore' , divide = 'ignore' ):
58+ normalised = data / max [:, np .newaxis ]
59+ normalised [np .isnan (normalised )] = 0
60+ return normalised
61+ ...
Original file line number Diff line number Diff line change 33import numpy as np
44import pytest
55import numpy .testing as npt
6+ import pytest_cov
67
78from inflammation .models import daily_mean
89
@@ -63,4 +64,26 @@ def test_daily_min():
6364 ])
6465def test_daily_mean (test , expected ):
6566 """Test mean function works for array of zeroes and positive integers."""
66- npt .assert_array_equal (daily_mean (np .array (test )), np .array (expected ))
67+ npt .assert_array_equal (daily_mean (np .array (test )), np .array (expected ))
68+
69+ def patient_normalise (data ):
70+ """
71+ Normalise patient data between 0 and 1 of a 2D inflammation data array.
72+
73+ Any NaN values are ignored, and normalised to 0
74+
75+ :param data: 2D array of inflammation data
76+ :type data: ndarray
77+
78+ """
79+ if not isinstance (data , np .ndarray ):
80+ raise TypeError ('data input should be ndarray' )
81+ if len (data .shape ) != 2 :
82+ raise ValueError ('inflammation array should be 2-dimensional' )
83+ if np .any (data < 0 ):
84+ raise ValueError ('inflammation values should be non-negative' )
85+ max = np .nanmax (data , axis = 1 )
86+ with np .errstate (invalid = 'ignore' , divide = 'ignore' ):
87+ normalised = data / max [:, np .newaxis ]
88+ normalised [np .isnan (normalised )] = 0
89+ return normalised
You can’t perform that action at this time.
0 commit comments