@@ -913,8 +913,28 @@ 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 )
916+ # use scipy.elementwise if available
917+ use_gs = False
918+ try :
919+ from scipy .optimize .elementwise import find_minimum
920+ init = (0. , 0.8 * v_oc , 1.01 * 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+ if res .success .all ():
928+ v_mp = res .x
929+ p_mp = - 1. * res .f_x
930+ else :
931+ use_gs = True
932+ except ModuleNotFoundError :
933+ use_gs = True
934+
935+ if use_gs :
936+ # gracefully switch to old golden section method
937+ p_mp , v_mp = _golden_sect_DataFrame (params , 0. , v_oc * 1.14 , _pwr_optfcn )
918938
919939 # Find Imp using Lambert W
920940 i_mp = _lambertw_i_from_v (v_mp , ** params )
@@ -938,6 +958,15 @@ def _lambertw(photocurrent, saturation_current, resistance_series,
938958 return out
939959
940960
961+ def _vmp_opt (v , iph , io , rs , rsh , nNsVth ):
962+ '''
963+ Function to find power from ``i_from_v``.
964+ '''
965+ current = _lambertw_i_from_v (v , iph , io , rs , rsh , nNsVth )
966+
967+ return - v * current
968+
969+
941970def _pwr_optfcn (df , loc ):
942971 '''
943972 Function to find power from ``i_from_v``.
0 commit comments