@@ -12,17 +12,17 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
12
12
cods = soiling .CODSAnalysis (cods_normalized_daily )
13
13
df_out , results_dict = \
14
14
cods .iterative_signal_decomposition ()
15
- assert 0.080641 == pytest .approx (results_dict ['degradation' ], abs = 1e-6 ),\
15
+ assert 0.080641 == pytest .approx (results_dict ['degradation' ], abs = 1e-6 ), \
16
16
'Degradation rate different from expected value'
17
- assert 3.305136 == pytest .approx (results_dict ['soiling_loss' ], abs = 1e-6 ),\
17
+ assert 3.305136 == pytest .approx (results_dict ['soiling_loss' ], abs = 1e-6 ), \
18
18
'Soiling loss different from expected value'
19
- assert 0.999359 == pytest .approx (results_dict ['residual_shift' ], abs = 1e-6 ),\
19
+ assert 0.999359 == pytest .approx (results_dict ['residual_shift' ], abs = 1e-6 ), \
20
20
'Residual shift different from expected value'
21
- assert 0.008144 == pytest .approx (results_dict ['RMSE' ], abs = 1e-6 ),\
21
+ assert 0.008144 == pytest .approx (results_dict ['RMSE' ], abs = 1e-6 ), \
22
22
'RMSE different from expected value'
23
23
assert not results_dict ['small_soiling_signal' ], \
24
24
'Small soiling signal assertion different from expected value'
25
- assert 7.019626e-11 == pytest .approx (results_dict ['adf_res' ][1 ], abs = 1e-6 ),\
25
+ assert 7.019626e-11 == pytest .approx (results_dict ['adf_res' ][1 ], abs = 1e-6 ), \
26
26
'p-value of Augmented Dickey-Fuller test different from expected value'
27
27
28
28
# Check result dataframe
@@ -31,10 +31,10 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
31
31
'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]
32
32
actual_columns = df_out .columns .values
33
33
for x in actual_columns :
34
- assert x in expected_columns ,\
34
+ assert x in expected_columns , \
35
35
"'{}' not an expected column in result_df]" .format (x )
36
36
for x in expected_columns :
37
- assert x in actual_columns ,\
37
+ assert x in actual_columns , \
38
38
"'{}' was expected as a column, but not in result_df" .format (x )
39
39
assert isinstance (df_out , pd .DataFrame ), 'result_df not a dataframe'
40
40
expected_means = pd .Series ({'soiling_ratio' : 0.9669486267086722 ,
@@ -48,7 +48,7 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
48
48
['soiling_ratio' , 'soiling_rates' , 'cleaning_events' ,
49
49
'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]]
50
50
pd .testing .assert_series_equal (expected_means , df_out .mean (),
51
- check_exact = False , check_less_precise = True )
51
+ check_exact = False , rtol = 1e-3 )
52
52
53
53
54
54
def test_iterative_signal_decomposition_with_nan_interval (cods_normalized_daily ):
@@ -59,17 +59,17 @@ def test_iterative_signal_decomposition_with_nan_interval(cods_normalized_daily)
59
59
cods = soiling .CODSAnalysis (normalized_corrupt )
60
60
df_out , results_dict = \
61
61
cods .iterative_signal_decomposition ()
62
- assert - 0.004968 == pytest .approx (results_dict ['degradation' ], abs = 1e-5 ),\
62
+ assert - 0.004968 == pytest .approx (results_dict ['degradation' ], abs = 1e-5 ), \
63
63
'Degradation rate different from expected value'
64
- assert 3.232171 == pytest .approx (results_dict ['soiling_loss' ], abs = 1e-5 ),\
64
+ assert 3.232171 == pytest .approx (results_dict ['soiling_loss' ], abs = 1e-5 ), \
65
65
'Soiling loss different from expected value'
66
- assert 1.000108 == pytest .approx (results_dict ['residual_shift' ], abs = 1e-5 ),\
66
+ assert 1.000108 == pytest .approx (results_dict ['residual_shift' ], abs = 1e-5 ), \
67
67
'Residual shift different from expected value'
68
- assert 0.008184 == pytest .approx (results_dict ['RMSE' ], abs = 1e-5 ),\
68
+ assert 0.008184 == pytest .approx (results_dict ['RMSE' ], abs = 1e-5 ), \
69
69
'RMSE different from expected value'
70
70
assert not results_dict ['small_soiling_signal' ], \
71
71
'Small soiling signal assertion different from expected value'
72
- assert 1.230754e-8 == pytest .approx (results_dict ['adf_res' ][1 ], abs = 1e-6 ),\
72
+ assert 1.230754e-8 == pytest .approx (results_dict ['adf_res' ][1 ], abs = 1e-6 ), \
73
73
'p-value of Augmented Dickey-Fuller test different from expected value'
74
74
75
75
# Check result dataframe
@@ -85,21 +85,21 @@ def test_iterative_signal_decomposition_with_nan_interval(cods_normalized_daily)
85
85
['soiling_ratio' , 'soiling_rates' , 'cleaning_events' ,
86
86
'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]]
87
87
pd .testing .assert_series_equal (expected_means , df_out .mean (),
88
- check_exact = False , check_less_precise = True )
88
+ check_exact = False , rtol = 1e-3 )
89
89
90
90
91
91
def test_soiling_cods (cods_normalized_daily ):
92
92
''' Test the CODS algorithm with fixed test case and 16 repetitions'''
93
93
reps = 16
94
94
np .random .seed (1977 )
95
95
sr , sr_ci , deg , deg_ci , result_df = soiling .soiling_cods (cods_normalized_daily , reps = reps )
96
- assert 0.962207 == pytest .approx (sr , abs = 0.5 ),\
96
+ assert 0.962207 == pytest .approx (sr , abs = 0.5 ), \
97
97
'Soiling ratio different from expected value'
98
- assert np .array ([0.96662419 , 0.95692131 ]) == pytest .approx (sr_ci , abs = 0.5 ),\
98
+ assert np .array ([0.96662419 , 0.95692131 ]) == pytest .approx (sr_ci , abs = 0.5 ), \
99
99
'Confidence interval of SR different from expected value'
100
- assert 0.09 == pytest .approx (deg , abs = 0.5 ),\
100
+ assert 0.09 == pytest .approx (deg , abs = 0.5 ), \
101
101
'Degradation rate different from expected value'
102
- assert np .array ([- 0.17143952 , 0.39313724 ]) == pytest .approx (deg_ci , abs = 0.5 ),\
102
+ assert np .array ([- 0.17143952 , 0.39313724 ]) == pytest .approx (deg_ci , abs = 0.5 ), \
103
103
'Confidence interval of degradation rate different from expected value'
104
104
105
105
# Check result dataframe
@@ -111,13 +111,26 @@ def test_soiling_cods(cods_normalized_daily):
111
111
'model_high' ]
112
112
actual_summary_columns = result_df .columns .values
113
113
for x in actual_summary_columns :
114
- assert x in expected_summary_columns ,\
114
+ assert x in expected_summary_columns , \
115
115
"'{}' not an expected column in result_df]" .format (x )
116
116
for x in expected_summary_columns :
117
- assert x in actual_summary_columns ,\
117
+ assert x in actual_summary_columns , \
118
118
"'{}' was expected as a column, but not in result_df" .format (x )
119
119
120
120
121
+ def test_soiling_cods_small_signal (cods_normalized_daily_small_soiling ):
122
+ ''' Test the CODS algorithm with small soiling signal'''
123
+ reps = 16
124
+ np .random .seed (1977 )
125
+ warn_small_signal = (
126
+ 'Soiling signal is small relative to the noise. '
127
+ 'Iterative decomposition not possible. '
128
+ 'Degradation found by RdTools YoY.' )
129
+
130
+ with pytest .warns (UserWarning , match = warn_small_signal ):
131
+ soiling .soiling_cods (cods_normalized_daily_small_soiling , reps = reps )
132
+
133
+
121
134
def test_Kalman_filter_for_SR (cods_normalized_daily ):
122
135
'''Test the Kalman Filter method in CODS'''
123
136
cods = soiling .CODSAnalysis (cods_normalized_daily )
@@ -131,10 +144,10 @@ def test_Kalman_filter_for_SR(cods_normalized_daily):
131
144
'soiling_rates' , 'cleaning_events' , 'days_since_ce' ]
132
145
actual_columns = dfk .columns .values
133
146
for x in actual_columns :
134
- assert x in expected_columns ,\
147
+ assert x in expected_columns , \
135
148
"'{}' not an expected column in Kalman Filter results]" .format (x )
136
149
for x in expected_columns :
137
- assert x in actual_columns ,\
150
+ assert x in actual_columns , \
138
151
"'{}' was expected as a column, but not in Kalman Filter results" .format (x )
139
152
assert Ps .shape == (732 , 2 , 2 ), "Shape of array of covariance matrices (Ps) not as expected"
140
153
0 commit comments