@@ -848,7 +848,7 @@ def _clear_sample_index(clear_windows, samples_per_window, align, H):
848
848
return clear_samples
849
849
850
850
851
- def detect_clearsky (measured , clearsky , times = None , window_length = 10 ,
851
+ def detect_clearsky (measured , clearsky , window_length = 10 ,
852
852
mean_diff = 75 , max_diff = 75 ,
853
853
lower_line_length = - 5 , upper_line_length = 10 ,
854
854
var_diff = 0.005 , slope_dev = 8 , max_iterations = 20 ,
@@ -873,13 +873,10 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
873
873
874
874
Parameters
875
875
----------
876
- measured : array or Series
876
+ measured : Series
877
877
Time series of measured GHI. [W/m2]
878
- clearsky : array or Series
878
+ clearsky : Series
879
879
Time series of the expected clearsky GHI. [W/m2]
880
- times : DatetimeIndex or None, default None.
881
- Times of measured and clearsky values. If None the index of measured
882
- will be used.
883
880
window_length : int, default 10
884
881
Length of sliding time window in minutes. Must be greater than 2
885
882
periods.
@@ -910,9 +907,9 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
910
907
911
908
Returns
912
909
-------
913
- clear_samples : array or Series
914
- Boolean array or Series of whether or not the given time is
915
- clear. Return type is the same as the input type.
910
+ clear_samples : Series
911
+ Series of boolean indicating whether or not the given time is
912
+ clear.
916
913
917
914
components : OrderedDict, optional
918
915
Dict of arrays of whether or not the given time window is clear
@@ -925,8 +922,6 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
925
922
926
923
Raises
927
924
------
928
- ValueError
929
- If measured is not a Series and times is not provided
930
925
NotImplementedError
931
926
If timestamps are not equally spaced
932
927
@@ -954,45 +949,25 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
954
949
* uses centered windows (Matlab function uses left-aligned windows)
955
950
"""
956
951
957
- if times is None :
958
- try :
959
- times = measured .index
960
- except AttributeError :
961
- raise ValueError ("times is required when measured is not a Series" )
962
-
963
- # be polite about returning the same type as was input
964
- ispandas = isinstance (measured , pd .Series )
965
-
966
- # for internal use, need a Series
967
- if not ispandas :
968
- meas = pd .Series (measured , index = times )
969
- else :
970
- meas = measured
971
-
972
- if not isinstance (clearsky , pd .Series ):
973
- clear = pd .Series (clearsky , index = times )
974
- else :
975
- clear = clearsky
976
-
977
- sample_interval , samples_per_window = _get_sample_intervals (times ,
952
+ sample_interval , samples_per_window = _get_sample_intervals (measured .index ,
978
953
window_length )
979
954
980
955
# generate matrix of integers for creating windows with indexing
981
956
H = hankel (np .arange (samples_per_window ),
982
- np .arange (samples_per_window - 1 , len (times )))
957
+ np .arange (samples_per_window - 1 , len (measured . index )))
983
958
984
959
# calculate measurement statistics
985
960
meas_mean , meas_max , meas_line_length , meas_slope_nstd , meas_slope \
986
- = _calc_stats (meas , samples_per_window , sample_interval , 'center' )
961
+ = _calc_stats (measured , samples_per_window , sample_interval , 'center' )
987
962
988
963
# calculate clear sky statistics
989
964
clear_mean , clear_max , _ , _ , clear_slope \
990
- = _calc_stats (clear , samples_per_window , sample_interval , 'center' )
965
+ = _calc_stats (clearsky , samples_per_window , sample_interval , 'center' )
991
966
992
967
alpha = 1
993
968
for iteration in range (max_iterations ):
994
969
_ , _ , clear_line_length , _ , _ = _calc_stats (
995
- alpha * clear , samples_per_window , sample_interval , 'center' )
970
+ alpha * clearsky , samples_per_window , sample_interval , 'center' )
996
971
997
972
line_diff = meas_line_length - clear_line_length
998
973
@@ -1002,24 +977,26 @@ def detect_clearsky(measured, clearsky, times=None, window_length=10,
1002
977
c3 = (line_diff > lower_line_length ) & (line_diff < upper_line_length )
1003
978
c4 = meas_slope_nstd < var_diff
1004
979
# need to reduce window by 1 since slope is differenced already
1005
- c5 = _calc_c5 (meas , alpha * clear , samples_per_window ,
980
+ c5 = _calc_c5 (measured , alpha * clearsky , samples_per_window ,
1006
981
'center' , slope_dev )
1007
982
c6 = (clear_mean != 0 ) & ~ np .isnan (clear_mean )
1008
983
clear_windows = c1 & c2 & c3 & c4 & c5 & c6
1009
984
1010
985
# create array to return
1011
- clear_samples = np .full_like (meas , False , dtype = 'bool' )
986
+ clear_samples = np .full_like (measured , False , dtype = 'bool' )
1012
987
# find the samples contained in any window classified as clear
1013
988
idx = _clear_sample_index (clear_windows , samples_per_window , 'center' ,
1014
989
H )
1015
990
clear_samples [idx ] = True
1016
991
1017
992
# find a new alpha
1018
993
previous_alpha = alpha
1019
- clear_meas = meas [clear_samples ]
1020
- clear_clear = clear [clear_samples ]
994
+ clear_meas = measured [clear_samples ]
995
+ clear_clear = clearsky [clear_samples ]
996
+
1021
997
def rmse (alpha ):
1022
998
return np .sqrt (np .mean ((clear_meas - alpha * clear_clear )** 2 ))
999
+
1023
1000
alpha = minimize_scalar (rmse ).x
1024
1001
if round (alpha * 10000 ) == round (previous_alpha * 10000 ):
1025
1002
break
@@ -1028,10 +1005,6 @@ def rmse(alpha):
1028
1005
warnings .warn ('failed to converge after %s iterations'
1029
1006
% max_iterations , RuntimeWarning )
1030
1007
1031
- # be polite about returning the same type as was input
1032
- if ispandas :
1033
- clear_samples = pd .Series (clear_samples , index = times )
1034
-
1035
1008
if return_components :
1036
1009
components = OrderedDict ()
1037
1010
components ['mean_diff' ] = c1
0 commit comments