-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adapts irradiance.isotropic to return_components framework. #2527
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,7 +587,7 @@ | |
return diffuse_irrad | ||
|
||
|
||
def isotropic(surface_tilt, dhi): | ||
def isotropic(surface_tilt, dhi, return_components=False): | ||
r''' | ||
Determine diffuse irradiance from the sky on a tilted surface using | ||
the isotropic sky model. | ||
|
@@ -613,10 +613,29 @@ | |
dhi : numeric | ||
Diffuse horizontal irradiance. [Wm⁻²] DHI must be >=0. | ||
|
||
return_components : bool, default False | ||
Flag used to decide whether to return the calculated diffuse components | ||
or not. If `False`, ``sky_diffuse`` is returned. If `True`, | ||
``diffuse_components`` is returned. | ||
|
||
Returns | ||
------- | ||
diffuse : numeric | ||
The sky diffuse component of the solar radiation. | ||
poa_sky_diffuse : numeric | ||
The sky diffuse component of the solar radiation on a tilted | ||
surface. | ||
|
||
diffuse_components : dict (array input) or DataFrame (Series input) | ||
Keys/columns are: | ||
* sky_diffuse (the sum of the components below) | ||
* isotropic | ||
* circumsolar | ||
* horizon | ||
* poa_sky_diffuse (the sum of the components below) | ||
* poa_isotropic | ||
* poa_circumsolar | ||
* poa_horizon | ||
The first four elements will be deprecated in v0.14.0 and are kept | ||
to avoit breaking changes. | ||
|
||
References | ||
---------- | ||
|
@@ -630,9 +649,31 @@ | |
Energy vol. 201. pp. 8-12 | ||
:doi:`10.1016/j.solener.2020.02.067` | ||
''' | ||
sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5 | ||
poa_sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5 | ||
|
||
return sky_diffuse | ||
if return_components: | ||
diffuse_components = dict() | ||
|
||
# original formatting (to be deprecated in v0.14.0) | ||
diffuse_components['sky_diffuse'] = poa_sky_diffuse # total | ||
diffuse_components['isotropic'] = poa_sky_diffuse | ||
diffuse_components['circumsolar'] = 0 | ||
diffuse_components['horizon'] = 0 | ||
|
||
# new formatting | ||
diffuse_components['poa_sky_diffuse'] = poa_sky_diffuse | ||
diffuse_components['poa_isotropic'] = poa_sky_diffuse | ||
diffuse_components['poa_circumsolar'] = 0 | ||
diffuse_components['poa_horizon'] = 0 | ||
|
||
if isinstance(poa_sky_diffuse, pd.Series): | ||
# follows `perez` worfklow | ||
# shouldn't it include an argument `index=dhi.index`? | ||
diffuse_components = pd.DataFrame(diffuse_components) | ||
Comment on lines
+669
to
+672
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any comments about my question here? This code is used in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, should preserve the index from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would adding this index bit to the diffuse-component-including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's a breaking change. pvlib strives that a function returns the same data type as the inputs. That's one reason we test functions with different input types. If those functions are returning e.g. Array for Series input, I'd regard that as a bug that needs fixing. In |
||
|
||
return diffuse_components | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to return both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. This "one or the other" is what is implemented in For clarity, do you mean returning two dictionaries, which makes the number of outputs depend on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking a tuple with two dicts, when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cwhanse I just noticed that in my latest commit I included in the If instead we have two dictionaries as originally proposed, the one having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, I misspoke. Return a tuple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edited: returning a tuple requires the user to change from
to
I was (wrongly) thinking that only the first element of the tuple would be assigned to So now I'm not so sure that returning a tuple is a good idea. Still, it seems better than requiring the user to change to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying and thinking things through. Going back to the start:
I just remembered that in my latest commit the While what you propose is v0.13.1-friendly for the models not yet returning What do you think? If agreed, can you can raise a new issue like @kandersolar did in #2529? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All the irradiance component sets I looked at include both components and sums of components. I think the cleanest way would be (would have been) to include only the lowest level and leave the summation up to the user. |
||
return poa_sky_diffuse | ||
|
||
|
||
def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, | ||
|
@@ -782,8 +823,9 @@ | |
or supply ``projection_ratio``. | ||
|
||
return_components : bool, default `False` | ||
If `False`, ``sky_diffuse`` is returned. | ||
If `True`, ``diffuse_components`` is returned. | ||
Flag used to decide whether to return the calculated diffuse components | ||
or not. If `False`, ``sky_diffuse`` is returned. If `True`, | ||
``diffuse_components`` is returned. | ||
|
||
Returns | ||
-------- | ||
|
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.
Assuming this is in reference to the names in the
Returns
section