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

Implemented closed-form solution in detect_clearsky #2217

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

agodbehere
Copy link
Contributor

@agodbehere agodbehere commented Sep 19, 2024

@cwhanse cwhanse modified the milestone: v0.11.1 Sep 19, 2024
Copy link
Contributor

@echedey-ls echedey-ls left a comment

Choose a reason for hiding this comment

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

Nice PR @agodbehere 💯 !!

Leaving early review comments:

  • You can safely address flake8 warnings in test_clearsky.py
  • Docs will need to be updated to reflect what new algorithm is being used, which I identify are:
    • The docstring of the modified function (pvilb.clearsky.detect_clearsky)
    • The user guide section at clearsky.rst
    • As you update these sections, you will be able to see how they will look when published at the following link (you can access it at the bottom of this PR in "Checks", through the "ReadTheDocs" action): https://pvlib-python--2217.org.readthedocs.build/en/2217/
  • I haven't checked the code much more deeply, but there may be parts relating to the old algorithm at other places too

Feel free to ask about whatever you need help with, we all know it's not that easy to contribute to open-source 🚀

@@ -30,6 +30,10 @@ Enhancements
* Added function for calculating wind speed at different heights,
:py:func:`pvlib.atmosphere.windspeed_powerlaw`.
(:issue:`2118`, :pull:`2124`)
* Implemented closed-form solution for alpha in detect_clearsky, obviating
the call to scipy.optimize that was prone to runtime errors and minimizing
computation, :py:func:`pvlib.clearsky.detect_clearsky`. Resolves :issue:`2712`.
Copy link
Contributor

@echedey-ls echedey-ls Sep 19, 2024

Choose a reason for hiding this comment

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

Suggested change
computation, :py:func:`pvlib.clearsky.detect_clearsky`. Resolves :issue:`2712`.
computation, :py:func:`pvlib.clearsky.detect_clearsky`. (:discuss:`2171`, :issue:`2216`, :pull:`2217`)

Copy link
Member

@cwhanse cwhanse Sep 19, 2024

Choose a reason for hiding this comment

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

Should be :issue:2171, :issue:2216

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated, thanks ❣️


# Compute arg min of MSE between model and observations
C = (clear_clear**2).sum()
if not (pd.isna(C) or C == 0): # safety check
Copy link
Contributor

Choose a reason for hiding this comment

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

What would physically mean that this value is zero or NaN? Maybe we can skip this safety check, I wonder what could happen if this code isn't executed

Copy link
Member

Choose a reason for hiding this comment

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

Without the check the next line divides by C. The exit criteria need alpha to be a float. I think the check and if...break are fine.

pvlib/clearsky.py Show resolved Hide resolved
Copy link
Contributor

@RDaxini RDaxini left a comment

Choose a reason for hiding this comment

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

Nice job 👍🏾
Minor suggestion for the whatsnew file (someone will correct me if I'm mistaken)

Comment on lines 33 to 35
* Implemented closed-form solution for alpha in detect_clearsky, obviating
the call to scipy.optimize that was prone to runtime errors and minimizing
computation, :py:func:`pvlib.clearsky.detect_clearsky`. Resolves :issue:`2712`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Link the function in the first line and then no need to repeat it here at the end as (I think?) we only do that if it is a new function being added

Suggested change
* Implemented closed-form solution for alpha in detect_clearsky, obviating
the call to scipy.optimize that was prone to runtime errors and minimizing
computation, :py:func:`pvlib.clearsky.detect_clearsky`. Resolves :issue:`2712`.
* Implemented closed-form solution for alpha in
:py:func:`pvlib.clearsky.detect_clearsky`, obviating
the call to scipy.optimize that was prone to runtime errors and minimizing
computation. (:issue:`2171`, :issue:`2216`, :pull:`2217`).

Copy link
Member

@cwhanse cwhanse left a comment

Choose a reason for hiding this comment

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

I approve providing the comments on the whatsnew file are resolved.

@kandersolar kandersolar mentioned this pull request Sep 23, 2024
11 tasks
@kandersolar kandersolar changed the title Implemented closed-form solution Implemented closed-form solution in detect_clearsky Sep 23, 2024
@kandersolar kandersolar merged commit d6baf97 into pvlib:main Sep 23, 2024
30 checks passed
@kandersolar
Copy link
Member

Thanks for this nice improvement @agodbehere!

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.

Simple closed-form solution for alpha in detect_clearsky - clarified
5 participants