Skip to content

Commit 5bdad64

Browse files
authored
Update irradiance.aoi to use more reliable formula (#1191)
* clip to [-1, 1] * add test * whatsnew * use new aoi formula * revert changes to aoi_projection * update test and whatsnew * don't set name; break after first Series * roll back to 2a0425b * test improvements
1 parent 77ac247 commit 5bdad64

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/sphinx/source/whatsnew/v0.9.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ Bug fixes
133133
(:issue:`1065`, :pull:`1140`)
134134
* Reindl model fixed to generate sky_diffuse=0 when GHI=0.
135135
(:issue:`1153`, :pull:`1154`)
136+
* Fix floating point round-off issue in
137+
:py:func:`~pvlib.irradiance.aoi_projection` (:issue:`1185`, :pull:`1191`)
136138
* Update GFS product names for GFS v16. (:issue:`1202`, :pull:`1203`)
137139
* Corrected methodology error in :py:func:`~pvlib.scaling.wvm`. Tracks with
138140
fix in PVLib for MATLAB. (:issue:`1206`, :pull:`1213`)

pvlib/irradiance.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def aoi_projection(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth):
182182
tools.sind(surface_tilt) * tools.sind(solar_zenith) *
183183
tools.cosd(solar_azimuth - surface_azimuth))
184184

185+
# GH 1185
186+
projection = np.clip(projection, -1, 1)
187+
185188
try:
186189
projection.name = 'aoi_projection'
187190
except AttributeError:

pvlib/tests/test_irradiance.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,27 @@ def test_aoi_and_aoi_projection(surface_tilt, surface_azimuth, solar_zenith,
792792
assert_allclose(aoi_projection, aoi_proj_expected, atol=1e-6)
793793

794794

795+
def test_aoi_projection_precision():
796+
# GH 1185 -- test that aoi_projection does not exceed 1.0, and when
797+
# given identical inputs, the returned projection is very close to 1.0
798+
799+
# scalars
800+
zenith = 89.26778228223463
801+
azimuth = 60.932028605997004
802+
projection = irradiance.aoi_projection(zenith, azimuth, zenith, azimuth)
803+
assert projection <= 1
804+
assert np.isclose(projection, 1)
805+
806+
# arrays
807+
zeniths = np.array([zenith])
808+
azimuths = np.array([azimuth])
809+
projections = irradiance.aoi_projection(zeniths, azimuths,
810+
zeniths, azimuths)
811+
assert all(projections <= 1)
812+
assert all(np.isclose(projections, 1))
813+
assert projections.dtype == np.dtype('float64')
814+
815+
795816
@pytest.fixture
796817
def airmass_kt():
797818
# disc algorithm stopped at am=12. test am > 12 for out of range behavior

0 commit comments

Comments
 (0)