Description
Hi,
I believe that I have found a bug or at least a misalignment between a formula that was written in a publication and the result of a pvlib method.
I think the previous modification works perfectly for a single day but doesn't take into account a vector with several days.
The original publication dissociates moments with values before (Kt'i-1) and after (Kt'i+1) the current value (Kt'i) equ 2 and values with only one of the 2 (e.g., beginning or end of day) eqn 3.
To Reproduce
time = pd.DatetimeIndex(['2014-01-01T05-0000','2014-01-01T06-0000','2014-01-01T07-0000','2014-01-01T08-0000','2014-01-01T09-0000','2014-01-01T10-0000','2014-01-01T11-0000','2014-01-01T12-0000','2014-01-01T13-0000','2014-01-01T14-0000','2014-01-01T15-0000','2014-01-01T16-0000','2014-01-01T17-0000','2014-01-01T18-0000','2014-01-01T19-0000','2014-01-01T20-0000'])
kt_prime = pd.Series([np.nan,np.nan,np.nan, 0.29458475, 0.21863506, 0.37650014, 0.41238529,0.23375275, 0.23363453, 0.26348652, 0.25412631, 0.43794681,np.nan,np.nan,np.nan])
_delta_kt_prime_dirint(kt_prime,True,time)
See error
I think in line 8 we have the expected result from the publication, line 7 is the result of the Python code: the error concerns the division by 2 of the 2 values in red (eqn 3).
Proposition of modification :
kt_next = np.roll(kt_prime,-1) delta_kt_next = abs(kt_prime - kt_next)* np.logical_and(np.logical_not(np.isnan(kt_prime)), np.logical_not(np.isnan(kt_next))) delta_kt_previous = np.roll(delta_kt_next,1) delta_kt_prime = (delta_kt_next.add(delta_kt_previous, fill_value=0)*np.logical_xor(np.logical_not(np.isnan(delta_kt_next)), np.logical_not(np.isnan(delta_kt_previous)))).add(0.5*(delta_kt_next+delta_kt_previous)*np.logical_and(np.logical_not(np.isnan(delta_kt_next)), np.logical_not(np.isnan(delta_kt_previous))),fill_value=0)
Versions:
pvlib.__version__
: '0.10.1'- python: 3.10.11