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

[ENH] extend iam.physical with optional n_ar parameter for AR coating #1616

Merged
merged 8 commits into from
Feb 4, 2023

Conversation

kdebrab
Copy link
Contributor

@kdebrab kdebrab commented Dec 16, 2022

  • Closes IAM that supports AR coating like Fresnel #1501
  • I am familiar with the contributing guidelines
  • Tests added
  • [ ] Updates entries in docs/sphinx/source/reference 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 (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

@mikofski
Copy link
Member

I love this so much! I’ll try to take a look asap unless someone else beats me to it. Thank you!

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.

Overall I like this code, but I think it would be better if all the arguments could be vectors like in the original version.

@mikofski
Copy link
Member

it looks like there's a stickler alert, some long lines, can you clean those up?

@adriesse
Copy link
Member

adriesse commented Jan 18, 2023

@mikofski Beat you to it by 15 minutes! :)

@kdebrab
Copy link
Contributor Author

kdebrab commented Feb 1, 2023

Overall I like this code, but I think it would be better if all the arguments could be vectors like in the original version.

Unless I'm mistaken, aoi, K and L could already be vectors, but the code will indeed fail when n or n_ar is a vector.

So, you mean that the code should also support n and n_ar as vectors?

@adriesse
Copy link
Member

adriesse commented Feb 1, 2023

So, you mean that the code should also support n and n_ar as vectors?

Yes, that's what I was thinking, if it's not too complicated.

@mikofski
Copy link
Member

mikofski commented Feb 1, 2023

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 n & n_ar and how often?

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!

@adriesse
Copy link
Member

adriesse commented Feb 1, 2023

I’d like to merge this ASAP

We do need some reviews/reviewers...

@kdebrab
Copy link
Contributor Author

kdebrab commented Feb 1, 2023

Personally, I'm not convinced whether we should really support n and n_ar as vectors. Also, I'm wondering whether we shouldn't move to the now ubiquitous black code style, which (amongst others) defaults to a line length of 88 instead of 79 characters.

Nevertheless, I pushed an update which addresses both requests. n and n_ar as vectors are now supported and the "E501 line too long" stickler alerts have been resolved.

@adriesse
Copy link
Member

adriesse commented Feb 2, 2023

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.

Copy link
Member

@AdamRJensen AdamRJensen left a 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.

pvlib/iam.py Outdated Show resolved Hide resolved
pvlib/iam.py Outdated Show resolved Hide resolved
pvlib/iam.py Outdated Show resolved Hide resolved
pvlib/iam.py Outdated Show resolved Hide resolved
pvlib/iam.py Outdated Show resolved Hide resolved
@@ -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):
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

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 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.

@adriesse
Copy link
Member

adriesse commented Feb 2, 2023

@AdamRJensen Did you run black on this file?

@kdebrab
Copy link
Contributor Author

kdebrab commented Feb 2, 2023

@AdamRJensen Did you run black on this file?

Oh, my mistake. I accidentally applied black in my latest commit. I reverted that commit now.

@adriesse
Copy link
Member

adriesse commented Feb 2, 2023

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!

@adriesse
Copy link
Member

adriesse commented Feb 2, 2023

@kdebrab I could test this, but you probably have done so already: if you leave out the if statements, do the calculations produce identical results with n_ar=1 and n_ar=n as inputs? The purpose of the if statements is just to save some processing time, right?

@kdebrab
Copy link
Contributor Author

kdebrab commented Feb 3, 2023

@kdebrab I could test this, but you probably have done so already: if you leave out the if statements, do the calculations produce identical results with n_ar=1 and n_ar=n as inputs? The purpose of the if statements is just to save some processing time, right?

Indeed, the only purpose of the 'if not np.allclose(n3, n2):' statement is to save processing time in case there is no AR coating. When n2==n3, sintheta and costheta don't change, the rho23 components are zero and as a result the tau components don't change.

As requested, I double checked: after out-commenting the line if not np.allclose(n3, n2): (and shifting the subsequent block to the left), the tests passed and thus the results (see test_physical and test_physical_noar) are indeed identical.

[EDIT]
I see that I may have misunderstood your question: you probably mean out-commenting the complete if block. In that case, the only test that fails is test_physical_ar (for obvious reasons), but all other tests pass, and thus for n_ar=1 and n_ar=n, results remain the same.

Copy link
Member

@kandersolar kandersolar left a 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`)
Copy link
Member

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 :)

Copy link
Member

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

Choose a reason for hiding this comment

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

Suggested change
n_ar : numeric, default None
n_ar : numeric, optional

See #1574

Copy link
Member

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?

Copy link
Contributor Author

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):
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 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.

@adriesse
Copy link
Member

adriesse commented Feb 3, 2023

As requested, I double checked:

Thanks @kdebrab !

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.

Nice work!

mikofski
mikofski approved these changes Feb 3, 2023
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
Copy link
Member

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?

pvlib/iam.py Show resolved Hide resolved
pvlib/tests/test_iam.py Show resolved Hide resolved
@mikofski
Copy link
Member

mikofski commented Feb 4, 2023

@kdebrab either in this PR or in a follow up I also think there should be a test for vector n and n_ar and an example in the Gallery to show how to use this function that way, especially if the shape of the inputs is important, EG: should aoi be in the 1st dimension and n in the 2nd dimension? Thanks! PS sorry if this is redundant with my previous comment. I can't find it now.

@kdebrab
Copy link
Contributor Author

kdebrab commented Feb 4, 2023

@kdebrab either in this PR or in a follow up I also think there should be a test for vector n and n_ar and an example in the Gallery to show how to use this function that way, especially if the shape of the inputs is important, EG: should aoi be in the 1st dimension and n in the 2nd dimension? Thanks! PS sorry if this is redundant with my previous comment. I can't find it now.

There is indeed no test against vectors of n, n_ar, L or K. I think when @adriesse uses vectors, these have the same dimension as aoi. Maybe, @adriesse can add a test for that in a follow up PR?

@mikofski mikofski merged commit a19b528 into pvlib:main Feb 4, 2023
@mikofski
Copy link
Member

mikofski commented Feb 4, 2023

Thanks @kdebrab and all reviewers!

@kdebrab kdebrab deleted the iam_for_AR_coating branch February 25, 2023 21:46
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.

IAM that supports AR coating like Fresnel
5 participants