Skip to content

Commit

Permalink
limit pvwatts_ac to gte 0 (#542)
Browse files Browse the repository at this point in the history
Closes #541
  • Loading branch information
wholmgren authored and cwhanse committed Aug 23, 2018
1 parent 5728d11 commit 0abc6ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew/v0.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Bug fixes
Hay-Davies diffuse sky algorithms. (:issue:`432`)
* Fix argument order of longitude and latitude when querying weather forecasts
by lonlat bounding box (:issue:`521`)
* Limit pvwatts_ac results to be greater than or equal to 0. (:issue:`541`)


Documentation
Expand Down
2 changes: 2 additions & 0 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,9 +2693,11 @@ def pvwatts_ac(pdc, pdc0, eta_inv_nom=0.96, eta_inv_ref=0.9637):
pac0 = eta_inv_nom * pdc0
zeta = pdc / pdc0

# 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)

pac = eta * pdc
pac = np.minimum(pac0, pac)
pac = np.maximum(0, pac) # GH 541

return pac
8 changes: 8 additions & 0 deletions pvlib/test/test_pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,14 @@ def test_pvwatts_ac_scalars():
assert_allclose(out, expected)


def test_pvwatts_ac_possible_negative():
# pvwatts_ac could return a negative value for (pdc / pdc0) < 0.006
# unless it is clipped. see GH 541 for more
expected = 0
out = pvsystem.pvwatts_ac(0.001, 1)
assert_allclose(out, expected)


@needs_numpy_1_10
def test_pvwatts_ac_arrays():
pdc = np.array([[np.nan], [50], [100]])
Expand Down

0 comments on commit 0abc6ce

Please sign in to comment.