Skip to content

Commit aa3e6e9

Browse files
committed
restart from PR2567
1 parent 28ea577 commit aa3e6e9

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

docs/sphinx/source/whatsnew/v0.13.2.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Enhancements
2727
:py:func:`~pvlib.singlediode.bishop88_mpp`,
2828
:py:func:`~pvlib.singlediode.bishop88_v_from_i`, and
2929
:py:func:`~pvlib.singlediode.bishop88_i_from_v`. (:issue:`2497`, :pull:`2498`)
30-
30+
* Accelerate :py:func:`~pvlib.pvsystem.singlediode` when scipy>=1.15 is
31+
installed. (:issue:`2497`, :pull:`XXXX`)
3132

3233

3334
Documentation
@@ -53,4 +54,4 @@ Maintenance
5354

5455
Contributors
5556
~~~~~~~~~~~~
56-
57+
* Cliff Hansen (:ghuser:`cwhanse`)

pvlib/singlediode.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,24 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
913913
v_oc = 0.
914914

915915
# Find the voltage, v_mp, where the power is maximized.
916-
# Start the golden section search at v_oc * 1.14
917-
p_mp, v_mp = _golden_sect_DataFrame(params, 0., v_oc * 1.14, _pwr_optfcn)
918-
919-
# Find Imp using Lambert W
920-
i_mp = _lambertw_i_from_v(v_mp, **params)
916+
# use scipy.elementwise if available
917+
# remove try/except when scipy>=1.15, and golden mean is retired
918+
try:
919+
from scipy.optimize.elementwise import find_minimum
920+
init = (0., 0.8*v_oc, v_oc)
921+
res = find_minimum(_vmp_opt, init,
922+
args=(params['photocurrent'],
923+
params['saturation_current'],
924+
params['resistance_series'],
925+
params['resistance_shunt'],
926+
params['nNsVth'],))
927+
v_mp = res.x
928+
p_mp = -1.*res.f_x
929+
except ModuleNotFoundError:
930+
# switch to old golden section method
931+
p_mp, v_mp = _golden_sect_DataFrame(params, 0., v_oc * 1.14,
932+
_pwr_optfcn)
933+
i_mp = p_mp / v_mp
921934

922935
# Find Ix and Ixx using Lambert W
923936
i_x = _lambertw_i_from_v(0.5 * v_oc, **params)
@@ -938,6 +951,15 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
938951
return out
939952

940953

954+
def _vmp_opt(v, iph, io, rs, rsh, nNsVth):
955+
'''
956+
Function to find negative of power from ``i_from_v``.
957+
'''
958+
current = _lambertw_i_from_v(v, iph, io, rs, rsh, nNsVth)
959+
960+
return -v * current
961+
962+
941963
def _pwr_optfcn(df, loc):
942964
'''
943965
Function to find power from ``i_from_v``.

0 commit comments

Comments
 (0)