@@ -12,17 +12,17 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
1212 cods = soiling .CODSAnalysis (cods_normalized_daily )
1313 df_out , results_dict = \
1414 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 ), \
1616 '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 ), \
1818 '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 ), \
2020 '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 ), \
2222 'RMSE different from expected value'
2323 assert not results_dict ['small_soiling_signal' ], \
2424 '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 ), \
2626 'p-value of Augmented Dickey-Fuller test different from expected value'
2727
2828 # Check result dataframe
@@ -31,10 +31,10 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
3131 'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]
3232 actual_columns = df_out .columns .values
3333 for x in actual_columns :
34- assert x in expected_columns ,\
34+ assert x in expected_columns , \
3535 "'{}' not an expected column in result_df]" .format (x )
3636 for x in expected_columns :
37- assert x in actual_columns ,\
37+ assert x in actual_columns , \
3838 "'{}' was expected as a column, but not in result_df" .format (x )
3939 assert isinstance (df_out , pd .DataFrame ), 'result_df not a dataframe'
4040 expected_means = pd .Series ({'soiling_ratio' : 0.9669486267086722 ,
@@ -48,7 +48,7 @@ def test_iterative_signal_decomposition(cods_normalized_daily):
4848 ['soiling_ratio' , 'soiling_rates' , 'cleaning_events' ,
4949 'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]]
5050 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 )
5252
5353
5454def 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)
5959 cods = soiling .CODSAnalysis (normalized_corrupt )
6060 df_out , results_dict = \
6161 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 ), \
6363 '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 ), \
6565 '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 ), \
6767 '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 ), \
6969 'RMSE different from expected value'
7070 assert not results_dict ['small_soiling_signal' ], \
7171 '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 ), \
7373 'p-value of Augmented Dickey-Fuller test different from expected value'
7474
7575 # Check result dataframe
@@ -85,21 +85,21 @@ def test_iterative_signal_decomposition_with_nan_interval(cods_normalized_daily)
8585 ['soiling_ratio' , 'soiling_rates' , 'cleaning_events' ,
8686 'seasonal_component' , 'degradation_trend' , 'total_model' , 'residuals' ]]
8787 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 )
8989
9090
9191def test_soiling_cods (cods_normalized_daily ):
9292 ''' Test the CODS algorithm with fixed test case and 16 repetitions'''
9393 reps = 16
9494 np .random .seed (1977 )
9595 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 ), \
9797 '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 ), \
9999 '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 ), \
101101 '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 ), \
103103 'Confidence interval of degradation rate different from expected value'
104104
105105 # Check result dataframe
@@ -111,13 +111,26 @@ def test_soiling_cods(cods_normalized_daily):
111111 'model_high' ]
112112 actual_summary_columns = result_df .columns .values
113113 for x in actual_summary_columns :
114- assert x in expected_summary_columns ,\
114+ assert x in expected_summary_columns , \
115115 "'{}' not an expected column in result_df]" .format (x )
116116 for x in expected_summary_columns :
117- assert x in actual_summary_columns ,\
117+ assert x in actual_summary_columns , \
118118 "'{}' was expected as a column, but not in result_df" .format (x )
119119
120120
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+
121134def test_Kalman_filter_for_SR (cods_normalized_daily ):
122135 '''Test the Kalman Filter method in CODS'''
123136 cods = soiling .CODSAnalysis (cods_normalized_daily )
@@ -131,10 +144,10 @@ def test_Kalman_filter_for_SR(cods_normalized_daily):
131144 'soiling_rates' , 'cleaning_events' , 'days_since_ce' ]
132145 actual_columns = dfk .columns .values
133146 for x in actual_columns :
134- assert x in expected_columns ,\
147+ assert x in expected_columns , \
135148 "'{}' not an expected column in Kalman Filter results]" .format (x )
136149 for x in expected_columns :
137- assert x in actual_columns ,\
150+ assert x in actual_columns , \
138151 "'{}' was expected as a column, but not in Kalman Filter results" .format (x )
139152 assert Ps .shape == (732 , 2 , 2 ), "Shape of array of covariance matrices (Ps) not as expected"
140153
0 commit comments