Skip to content

[bug] use clip instead of abs #1272

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pvlib/tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,18 @@ def test_slope_aware_backtracking():
np.testing.assert_allclose(
truetracking['tracker_theta'], expected_data['TrueTracking'],
rtol=1e-3, atol=1e-3)


def test_singleaxis_aoi_gh1221():
# vertical tracker
loc = pvlib.location.Location(40.1134, -88.3695)
dr = pd.date_range(
start='02-Jun-1998 00:00:00', end='02-Jun-1998 23:55:00', freq='5T',
tz='Etc/GMT+6')
sp = loc.get_solarposition(dr)
tr = pvlib.tracking.singleaxis(
sp['apparent_zenith'], sp['azimuth'], axis_tilt=90, axis_azimuth=180,
max_angle=0.01, backtrack=False)
fixed = pvlib.irradiance.aoi(90, 180, sp['apparent_zenith'], sp['azimuth'])
fixed[fixed>90] = np.nan
assert np.allclose(tr['aoi'], fixed, equal_nan=True)
4 changes: 3 additions & 1 deletion pvlib/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ def singleaxis(apparent_zenith, apparent_azimuth,
sun_vec = np.array([xp, yp, zp])

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

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