From aa6df598e8f44215cc3c0e2f96e4b002ea55ad6a Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Wed, 10 May 2023 16:57:58 -0700 Subject: [PATCH 1/4] fix recombination args in pvsystem.maximum_power_point * d2mutau and NsVbi were hardcoded instead of passing through the arguments to the function --- docs/sphinx/source/whatsnew/v0.9.6.rst | 3 +++ pvlib/pvsystem.py | 3 +-- pvlib/tests/test_pvsystem.py | 35 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index 7d1271086f..cb935bfd9f 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -17,6 +17,8 @@ Bug fixes ~~~~~~~~~ * `data` can no longer be left unspecified in :py:meth:`pvlib.modelchain.ModelChain.run_model_from_effective_irradiance`. (:issue:`1713`, :pull:`1720`) +* fix ``d2mutau`` and ``NsVbi`` were hardcoded in :py:func:`pvlib.pvsystem.max_power_point` instead of + passing through the arguments to the function. Testing ~~~~~~~ @@ -43,4 +45,5 @@ Contributors * Siddharth Kaul (:ghuser:`k10blogger`) * Kshitiz Gupta (:ghuser:`kshitiz305`) * Stefan de Lange (:ghuser:`langestefan`) +* Mark Mikofski (:ghuser:`mikofski`) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 0cf034e9b0..65c33d0146 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -2948,8 +2948,7 @@ def max_power_point(photocurrent, saturation_current, resistance_series, """ i_mp, v_mp, p_mp = _singlediode.bishop88_mpp( photocurrent, saturation_current, resistance_series, - resistance_shunt, nNsVth, d2mutau=0, NsVbi=np.Inf, - method=method.lower() + resistance_shunt, nNsVth, d2mutau, NsVbi, method=method.lower() ) if isinstance(photocurrent, pd.Series): ivp = {'i_mp': i_mp, 'v_mp': v_mp, 'p_mp': p_mp} diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py index 7fa013d0dc..2b767037d8 100644 --- a/pvlib/tests/test_pvsystem.py +++ b/pvlib/tests/test_pvsystem.py @@ -19,6 +19,8 @@ from pvlib import temperature from pvlib._deprecation import pvlibDeprecationWarning from pvlib.tools import cosd +from pvlib.singlediode import VOLTAGE_BUILTIN +from pvlib.tests.test_singlediode import get_pvsyst_fs_495 @pytest.mark.parametrize('iam_model,model_params', [ @@ -1250,6 +1252,39 @@ def test_mpp_floats(): assert np.isclose(v, expected[k]) +def test_mpp_recombination(): + """test max_power_point""" + pvsyst_fs_495 = get_pvsyst_fs_495() + IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_pvsyst( + effective_irradiance=pvsyst_fs_495['irrad_ref'], + temp_cell=pvsyst_fs_495['temp_ref'], + alpha_sc=pvsyst_fs_495['alpha_sc'], + gamma_ref=pvsyst_fs_495['gamma_ref'], + mu_gamma=pvsyst_fs_495['mu_gamma'], I_L_ref=pvsyst_fs_495['I_L_ref'], + I_o_ref=pvsyst_fs_495['I_o_ref'], R_sh_ref=pvsyst_fs_495['R_sh_ref'], + R_sh_0=pvsyst_fs_495['R_sh_0'], R_sh_exp=pvsyst_fs_495['R_sh_exp'], + R_s=pvsyst_fs_495['R_s'], + cells_in_series=pvsyst_fs_495['cells_in_series'], + EgRef=pvsyst_fs_495['EgRef']) + out = pvsystem.max_power_point(IL, I0, Rs, Rsh, nNsVth, + d2mutau=pvsyst_fs_495['d2mutau'], + NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], method='brentq') + expected_imp = pvsyst_fs_495['I_mp_ref'] + expected_vmp = pvsyst_fs_495['V_mp_ref'] + expected_pmp = expected_imp*expected_vmp + expected = {'i_mp': expected_imp, + 'v_mp': expected_vmp, + 'p_mp': expected_pmp} + assert isinstance(out, dict) + for k, v in out.items(): + assert np.isclose(v, expected[k], 0.1) + out = pvsystem.max_power_point(IL, I0, Rs, Rsh, nNsVth, + d2mutau=pvsyst_fs_495['d2mutau'], + NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], method='newton') + for k, v in out.items(): + assert np.isclose(v, expected[k], 0.1) + + def test_mpp_array(): """test max_power_point""" IL, I0, Rs, Rsh, nNsVth = (np.array([7, 7]), 6e-7, .1, 20, .5) From 63288d5273ef7d51af8bfc544e8e78d4480b6d38 Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Wed, 10 May 2023 17:12:44 -0700 Subject: [PATCH 2/4] fix stickler --- pvlib/tests/test_pvsystem.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py index 2b767037d8..27905090e3 100644 --- a/pvlib/tests/test_pvsystem.py +++ b/pvlib/tests/test_pvsystem.py @@ -1266,9 +1266,11 @@ def test_mpp_recombination(): R_s=pvsyst_fs_495['R_s'], cells_in_series=pvsyst_fs_495['cells_in_series'], EgRef=pvsyst_fs_495['EgRef']) - out = pvsystem.max_power_point(IL, I0, Rs, Rsh, nNsVth, + out = pvsystem.max_power_point( + IL, I0, Rs, Rsh, nNsVth, d2mutau=pvsyst_fs_495['d2mutau'], - NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], method='brentq') + NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], + method='brentq') expected_imp = pvsyst_fs_495['I_mp_ref'] expected_vmp = pvsyst_fs_495['V_mp_ref'] expected_pmp = expected_imp*expected_vmp @@ -1278,9 +1280,11 @@ def test_mpp_recombination(): assert isinstance(out, dict) for k, v in out.items(): assert np.isclose(v, expected[k], 0.1) - out = pvsystem.max_power_point(IL, I0, Rs, Rsh, nNsVth, + out = pvsystem.max_power_point( + IL, I0, Rs, Rsh, nNsVth, d2mutau=pvsyst_fs_495['d2mutau'], - NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], method='newton') + NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], + method='newton') for k, v in out.items(): assert np.isclose(v, expected[k], 0.1) From e1488fd3f784c9a6965b8e5f86dcac7cbefb874a Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Thu, 11 May 2023 13:00:10 -0700 Subject: [PATCH 3/4] Update docs/sphinx/source/whatsnew/v0.9.6.rst remove "fix" from whatsnew Co-authored-by: Cliff Hansen --- docs/sphinx/source/whatsnew/v0.9.6.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index cb935bfd9f..6cce79405a 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -17,7 +17,7 @@ Bug fixes ~~~~~~~~~ * `data` can no longer be left unspecified in :py:meth:`pvlib.modelchain.ModelChain.run_model_from_effective_irradiance`. (:issue:`1713`, :pull:`1720`) -* fix ``d2mutau`` and ``NsVbi`` were hardcoded in :py:func:`pvlib.pvsystem.max_power_point` instead of +* ``d2mutau`` and ``NsVbi`` were hardcoded in :py:func:`pvlib.pvsystem.max_power_point` instead of passing through the arguments to the function. Testing From caa32ed4c7049e9f45721a900528c1d018f21c54 Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Fri, 9 Jun 2023 21:15:19 -0400 Subject: [PATCH 4/4] Apply suggestions from code review --- docs/sphinx/source/whatsnew/v0.9.6.rst | 2 +- pvlib/tests/test_pvsystem.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.9.6.rst b/docs/sphinx/source/whatsnew/v0.9.6.rst index 6cce79405a..54d7cd21b4 100644 --- a/docs/sphinx/source/whatsnew/v0.9.6.rst +++ b/docs/sphinx/source/whatsnew/v0.9.6.rst @@ -18,7 +18,7 @@ Bug fixes * `data` can no longer be left unspecified in :py:meth:`pvlib.modelchain.ModelChain.run_model_from_effective_irradiance`. (:issue:`1713`, :pull:`1720`) * ``d2mutau`` and ``NsVbi`` were hardcoded in :py:func:`pvlib.pvsystem.max_power_point` instead of - passing through the arguments to the function. + passing through the arguments to the function. (:pull:`1733`) Testing ~~~~~~~ diff --git a/pvlib/tests/test_pvsystem.py b/pvlib/tests/test_pvsystem.py index 27905090e3..64fc506045 100644 --- a/pvlib/tests/test_pvsystem.py +++ b/pvlib/tests/test_pvsystem.py @@ -1279,14 +1279,14 @@ def test_mpp_recombination(): 'p_mp': expected_pmp} assert isinstance(out, dict) for k, v in out.items(): - assert np.isclose(v, expected[k], 0.1) + assert np.isclose(v, expected[k], 0.01) out = pvsystem.max_power_point( IL, I0, Rs, Rsh, nNsVth, d2mutau=pvsyst_fs_495['d2mutau'], NsVbi=VOLTAGE_BUILTIN*pvsyst_fs_495['cells_in_series'], method='newton') for k, v in out.items(): - assert np.isclose(v, expected[k], 0.1) + assert np.isclose(v, expected[k], 0.01) def test_mpp_array():