limit cos(aoi) in diffuse sky functions#535
Conversation
| into the plane of the array. For example, 0 is equivalent to a | ||
| 90 degree limit, 0.01745 is equivalent to a 89 degree limit. | ||
| `None` applies no limit. | ||
|
|
There was a problem hiding this comment.
Your explanation makes me wonder whether the minimum would be better expressed in degrees.
There was a problem hiding this comment.
Yes, I also wondered this. I only went with the projection because it's the quantity that is hardcoded in the matlab library.
There was a problem hiding this comment.
After thinking through the response to your comment below, I am leaning towards keeping it as the dot product to avoid the complexity of handling angles > 90 degrees or less than 0.
There was a problem hiding this comment.
I'm having trouble seeing a use case which requires projection_minimum. The function's description says it calculates a dot product so that's what I'd expect it to do, and to not do more.
There was a problem hiding this comment.
Actually it does less than a dot product since it assumes/requires the vectors are unit vectors. It's really just calculating the cosine of the angle of incidence. I think the name "projection" seems to suggest more, and may even be confusing to some.
There was a problem hiding this comment.
I will remove the projection_minimum kwargs and put the limits in the diffuse models where necessary. We can address the function name in a separate issue.
pvlib/irradiance.py
Outdated
|
|
||
| cos_solar_zenith = tools.cosd(solar_zenith) | ||
|
|
||
| if solar_zenith_projection_minimum is not None: |
There was a problem hiding this comment.
I don't think None should be possible here.
There was a problem hiding this comment.
I suppose we could go with a default value of -1 and always apply the limit.
pvlib/irradiance.py
Outdated
| projection_minimum=0) | ||
|
|
||
| cos_solar_zenith = tools.cosd(solar_zenith) | ||
| cos_solar_zenith = np.maximum(tools.cosd(solar_zenith), 0.01745) |
There was a problem hiding this comment.
For Rb this limit might be good, but for HB further below the limit should be zero (already enforced).
There was a problem hiding this comment.
Agreed. I'll fix this.
There was a problem hiding this comment.
IMO it is more clear to leave the cos_tt and cos_solar_zenith calculations alone, and apply the filters to the value of Rb.
| into the plane of the array. For example, 0 is equivalent to a | ||
| 90 degree limit, 0.01745 is equivalent to a 89 degree limit. | ||
| `None` applies no limit. | ||
|
|
There was a problem hiding this comment.
I'm having trouble seeing a use case which requires projection_minimum. The function's description says it calculates a dot product so that's what I'd expect it to do, and to not do more.
pvlib/irradiance.py
Outdated
| into the plane of the array. `None` applies no limit. | ||
| solar_zenith_projection_minimum : numeric, default None | ||
| Minimum allowable value for the projection of the solar angle | ||
| on to a horizontal surface. `None` applies no limit. |
There was a problem hiding this comment.
I'm struggling to see how the xxx_minimum kwargs are more clear than handling the behind-the-plane or nearly co-planar cases directly, in the calculation of the ratios in the diffuse sky models.
There was a problem hiding this comment.
That's fair. I think this is a borderline case of "don't repeat yourself". I have no idea if people use these functions on their own.
pvlib/irradiance.py
Outdated
| cos_solar_zenith = np.maximum(cos_solar_zenith, | ||
| solar_zenith_projection_minimum) | ||
|
|
||
| # ratio of titled and horizontal beam irradiance |
|
@cwhanse is it easy enough for you to run the matlab equivalents of klucher, haydavies, reindl, king with the same inputs as our test suite? |
|
@cwhanse is pvlib-matlab all functions, no classes? If so it should run in Octave, so then if there's a test suite, you could run it on a CI server like Travis. Just use sudo install octave in the build script |
|
Yes, PVLib for Matlab is a collection of function. We currently have no test suite for PVLib for Matlab, which is a major deficiency. |
|
I'm working on some matlab/python tests here: https://github.com/wholmgren/MATLAB_PV_LIB/blob/skydifftest/tests/test_sky_diffuse.m I have little idea about what I'm doing with matlab testing, but it seems to get the job done for this pvlib python PR. @cwhanse if you're interested I can make a PR to the matlab repository, but I imagine you all might have a preferred way to do the testing. |
|
Klucher: The expected result for |
pvlib/irradiance.py
Outdated
| if projection_ratio is None: | ||
| cos_tt = aoi_projection(surface_tilt, surface_azimuth, | ||
| solar_zenith, solar_azimuth) | ||
| cos_tt = np.minimum(cos_tt, 0) # GH 526 |
There was a problem hiding this comment.
Hay and Davies:
test_haydavies fails because of this error np.minimum. Otherwise I believe it should pass.
pvlib/irradiance.py
Outdated
|
|
||
| cos_tt = aoi_projection(surface_tilt, surface_azimuth, | ||
| solar_zenith, solar_azimuth) | ||
| cos_tt = np.minimum(cos_tt, 0) # GH 526 |
|
The test failures are unrelated. I believe this is ready to merge. |
Fixes two issues related to projection of the solar angle:
reindl,haydavies, andklucherfunctions.Implementation is up for debate. Seemed easier to make a pull request with a concrete proposal.
I considered calculating the
cos_solar_zenithas:but I am worried this could lead to issues with small floating point arithmetic (worse, they could be platform and python/numpy version dependent).
docs/sphinx/source/api.rstfor API changes.docs/sphinx/source/whatsnewfile for all changes.git diff upstream/master -u -- "*.py" | flake8 --diffother: