1414
1515from pvlib .pvsystem import singlediode , v_from_i
1616
17- from pvlib .ivtools .utility import constants , rectify_iv_curve , _numdiff
17+ from pvlib .ivtools .utils import rectify_iv_curve , _numdiff
1818from pvlib .ivtools .sde import _fit_sandia_cocontent
1919
2020
@@ -299,7 +299,7 @@ def _system_of_equations_desoto(params, specs):
299299 return y
300300
301301
302- def fit_pvsyst_sandia (ivcurves , specs , const = constants , maxiter = 5 , eps1 = 1.e-3 ):
302+ def fit_pvsyst_sandia (ivcurves , specs , const = None , maxiter = 5 , eps1 = 1.e-3 ):
303303 """
304304 Estimate parameters for the PVsyst module performance model.
305305
@@ -414,6 +414,9 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
414414 .. [7] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
415415 """
416416
417+ if const is None :
418+ const = {'E0' : 1000.0 , 'T0' : 25.0 , 'k' : 1.38066e-23 , 'q' : 1.60218e-19 }
419+
417420 ee = ivcurves ['ee' ]
418421 tc = ivcurves ['tc' ]
419422 tck = tc + 273.15
@@ -474,7 +477,7 @@ def fit_pvsyst_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
474477 return pvsyst
475478
476479
477- def fit_desoto_sandia (ivcurves , specs , const = constants , maxiter = 5 , eps1 = 1.e-3 ):
480+ def fit_desoto_sandia (ivcurves , specs , const = None , maxiter = 5 , eps1 = 1.e-3 ):
478481 """
479482 Estimate parameters for the De Soto module performance model.
480483
@@ -573,6 +576,9 @@ def fit_desoto_sandia(ivcurves, specs, const=constants, maxiter=5, eps1=1.e-3):
573576 .. [4] PVLib MATLAB https://github.com/sandialabs/MATLAB_PV_LIB
574577 """
575578
579+ if const is None :
580+ const = {'E0' : 1000.0 , 'T0' : 25.0 , 'k' : 1.38066e-23 , 'q' : 1.60218e-19 }
581+
576582 ee = ivcurves ['ee' ]
577583 tc = ivcurves ['tc' ]
578584 tck = tc + 273.15
@@ -936,10 +942,11 @@ def _update_io(voc, iph, io, rs, rsh, nnsvth):
936942 dvoc = pvoc - voc
937943
938944 # Update Io
939- new_io = tio * (1. + (2. * dvoc ) / (2. * nnsvth - dvoc ))
945+ with np .errstate (invalid = "ignore" , divide = "ignore" ):
946+ new_io = tio * (1. + (2. * dvoc ) / (2. * nnsvth - dvoc ))
947+ # Calculate Maximum Percent Difference
948+ maxerr = np .max (np .abs (new_io - tio ) / tio ) * 100.
940949
941- # Calculate Maximum Percent Difference
942- maxerr = np .max (np .abs (new_io - tio ) / tio ) * 100.
943950 tio = new_io
944951 k += 1.
945952
@@ -1128,8 +1135,9 @@ def _update_rsh_fixed_pt(vmp, imp, iph, io, rs, rsh, nnsvth):
11281135
11291136 for i in range (niter ):
11301137 _ , z = _calc_theta_phi_exact (vmp , imp , iph , io , rs , x1 , nnsvth )
1131- next_x1 = (1 + z ) / z * ((iph + io ) * x1 / imp - nnsvth * z / imp - 2 *
1132- vmp / imp )
1138+ with np .errstate (divide = "ignore" ):
1139+ next_x1 = (1 + z ) / z * ((iph + io ) * x1 / imp - nnsvth * z / imp
1140+ - 2 * vmp / imp )
11331141 x1 = next_x1
11341142
11351143 return x1
@@ -1191,12 +1199,12 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):
11911199
11921200 # Argument for Lambert W function involved in V = V(I) [2] Eq. 12; [3]
11931201 # Eq. 3
1194- with np .errstate (over = "ignore" ):
1202+ with np .errstate (over = "ignore" , divide = "ignore" , invalid = "ignore" ):
11951203 argw = np .where (
11961204 nnsvth == 0 ,
11971205 np .nan ,
11981206 rsh * io / nnsvth * np .exp (rsh * (iph + io - imp ) / nnsvth ))
1199- phi = np .where (argw > 0 , lambertw (argw ).real , np .nan )
1207+ phi = np .where (argw > 0 , lambertw (argw ).real , np .nan )
12001208
12011209 # NaN where argw overflows. Switch to log space to evaluate
12021210 u = np .isinf (argw )
@@ -1216,21 +1224,23 @@ def _calc_theta_phi_exact(vmp, imp, iph, io, rs, rsh, nnsvth):
12161224
12171225 # Argument for Lambert W function involved in I = I(V) [2] Eq. 11; [3]
12181226 # E1. 2
1219- with np .errstate (over = "ignore" ):
1227+ with np .errstate (over = "ignore" , divide = "ignore" , invalid = "ignore" ):
12201228 argw = np .where (
12211229 nnsvth == 0 ,
12221230 np .nan ,
12231231 rsh / (rsh + rs ) * rs * io / nnsvth * np .exp (
12241232 rsh / (rsh + rs ) * (rs * (iph + io ) + vmp ) / nnsvth ))
1225- theta = np .where (argw > 0 , lambertw (argw ).real , np .nan )
1233+ theta = np .where (argw > 0 , lambertw (argw ).real , np .nan )
12261234
12271235 # NaN where argw overflows. Switch to log space to evaluate
12281236 u = np .isinf (argw )
12291237 if np .any (u ):
1230- logargw = (
1231- np .log (rsh [u ]) / (rsh [u ] + rs [u ]) + np .log (rs [u ]) + np .log (io [u ])
1232- - np .log (nnsvth [u ]) + (rsh [u ] / (rsh [u ] + rs [u ]))
1233- * (rs [u ] * (iph [u ] + io [u ]) + vmp [u ]) / nnsvth [u ])
1238+ with np .errstate (divide = "ignore" ):
1239+ logargw = (
1240+ np .log (rsh [u ]) - np .log (rsh [u ] + rs [u ]) + np .log (rs [u ])
1241+ + np .log (io [u ]) - np .log (nnsvth [u ])
1242+ + (rsh [u ] / (rsh [u ] + rs [u ]))
1243+ * (rs [u ] * (iph [u ] + io [u ]) + vmp [u ]) / nnsvth [u ])
12341244 # Three iterations of Newton-Raphson method to solve w+log(w)=logargW.
12351245 # The initial guess is w=logargW. Where direct evaluation (above)
12361246 # results in NaN from overflow, 3 iterations of Newton's method gives
0 commit comments