Skip to content

Commit ceaf104

Browse files
authored
Fix major error in singlediode p_mp calculation for array/Series input (#222)
* fix issue with singlediode p_mp, i_mp, v_mp calculation for arrays * edit whatsnew
1 parent bfbdb23 commit ceaf104

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

docs/sphinx/source/whatsnew/v0.4.0.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ Enhancements
5151
Bug fixes
5252
~~~~~~~~~
5353

54+
* Fixed an error in pvsystem.singlediode's i_mp, v_mp, and p_mp
55+
calculations when using array or Series input. The function wrongly
56+
returned solutions when any single point is within the error tolerance,
57+
rather than requiring that the solution for all points be within the
58+
error tolerance. Results in test scenarios changed by 1-10%.
59+
(:issue:`221`)
5460
* dirint function yielded the wrong results for non-sea-level pressures.
5561
Fixed. (:issue:`212`)
5662
* Fixed a bug in the day angle calculation used by the 'spencer' and 'asce'

pvlib/pvsystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ def _golden_sect_DataFrame(params, VL, VH, func):
17341734

17351735
err = df['V1'] - df['V2']
17361736
try:
1737-
errflag = (abs(err) > .01).all()
1737+
errflag = (abs(err) > .01).any()
17381738
except ValueError:
17391739
errflag = (abs(err) > .01)
17401740

pvlib/test/test_pvsystem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,26 @@ def test_singlediode_series(sam_data):
393393
assert isinstance(out, pd.DataFrame)
394394

395395

396+
@requires_scipy
397+
def test_singlediode_array():
398+
# github issue 221
399+
photocurrent = np.linspace(0, 10, 11)
400+
resistance_shunt = 16
401+
resistance_series = 0.094
402+
nNsVth = 0.473
403+
saturation_current = 1.943e-09
404+
405+
sd = pvsystem.singlediode(photocurrent, saturation_current,
406+
resistance_series, resistance_shunt, nNsVth)
407+
408+
expected = np.array([
409+
0. , 0.54538398, 1.43273966, 2.36328163, 3.29255606,
410+
4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051,
411+
8.88220557])
412+
413+
assert_allclose(sd['i_mp'], expected, atol=0.01)
414+
415+
396416
@requires_scipy
397417
def test_singlediode_floats(sam_data):
398418
module = 'Example_Module'

0 commit comments

Comments
 (0)