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

Implement Caballero et al. spectral factor model #1296

Merged
merged 114 commits into from Jun 23, 2023

Conversation

Jacc0027
Copy link
Contributor

@Jacc0027 Jacc0027 commented Aug 26, 2021

  • Closes Add a model for spectral corrections #1278
  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries to docs/sphinx/source/api.rst for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels and Milestone are assigned to the Pull Request and linked Issue.
https://github.com//issues/1278

AM_AOD_PW_spectral_correction.zip

@kandersolar
Copy link
Member

Hi @Jacc0027 -- sorry for the delay if you were waiting for feedback on this PR! It looks great so far. To make a more detailed review easier, could you address the code style issues noted by "Stickler CI" on this page? https://github.com/pvlib/pvlib-python/pull/1296/files

This will also need some tests (see the contributing docs) to check that the code works on all the various python versions and package versions we support. Please reach out if you need input from us to move this PR forward :) And thanks again for the contribution!

@Jacc0027
Copy link
Contributor Author

Hi @Jacc0027 -- sorry for the delay if you were waiting for feedback on this PR! It looks great so far. To make a more detailed review easier, could you address the code style issues noted by "Stickler CI" on this page? https://github.com/pvlib/pvlib-python/pull/1296/files

This will also need some tests (see the contributing docs) to check that the code works on all the various python versions and package versions we support. Please reach out if you need input from us to move this PR forward :) And thanks again for the contribution!

Hi @kanderso-nrel , thank you for your help.

After a bit of time and testing, I finally managed to adapt the code and pass the Stickler CI test.

It is a pleasure for me to contribute to this wonderful project.

I remain at your disposal for any further issues.

@kandersolar
Copy link
Member

Thanks @Jacc0027 for the effort here! I think I see how to get the tests working; would you mind if I pushed some commits to this PR for that? Then after a bit of documentation I think this PR will be ready.

@Jacc0027
Copy link
Contributor Author

Thanks @Jacc0027 for the effort here! I think I see how to get the tests working; would you mind if I pushed some commits to this PR for that? Then after a bit of documentation I think this PR will be ready.

Hi @kandersolar , no problem. Go ahead with the solution. Thanks for the support!

@kandersolar
Copy link
Member

Looks like things are working! I think these are the last main things, @Jacc0027 can you take a look:

  • Fill in the two "TODO" parameter descriptions
  • Add an entry in /docs/sphinx/source/reference/airmass_atmospheric.rst for this new function
  • Add a new item in /docs/sphinx/source/whatsnew/v0.9.6.rst for this enhancement, and yourself as a contributor at the bottom

@Jacc0027
Copy link
Contributor Author

Looks like things are working! I think these are the last main things, @Jacc0027 can you take a look:

  • Fill in the two "TODO" parameter descriptions
  • Add an entry in /docs/sphinx/source/reference/airmass_atmospheric.rst for this new function
  • Add a new item in /docs/sphinx/source/whatsnew/v0.9.6.rst for this enhancement, and yourself as a contributor at the bottom

Thanks @kandersolar you did it!. I have done the 3 things you've requested me. Please, let me know if you need something else.

@kandersolar
Copy link
Member

Hmm, for some reason this PR is not showing any changes to the reference and whatsnew pages: https://github.com/pvlib/pvlib-python/pull/1296/files

Maybe you only changed them locally but did not include them in a commit?

@Jacc0027
Copy link
Contributor Author

Hmm, for some reason this PR is not showing any changes to the reference and whatsnew pages: https://github.com/pvlib/pvlib-python/pull/1296/files

Maybe you only changed them locally but did not include them in a commit?

I requested to update both files after modifying them via Github online. After requesting the Commit of the changes, I got an option to create a PR for them. Should I create these new PRs?

@kandersolar
Copy link
Member

It would be better to include them in this PR so that all the changes are in one place. If you are editing them with Github online, then I think you can add the changes to this PR by editing the files on the specific git branch associated with this PR (the Spectral-corrections branch in your fork of pvlib). For example this is the link for the "what's new" file on the PR branch: https://github.com/Jacc0027/pvlib-python/blob/Spectral-corrections/docs/sphinx/source/whatsnew/v0.9.6.rst

If you edit that file and go to commit the change, it should give you the option "Commit directly to the Spectral-corrections branch", and then I think the commit will show up in this PR.

Copy link
Member

@adriesse adriesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two very old comments that show up as pending. Does that mean nobody else saw them? I'm going to click on submit now but will take another look when I get back to the office next week.

as a function of AM, AOD and PW was performed according to [2] and [3].
As such, the polynomial adjustment coefficients included in [3]
were obtained.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is very good to have a couple of paragraphs explaining the basics here, but unfortunately I find them hard to understand. If you recorded AM, AOD, PW and spectra, then where does smarts come in? I guess I should read the paper, but this text should also be consistent and comprehensible on its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @adriesse, the reason for using synthetic spectra, generated through SMARTS2, was to ascertain the ideal polynomial type of the experimental equations related to the AM, AOD and PW parameters.

