Skip to content

Bug within scaling.py wavelet calculation methodology #1206

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

Closed
jranalli opened this issue Apr 1, 2021 · 5 comments · Fixed by #1213
Closed

Bug within scaling.py wavelet calculation methodology #1206

jranalli opened this issue Apr 1, 2021 · 5 comments · Fixed by #1213
Labels

Comments

@jranalli
Copy link
Contributor

jranalli commented Apr 1, 2021

Describe the bug
Mathematical error within the wavelet computation for the scaling.py WVM implementation. Error arises from the methodology, as opposed to just a software bug.

To Reproduce
Steps to reproduce the behavior:

import numpy as np
from pvlib import scaling
cs = np.random.rand(2**14)
w, ts = scaling._compute_wavelet(cs,1)
print(np.all( (sum(w)-cs) < 1e-8 ))  # Returns False, expect True

Expected behavior
For a discrete wavelet transform (DWT) the sum of all wavelet modes should equate to the original data.

Versions:

  • pvlib.__version__: 0.7.2
  • pandas.__version__: 1.2.3
  • python: 3.8.8

Additional context
This bug is also present in the PV_LIB Matlab version that was used as the basis for this code (I did reach out to them using the PVLIB MATLAB email form, but don't know who actually wrote that code). Essentially, the existing code throws away the highest level of Detail Coefficient in the transform and keeps an extra level of Approximation coefficient. The impact on the calculation is small, but leads to an incorrect DWT and reconstruction. I have a fix that makes the code pass the theoretical test about the DWT proposed under 'To Reproduce' but there may be some question as to whether this should be corrected or left alone to match the MATLAB code it was based on.

@cwhanse
Copy link
Member

cwhanse commented Apr 1, 2021

@jranalli thanks for finding and reporting this. Can I ask how you contacted PVLIB MATLAB? Because I maintain that repository and I didn't see the email, so we need to fix something on our end with communications.

@jranalli
Copy link
Contributor Author

jranalli commented Apr 1, 2021

@cwhanse Now that I look again, I think I used the wrong form. It was just a general Questions and Comments link for the PV Performance Modeling Collaborative at the bottom of the page. I didn't see any contact point for the PV_LIB MATLAB library and I also didn't know about the github repo for it, but now I do!

I do have a fix for the MATLAB code as well, but I don't see that part of the library on github. If you'd like me to open an issue on that repository as well, I'd be happy to do so, but if there's some other pathway or contact point since that's kind of listed as a separate package of the code, please let me know.

Either way, do you think it's appropriate to fix this, or does there need to be a conversation with the original author of that MATLAB code? If everything is fine to go ahead with it here, I can just put together my fix as a pull request for review.

@cwhanse
Copy link
Member

cwhanse commented Apr 1, 2021

And did my own looking: pvl_WVM is in it's own Matlab archive, separate from PVLIB for Matlab. The WVM code is only available as a download from pvpmc.sandia.gov, whereas PVLIB for Matlab is on github.

I've sent the bug report to Matt Lave, the originator of the WVM algorithm and code. We'll likely welcome the bug fix but I'd like to hear Matt's view first.

@jranalli
Copy link
Contributor Author

jranalli commented Apr 1, 2021

OK sounds good. If he or you want to connect for more detail on the issue, you can get contact info for me at my Faculty Page.

@jranalli jranalli mentioned this issue Apr 9, 2021
8 tasks
@cwhanse
Copy link
Member

cwhanse commented Apr 9, 2021

for the record: bug is confirmed via separate communication with the WVM algorithm author.

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