-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[ENH] extend iam.physical with optional n_ar parameter for AR coating #1616
Conversation
I love this so much! I’ll try to take a look asap unless someone else beats me to it. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like this code, but I think it would be better if all the arguments could be vectors like in the original version.
it looks like there's a stickler alert, some long lines, can you clean those up? |
@mikofski Beat you to it by 15 minutes! :) |
Unless I'm mistaken, So, you mean that the code should also support |
Yes, that's what I was thinking, if it's not too complicated. |
If making them vectors is a bridge too far, I’d prefer bird in the hand instead of two in the bush. what is the use case for vector forms of let’s get this pull request closed and follow up with a refinement. don’t let perfect be the enemy of good @kdebrab can you address the pep-8 issues? I’d like to merge this ASAP if there are no other concerns. Thanks! |
We do need some reviews/reviewers... |
Personally, I'm not convinced whether we should really support Nevertheless, I pushed an update which addresses both requests. |
Great, thanks! Interesting to learn about black too. A use case for n/n_ar as vectors could be modeling an ar coating that degrades. In research mode I also like to send a vectors to do parameter sweeps on models. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick first partial review from my side.
@@ -91,21 +91,22 @@ def ashrae(aoi, b=0.05): | |||
return iam | |||
|
|||
|
|||
def physical(aoi, n=1.526, K=4., L=0.002): | |||
def physical(aoi, n=1.526, K=4.0, L=0.002, *, n_ar=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning behind including an asterisk (allowing a variable number of arguments) in this specific function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ‘single star’ syntax indicates the end of positional parameters and enforces the user to use a keyword for all following parameters, see https://peps.python.org/pep-3102.
In other words physical(aoi, 1.526, 4.0, 0.0032, 1.29)
is not allowed and will fail with a TypeError
. One needs to explicitly add the n_ar
keyword, like physical(aoi, 1.526, 4.0, 0.0032, n_ar=1.29)
.
I think of using *
to be good practice for functions with many parameters, so I typically do it when adding new parameters, but it may be overkill. On the other hand, removing the asterisk later is easy and doesn't break anything, but adding it later would be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, interesting, I certainly didn't know that. I'm all for keeping it. Thanks for the explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be a first for pvlib, but I'm okay with keeping it. If anyone complains we can always revert it as @kdebrab points out.
@AdamRJensen Did you run black on this file? |
Oh, my mistake. I accidentally applied black in my latest commit. I reverted that commit now. |
Interestingly black did not make all that many changes. I intend to throw some of my personal code at it and fear it may crash! |
@kdebrab I could test this, but you probably have done so already: if you leave out the |
Indeed, the only purpose of the ' As requested, I double checked: after out-commenting the line [EDIT] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor comments but otherwise LGTM
@@ -17,6 +17,8 @@ Deprecations | |||
Enhancements | |||
~~~~~~~~~~~~ | |||
|
|||
* Added optional ``n_ar`` parameter to :py:func:`pvlib.iam.physical` to | |||
support an anti-reflective coating. (:issue:`1501`, :pull:`1616`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to add yourself to the Contributors list below :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well as the reviewers.
pvlib/iam.py
Outdated
@@ -121,6 +122,10 @@ def physical(aoi, n=1.526, K=4., L=0.002): | |||
indicates that 0.002 meters (2 mm) is reasonable for most | |||
glass-covered PV panels. | |||
|
|||
n_ar : numeric, default None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n_ar : numeric, default None | |
n_ar : numeric, optional |
See #1574
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with the default being normal glass, no ARC, but would it be possible in the docstring somewhere, either here or after returns in the notes, to suggest nAR = 1.290
to mimic PVsyst? Or to provide a reference of what would be typical values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the docstring.
@@ -91,21 +91,22 @@ def ashrae(aoi, b=0.05): | |||
return iam | |||
|
|||
|
|||
def physical(aoi, n=1.526, K=4., L=0.002): | |||
def physical(aoi, n=1.526, K=4.0, L=0.002, *, n_ar=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be a first for pvlib, but I'm okay with keeping it. If anyone complains we can always revert it as @kdebrab points out.
Thanks @kdebrab ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
pvlib/iam.py
Outdated
@@ -121,6 +122,10 @@ def physical(aoi, n=1.526, K=4., L=0.002): | |||
indicates that 0.002 meters (2 mm) is reasonable for most | |||
glass-covered PV panels. | |||
|
|||
n_ar : numeric, default None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with the default being normal glass, no ARC, but would it be possible in the docstring somewhere, either here or after returns in the notes, to suggest nAR = 1.290
to mimic PVsyst? Or to provide a reference of what would be typical values?
@kdebrab either in this PR or in a follow up I also think there should be a test for vector |
There is indeed no test against vectors of |
Thanks @kdebrab and all reviewers! |
[ ] Updates entries indocs/sphinx/source/reference
for API changes.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`
).remote-data
) and Milestone are assigned to the Pull Request and linked Issue.