@@ -680,36 +680,37 @@ def detect_clearsky(measured, clearsky, times, window_length,
680
680
raise NotImplementedError ('algorithm does not yet support unequal '
681
681
'times. consider resampling your data.' )
682
682
683
- samples_per_window = int (window_length / sample_interval )
683
+ intervals_per_window = int (window_length / sample_interval )
684
684
685
685
# generate matrix of integers for creating windows with indexing
686
686
from scipy .linalg import hankel
687
- H = hankel (np .arange (samples_per_window ), # noqa: N806
688
- np .arange (samples_per_window - 1 , len (times )))
687
+ H = hankel (np .arange (intervals_per_window ), # noqa: N806
688
+ np .arange (intervals_per_window - 1 , len (times )))
689
689
690
690
# calculate measurement statistics
691
691
meas_mean = np .mean (measured [H ], axis = 0 )
692
692
meas_max = np .max (measured [H ], axis = 0 )
693
- meas_slope = np .diff (measured [H ], n = 1 , axis = 0 )
693
+ meas_diff = np .diff (measured [H ], n = 1 , axis = 0 )
694
+ meas_slope = np .diff (measured [H ], n = 1 , axis = 0 ) / sample_interval
694
695
# matlab std function normalizes by N-1, so set ddof=1 here
695
696
meas_slope_nstd = np .std (meas_slope , axis = 0 , ddof = 1 ) / meas_mean
696
- meas_slope_max = np .max (np .abs (meas_slope ), axis = 0 )
697
697
meas_line_length = np .sum (np .sqrt (
698
- meas_slope * meas_slope + sample_interval * sample_interval ), axis = 0 )
698
+ meas_diff * meas_diff +
699
+ sample_interval * sample_interval ), axis = 0 )
699
700
700
701
# calculate clear sky statistics
701
702
clear_mean = np .mean (clearsky [H ], axis = 0 )
702
703
clear_max = np .max (clearsky [H ], axis = 0 )
703
- clear_slope = np .diff (clearsky [H ], n = 1 , axis = 0 )
704
- clear_slope_max = np .max ( np . abs ( clear_slope ), axis = 0 )
704
+ clear_diff = np .diff (clearsky [H ], n = 1 , axis = 0 )
705
+ clear_slope = np .diff ( clearsky [ H ], n = 1 , axis = 0 ) / sample_interval
705
706
706
707
from scipy .optimize import minimize_scalar
707
708
708
709
alpha = 1
709
710
for iteration in range (max_iterations ):
710
711
clear_line_length = np .sum (np .sqrt (
711
- alpha * alpha * clear_slope * clear_slope +
712
- sample_interval * sample_interval ), axis = 0 )
712
+ alpha * alpha * clear_diff * clear_diff +
713
+ sample_interval * sample_interval ), axis = 0 )
713
714
714
715
line_diff = meas_line_length - clear_line_length
715
716
@@ -718,7 +719,8 @@ def detect_clearsky(measured, clearsky, times, window_length,
718
719
c2 = np .abs (meas_max - alpha * clear_max ) < max_diff
719
720
c3 = (line_diff > lower_line_length ) & (line_diff < upper_line_length )
720
721
c4 = meas_slope_nstd < var_diff
721
- c5 = (meas_slope_max - alpha * clear_slope_max ) < slope_dev
722
+ c5 = np .max (np .abs (meas_slope -
723
+ alpha * clear_slope ), axis = 0 ) < slope_dev
722
724
c6 = (clear_mean != 0 ) & ~ np .isnan (clear_mean )
723
725
clear_windows = c1 & c2 & c3 & c4 & c5 & c6
724
726
@@ -749,13 +751,21 @@ def rmse(alpha):
749
751
750
752
if return_components :
751
753
components = OrderedDict ()
752
- components ['mean_diff ' ] = c1
753
- components ['max_diff ' ] = c2
754
- components ['line_length ' ] = c3
755
- components ['slope_nstd ' ] = c4
756
- components ['slope_max ' ] = c5
757
- components ['mean_nan ' ] = c6
754
+ components ['mean_diff_flag ' ] = c1
755
+ components ['max_diff_flag ' ] = c2
756
+ components ['line_length_flag ' ] = c3
757
+ components ['slope_nstd_flag ' ] = c4
758
+ components ['slope_max_flag ' ] = c5
759
+ components ['mean_nan_flag ' ] = c6
758
760
components ['windows' ] = clear_windows
761
+
762
+ components ['mean_diff' ] = np .abs (meas_mean - alpha * clear_mean )
763
+ components ['max_diff' ] = np .abs (meas_max - alpha * clear_max )
764
+ components ['line_length' ] = meas_line_length - clear_line_length
765
+ components ['slope_nstd' ] = meas_slope_nstd
766
+ components ['slope_max' ] = (np .max (
767
+ meas_slope - alpha * clear_slope , axis = 0 ))
768
+
759
769
return clear_samples , components , alpha
760
770
else :
761
771
return clear_samples
0 commit comments