diff --git a/docs/sphinx/source/whatsnew/v0.4.0.txt b/docs/sphinx/source/whatsnew/v0.4.0.txt index 03eaa8a90d..ecd2ed6675 100644 --- a/docs/sphinx/source/whatsnew/v0.4.0.txt +++ b/docs/sphinx/source/whatsnew/v0.4.0.txt @@ -48,6 +48,12 @@ Enhancements Bug fixes ~~~~~~~~~ +* Fixed an error in pvsystem.singlediode's i_mp, v_mp, and p_mp + calculations when using array or Series input. The function wrongly + returned solutions when any single point is within the error tolerance, + rather than requiring that the solution for all points be within the + error tolerance. Results in test scenarios changed by 1-10%. + (:issue:`221`) * dirint function yielded the wrong results for non-sea-level pressures. Fixed. (:issue:`212`) * Fixed a bug in the day angle calculation used by the 'spencer' and 'asce' diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 812c74583f..4b8c6e6b05 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -1725,7 +1725,7 @@ def _golden_sect_DataFrame(params, VL, VH, func): err = df['V1'] - df['V2'] try: - errflag = (abs(err) > .01).all() + errflag = (abs(err) > .01).any() except ValueError: errflag = (abs(err) > .01) diff --git a/pvlib/test/test_pvsystem.py b/pvlib/test/test_pvsystem.py index 3c8aa08a71..c6a6eb3edc 100644 --- a/pvlib/test/test_pvsystem.py +++ b/pvlib/test/test_pvsystem.py @@ -383,6 +383,26 @@ def test_singlediode_series(sam_data): assert isinstance(out, pd.DataFrame) +@requires_scipy +def test_singlediode_array(): + # github issue 221 + photocurrent = np.linspace(0, 10, 11) + resistance_shunt = 16 + resistance_series = 0.094 + nNsVth = 0.473 + saturation_current = 1.943e-09 + + sd = pvsystem.singlediode(photocurrent, saturation_current, + resistance_series, resistance_shunt, nNsVth) + + expected = np.array([ + 0. , 0.54538398, 1.43273966, 2.36328163, 3.29255606, + 4.23101358, 5.16177031, 6.09368251, 7.02197553, 7.96846051, + 8.88220557]) + + assert_allclose(sd['i_mp'], expected, atol=0.01) + + @requires_scipy def test_singlediode_floats(sam_data): module = 'Example_Module'