Spain for one year synchronously with both, broadband and
spectroradiometric measurements of 30º tilted global irradiance
south-facing logged in 5-min intervals. AM was estimated through
elevation data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this estimation refer to solar elevation? Airmass calculations are pretty standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @adriesse, yes it does. The solar elevation was measured by means of a solar spectral irradiance meter (SolarSIM-D2) from Spectrafy Inc. Then the AM was computed by using the sun’s zenith angle (z). Reference: F. Kasten and A. T. Young, “Revised optical air mass tables and approxi-mation formula,” Appl. Opt., vol. 28, pp. 4735–4738, Nov. 15, 1989.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that your responses might make it into the doc string at some point...

Added caballero spectral correction as a new function.
Added a new function: atmosphere.caballero_spectral_correction
@Jacc0027
Copy link
Contributor Author

It would be better to include them in this PR so that all the changes are in one place. If you are editing them with Github online, then I think you can add the changes to this PR by editing the files on the specific git branch associated with this PR (the Spectral-corrections branch in your fork of pvlib). For example this is the link for the "what's new" file on the PR branch: https://github.com/Jacc0027/pvlib-python/blob/Spectral-corrections/docs/sphinx/source/whatsnew/v0.9.6.rst

If you edit that file and go to commit the change, it should give you the option "Commit directly to the Spectral-corrections branch", and then I think the commit will show up in this PR.

Hi @kandersolar, done. Thank you for the guidelines!

pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
pvlib/atmosphere.py Outdated Show resolved Hide resolved
Jacc0027 and others added 5 commits May 24, 2023 20:41
Co-authored-by: Anton Driesse <anton.driesse@pvperformancelabs.com>
following the conventions set out in pvlib#1628
- reorder and rename parameters to match pvlib#1768
- remove reference parameters
- shorten/simplify docstring
- restructure calculation to be more readable
@kandersolar kandersolar changed the title Update atmosphere.py - Add a model for spectral corrections Implement Caballero et al. spectral factor model Jun 12, 2023
@kandersolar
Copy link
Member

Hi @Jacc0027, I just added a few changes. The main one is to move the new function to pvlib.spectrum, since we are consolidating the spectral modifier functions to that module (see #1628). I also made some changes to the function to better match typical pvlib style, and address @adriesse's comments above.

I think this PR is ready to merge, but I'll leave it open for a few days to allow a chance for anyone else to review again.

@Jacc0027
Copy link
Contributor Author

Hi @Jacc0027, I just added a few changes. The main one is to move the new function to pvlib.spectrum, since we are consolidating the spectral modifier functions to that module (see #1628). I also made some changes to the function to better match typical pvlib style, and address @adriesse's comments above.

I think this PR is ready to merge, but I'll leave it open for a few days to allow a chance for anyone else to review again.

Thank you @kandersolar .

Hi @Jacc0027, I just added a few changes. The main one is to move the new function to pvlib.spectrum, since we are consolidating the spectral modifier functions to that module (see #1628). I also made some changes to the function to better match typical pvlib style, and address @adriesse's comments above.

I think this PR is ready to merge, but I'll leave it open for a few days to allow a chance for anyone else to review again.

Hi @kandersolar, thank you so much for the effort! There have been two major solar energy events during the last week: Intersolar Europe 2023 and PVSC50. Perhaps during the week ahead there will be some additional comments. We'll see.

Comment on lines +548 to +566
f_AM = (
coeff[0]
+ coeff[1] * ama
+ coeff[2] * ama**2
+ coeff[3] * ama**3
+ coeff[4] * ama**4
)
# Eq 6, with Table 1
f_AOD = (aod500 - aod500_ref) * (
coeff[5]
+ coeff[10] * coeff[6] * ama
+ coeff[11] * coeff[6] * np.log(ama)
+ coeff[7] * ama**2
)
# Eq 7, with Table 1
f_PW = (precipitable_water - pw_ref) * (
coeff[8]
+ coeff[9] * np.log(ama)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a several options for making this more efficient: Horner's method, np.polyval, pre-calculating ama powers, expanding **3 and **4, adding coefficients before multiplying where applicable. Just thought I'd mention that since it came up in other places in the past. They would all reduce the much-appreciated code clarity to varying degrees, so I'll stop short of making a recommendation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt the same conflict between code clarity and efficiency. I settled in favor of clarity after seeing that this inefficient implementation is still plenty fast by my standards (computes ~10 million values in one second).

Still, it does offend the sensibilities to calculate x**3 on one line and x**4 on the next :(

@kandersolar kandersolar merged commit 948d820 into pvlib:main Jun 23, 2023
27 of 29 checks passed
@kandersolar
Copy link
Member

Thanks again @Jacc0027 for this contribution, and my apologies that it took nearly two years to get it merged. Better late than never, hopefully :)

@Jacc0027
Copy link
Contributor Author

Jacc0027 commented Jul 5, 2023

Thank you so much @kandersolar, @adriesse, @cwhanse, @mikofski for your support during this time! To a lesser or greater extent, the closing of this contribution has also been possible thanks to your assistance. I would really wish I could have made this contribution in other circumstances with more time available.
See you!

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

Successfully merging this pull request may close these issues.

Add a model for spectral corrections
5 participants