You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dividing by cos(solar_zenith) in haydavies and reindl functions #432
A few issues with the pvlib package seem to be caused by dividing by cos(solar_zenith) since solar zenith can vary from 0-180 degrees. As the solar_zenith approaches 90 degrees, these results will approach infinity. The problem becomes very apparent when the value of solar_zenith is between 89 and 90 degrees which is rare unless working with minute interval (or smaller) because the denominator then becomes a large scaling factor. I have attached a quick sample code to illustrate the issue. cos(solar_zenith)_errors.txt
A few questions and comments to note:
This seems to have been addressed in a similar context in the DISC Model and Zenith Threshold issue but appear again in the haydavies algorithm implementation on line 729 of irradiance.py when calculating the projection_ratio and could potentially appear elsewhere in the package.
The MATLAB version of the haydavies algorithm, pvl_haydavies1980.m, uses the formula "RB = max(COSTT, 0) ./ max(cosd(SunZen), 0.01745))" where 0.01745 corresponds to a zenith angle of 89 degrees to avoid the issue.
This seems to have been addressed in a similar context in the DISC Model and Zenith Threshold
A related issue was discussed and a potential solution was proposed, but it was not merged.
could potentially appear elsewhere in the package.
I see that a similar issue could come up in reindl. I don't see any other problems in the irradiance.py module. I'm going to go ahead and change this issue to be specific to the transposition functions. Please post separate issues if you find them in the rest of the library.
I'll post a few haydavies and reindl calculations that use only slightly unphysical input data:
So the functions behave ok for some problematic inputs but not for others. I think it's in the scope of pvlib to be able to gracefully handle these inputs.
The MATLAB version of the haydavies algorithm, pvl_haydavies1980.m, uses the formula "RB = max(COSTT, 0) ./ max(cosd(SunZen), 0.01745))" where 0.01745 corresponds to a zenith angle of 89 degrees to avoid the issue.
We could do this here for consistency. It seems somewhat arbitrary but pragmatic to me. I looked at the git history and I saw that the original port did contain this code, but I removed it as one of many changes to clean up and simplify the library. My bad.
Sandia National Laboratories documentation seems to suggest that dividing by cos(solar_zenith) is not part of the Hay and Davies diffuse model.
The pvlib implementation roughly follows the Loutzenhiser 2007 description of the model. From a numerical standpoint, the PVPMC website's description would be a better implementation. There may be some legacy here that I'm not aware of, such as the MATLAB function could have at one point returned the total POA irradiance, rather than just the sky diffuse component.
Is there a documented reason for the differences between these formulas or is this a mistake in implementation?
See Loutzenhiser 2007. The implementation is correct, it's just not numerically the best way to do it.
Sandia National Laboratories documentation seems to suggest that dividing by cos(solar_zenith) is not part of the Hay and Davies diffuse model.
The pvlib implementation roughly follows the Loutzenhiser 2007 description of the model. From a numerical standpoint, the PVPMC website's description would be a better implementation. There may be some legacy here that I'm not aware of, such as the MATLAB function could have at one point returned the total POA irradiance, rather than just the sky diffuse component.
I think the Sandia National Laboratories documentation is wrong on this one. Just imagine 100% circumsolar diffuse: tilted diffuse could never be greater than horizontal diffuse with this formula, even with the array pointed at the sun.
I see that a similar issue could come up in reindl. I don't see any other problems in the irradiance.py module. I'm going to go ahead and change this issue to be specific to the transposition functions. Please post separate issues if you find them in the rest of the library.
Essentially the same problem occurs in the function dni (Determine DNI from GHI and DHI). Practical solutions for that particular case were discussed at length in #250.
So the functions behave ok for some problematic inputs but not for others. I think it's in the scope of pvlib to be able to gracefully handle these inputs.
I agree with this. Maybe focus on the ratio AI/cos(zenith) which should become 0/0 at the horizon.
I think the Sandia National Laboratories documentation is wrong on this one. Just imagine 100% circumsolar diffuse: tilted diffuse could never be greater than horizontal diffuse with this formula, even with the array pointed at the sun.
@adriesse you are correct, thanks for catching that. We wrote cos(AOI) where we should have written Rb. And we should give the equation for Rb = cos(AOI) / cos(zenith).
Loutzenhiser doesn't give an explicit expression for Rb. I could dig up the original Hay and Davies paper if we need to confirm, but others have written out the expression Rb = cos(AOI) / cos(zenith)
The handling of zenith near 90 in PVLib for Matlab was our addition to Hay and Davies. An alternative value for Hay and Davies at zenith = 90 would be the isotropic sky diffuse component, reasoning that at zenith = 90 there is not direct or circumsolar irradiance that reaches a tilted surface near ground level. We could linearly interpolate from 89 (or 88) to 90.
I am confident that the Hay and Davies model did not anticipate being applied at zenith = 90 and that we won't find any guidance in the original paper.
The Hay-Davies model is equal to the isotropic model when DNI is 0. So, I think the matlab approach of ensuring that Rb doesn't explode while DNI goes to 0 at the horizon is a kind of implicit interpolation. Maybe that's not the right way to put it, but hopefully it gets the point across.
There is one more difference with the matlab implementation. In pvl_haydavies1989.m:
RB = max(COSTT,0)./max(cosd(SunZen),0.01745);
Our python haydavies does not restrict the numerator to positive values:
Activity
wholmgren commentedon Feb 19, 2018
A related issue was discussed and a potential solution was proposed, but it was not merged.
I see that a similar issue could come up in
reindl. I don't see any other problems in theirradiance.pymodule. I'm going to go ahead and change this issue to be specific to the transposition functions. Please post separate issues if you find them in the rest of the library.I'll post a few
haydaviesandreindlcalculations that use only slightly unphysical input data:So the functions behave ok for some problematic inputs but not for others. I think it's in the scope of pvlib to be able to gracefully handle these inputs.
We could do this here for consistency. It seems somewhat arbitrary but pragmatic to me. I looked at the git history and I saw that the original port did contain this code, but I removed it as one of many changes to clean up and simplify the library. My bad.
The pvlib implementation roughly follows the Loutzenhiser 2007 description of the model.
From a numerical standpoint, the PVPMC website's description would be a better implementation. There may be some legacy here that I'm not aware of, such as the MATLAB function could have at one point returned the total POA irradiance, rather than just the sky diffuse component.See Loutzenhiser 2007. The implementation is correct, it's just not numerically the best way to do it.
[-]Dividing by cos(solar_zenith)[/-][+]Dividing by cos(solar_zenith) in haydavies and reindl functions[/+]adriesse commentedon Feb 20, 2018
I think the Sandia National Laboratories documentation is wrong on this one. Just imagine 100% circumsolar diffuse: tilted diffuse could never be greater than horizontal diffuse with this formula, even with the array pointed at the sun.
adriesse commentedon Feb 20, 2018
Essentially the same problem occurs in the function
dni(Determine DNI from GHI and DHI). Practical solutions for that particular case were discussed at length in #250.adriesse commentedon Feb 20, 2018
I agree with this. Maybe focus on the ratio
AI/cos(zenith)which should become 0/0 at the horizon.cwhanse commentedon Feb 20, 2018
@adriesse you are correct, thanks for catching that. We wrote
cos(AOI)where we should have writtenRb. And we should give the equation forRb = cos(AOI) / cos(zenith).Loutzenhiser doesn't give an explicit expression for
Rb. I could dig up the original Hay and Davies paper if we need to confirm, but others have written out the expressionRb = cos(AOI) / cos(zenith)https://www.researchgate.net/publication/275276907_Comparative_study_of_isotropic_and_anisotropic_sky_models_to_estimate_solar_radiation_incident_on_tilted_surface_A_case_study_for_Bhopal_India
for example.
cwhanse commentedon Feb 20, 2018
The handling of zenith near 90 in PVLib for Matlab was our addition to Hay and Davies. An alternative value for Hay and Davies at zenith = 90 would be the isotropic sky diffuse component, reasoning that at zenith = 90 there is not direct or circumsolar irradiance that reaches a tilted surface near ground level. We could linearly interpolate from 89 (or 88) to 90.
I am confident that the Hay and Davies model did not anticipate being applied at zenith = 90 and that we won't find any guidance in the original paper.
wholmgren commentedon Feb 21, 2018
The Hay-Davies model is equal to the isotropic model when DNI is 0. So, I think the matlab approach of ensuring that
Rbdoesn't explode while DNI goes to 0 at the horizon is a kind of implicit interpolation. Maybe that's not the right way to put it, but hopefully it gets the point across.There is one more difference with the matlab implementation. In
pvl_haydavies1989.m:RB = max(COSTT,0)./max(cosd(SunZen),0.01745);Our python
haydaviesdoes not restrict the numerator to positive values:The same discrepancy is also present in the Reindl implementations. So, that's another problem with the python implementations.