Skip to content

Commit 0fd5c43

Browse files
authored
[bug] use clip instead of abs in singleaxis (#1273)
* [bug] use clip instead of abs * [test] add test using repro steps * check if single axis tracker has correct aoi when sun is behind modules by comparison to fixed and limiting rotation * [sty] fix stickler * [test] oops forgot aoi key * [test] oops typo tr['aoi' * [test] set angles behind fixed to nan * [test] use smaller max angle, set nans from tracker * [doc] whatsnew singleaxis aoi fix gh1221
1 parent 9543d87 commit 0fd5c43

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ Bug fixes
192192
(:issue:`1257`, :pull:`1258`)
193193
* Changed deprecated use of ``.astype()`` to ``.view()`` in :py:mod:`~pvlib.solarposition`.
194194
(:pull:`1256`, :issue:`1261`, :pull:`1262`)
195+
* Fix :py:func:`~pvlib.tracking.singleaxis` AOI wrong when sun behind module.
196+
(:pull:`1273`, :issue:`1221`)
195197

196198
Testing
197199
~~~~~~~

pvlib/tests/test_tracking.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,18 @@ def test_slope_aware_backtracking():
502502
np.testing.assert_allclose(
503503
truetracking['tracker_theta'], expected_data['TrueTracking'],
504504
rtol=1e-3, atol=1e-3)
505+
506+
507+
def test_singleaxis_aoi_gh1221():
508+
# vertical tracker
509+
loc = pvlib.location.Location(40.1134, -88.3695)
510+
dr = pd.date_range(
511+
start='02-Jun-1998 00:00:00', end='02-Jun-1998 23:55:00', freq='5T',
512+
tz='Etc/GMT+6')
513+
sp = loc.get_solarposition(dr)
514+
tr = pvlib.tracking.singleaxis(
515+
sp['apparent_zenith'], sp['azimuth'], axis_tilt=90, axis_azimuth=180,
516+
max_angle=0.001, backtrack=False)
517+
fixed = pvlib.irradiance.aoi(90, 180, sp['apparent_zenith'], sp['azimuth'])
518+
fixed[np.isnan(tr['aoi'])] = np.nan
519+
assert np.allclose(tr['aoi'], fixed, equal_nan=True)

pvlib/tracking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ def singleaxis(apparent_zenith, apparent_azimuth,
458458
sun_vec = np.array([xp, yp, zp])
459459

460460
# calculate angle-of-incidence on panel
461-
aoi = np.degrees(np.arccos(np.abs(np.sum(sun_vec*panel_norm, axis=0))))
461+
# TODO: use irradiance.aoi
462+
projection = np.clip(np.sum(sun_vec*panel_norm, axis=0), -1, 1)
463+
aoi = np.degrees(np.arccos(projection))
462464

463465
# Calculate panel tilt and azimuth in a coordinate system where the panel
464466
# tilt is the angle from horizontal, and the panel azimuth is the compass

0 commit comments

Comments
 (0)