@@ -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+
941963def _pwr_optfcn (df , loc ):
942964 '''
943965 Function to find power from ``i_from_v``.
0 commit comments