Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Enhancements
Bug fixes
~~~~~~~~~

* Fixed bug in :py:func:`pvlib.shading.masking_angle` and :py:func:`pvlib.bifacial.infinite_sheds._ground_angle`
where zero ``gcr`` input caused a ZeroDivisionError (:issue:`1576`, :pull:`1589`)

Testing
~~~~~~~
Expand All @@ -43,3 +45,4 @@ Contributors
* Christian Orner (:ghuser:`chrisorner`)
* Saurabh Aneja (:ghuser:`spaneja`)
* Marcus Boumans (:ghuser:`bowie2211`)
* Karel De Brabandere (:ghuser:`kdebrab`)
4 changes: 2 additions & 2 deletions pvlib/bifacial/infinite_sheds.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def _ground_angle(x, surface_tilt, gcr):
# : \ v *-.\
# : \<-----P---->\

x1 = x * sind(surface_tilt)
x2 = (x * cosd(surface_tilt) + 1 / gcr)
x1 = gcr * x * sind(surface_tilt)
x2 = gcr * x * cosd(surface_tilt) + 1
psi = np.arctan2(x1, x2) # do this first because it handles 0 / 0
return np.rad2deg(psi)

Expand Down
4 changes: 2 additions & 2 deletions pvlib/shading.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def masking_angle(surface_tilt, gcr, slant_height):
# The original equation (8 in [1]) requires pitch and collector width,
# but it's easy to non-dimensionalize it to make it a function of GCR
# by factoring out B from the argument to arctan.
numerator = (1 - slant_height) * sind(surface_tilt)
denominator = 1/gcr - (1 - slant_height) * cosd(surface_tilt)
numerator = gcr * (1 - slant_height) * sind(surface_tilt)
denominator = 1 - gcr * (1 - slant_height) * cosd(surface_tilt)
phi = np.arctan(numerator / denominator)
return np.degrees(phi)

Expand Down
8 changes: 8 additions & 0 deletions pvlib/tests/bifacial/test_infinite_sheds.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def test__ground_angle(test_system):
assert np.allclose(angles, expected_angles)


def test__ground_angle_zero_gcr():
surface_tilt = 30.0
x = np.array([0.0, 0.5, 1.0])
angles = infinite_sheds._ground_angle(x, surface_tilt, 0)
expected_angles = np.array([0, 0, 0])
assert np.allclose(angles, expected_angles)


def test__vf_row_ground(test_system):
ts, _, _ = test_system
x = np.array([0., 0.5, 1.0])
Expand Down
7 changes: 7 additions & 0 deletions pvlib/tests/test_shading.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def test_masking_angle_scalar(surface_tilt, masking_angle):
assert np.isclose(masking_angle_actual, angle)


def test_masking_angle_zero_gcr(surface_tilt):
# scalar inputs and outputs, including zero
for tilt in surface_tilt:
masking_angle_actual = shading.masking_angle(tilt, 0, 0.25)
assert np.isclose(masking_angle_actual, 0)


def test_masking_angle_passias_series(surface_tilt, average_masking_angle):
# pandas series inputs and outputs
masking_angle_actual = shading.masking_angle_passias(surface_tilt, 0.5)
Expand Down