Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation of delta kt' #1847

Open
FrancoisFEM opened this issue Sep 6, 2023 · 1 comment
Open

Calculation of delta kt' #1847

FrancoisFEM opened this issue Sep 6, 2023 · 1 comment

Comments

@FrancoisFEM
Copy link

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.
Capture d'écran 2023-09-06 153847

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).
Capture d'écran 2023-09-06 155022

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
@kandersolar
Copy link
Member

I think I agree that this is an error in pvlib's implementation.

For fixing the error, instead of verbose logic to keep track of missing values, I think we can use pandas to determine whether there are zero, one, or two valid values and perform the appropriate calculation:

delta_kt_prime = pd.DataFrame({
    'next': (kt_prime - kt_next).abs(),
    'prev': (kt_prime - kt_previous).abs(),
}).mean(axis=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants