Skip to content

fix pvwatts_ac exception and return value when called with pdc=0s #676

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

Merged
merged 2 commits into from
Mar 20, 2019
Merged
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
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.6.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Enhancements
Bug fixes
~~~~~~~~~
* Compatibility with pandas 0.24 deprecations. (:issue:`659`)
* pvwatts_ac raised ZeroDivisionError when called with scalar pdc=0
and a RuntimeWarning for array(0) input. Now correctly returns 0s
of the appropriate type. (:issue:`675`)


Testing
Expand Down
9 changes: 8 additions & 1 deletion pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2967,8 +2967,15 @@ def pvwatts_ac(pdc, pdc0, eta_inv_nom=0.96, eta_inv_ref=0.9637):
pac0 = eta_inv_nom * pdc0
zeta = pdc / pdc0

# arrays to help avoid divide by 0 for scalar and array
eta = np.zeros_like(pdc, dtype=float)
pdc_neq_0 = ~np.equal(pdc, 0)

# eta < 0 if zeta < 0.006. pac is forced to be >= 0 below. GH 541
eta = eta_inv_nom / eta_inv_ref * (-0.0162*zeta - 0.0059/zeta + 0.9858)
eta = eta_inv_nom / eta_inv_ref * (
- 0.0162*zeta
- np.divide(0.0059, zeta, out=eta, where=pdc_neq_0)
+ 0.9858)

pac = eta * pdc
pac = np.minimum(pac0, pac)
Expand Down
11 changes: 8 additions & 3 deletions pvlib/test/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ def test_pvwatts_ac_scalars():
expected = 85.58556604752516
out = pvsystem.pvwatts_ac(90, 100, 0.95)
assert_allclose(out, expected)
# GH 675
expected = 0.
out = pvsystem.pvwatts_ac(0., 100)
assert_allclose(out, expected)


def test_pvwatts_ac_possible_negative():
Expand All @@ -1378,19 +1382,20 @@ def test_pvwatts_ac_possible_negative():

@needs_numpy_1_10
def test_pvwatts_ac_arrays():
pdc = np.array([[np.nan], [50], [100]])
pdc = np.array([[np.nan], [0], [50], [100]])
pdc0 = 100
expected = np.array([[nan],
[0.],
[47.60843624],
[95.]])
out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95)
assert_allclose(out, expected, equal_nan=True)


def test_pvwatts_ac_series():
pdc = pd.Series([np.nan, 50, 100])
pdc = pd.Series([np.nan, 0, 50, 100])
pdc0 = 100
expected = pd.Series(np.array([ nan, 47.608436, 95. ]))
expected = pd.Series(np.array([nan, 0., 47.608436, 95.]))
out = pvsystem.pvwatts_ac(pdc, pdc0, 0.95)
assert_series_equal(expected, out)

Expand Down