@@ -414,11 +414,6 @@ def fit_pvsyst_iec61853_sandia(effective_irradiance, temp_cell,
414
414
of Photovoltaics, vol. 15, 3, 2025. :doi:`10.1109/JPHOTOV.2025.3554338`
415
415
"""
416
416
417
- try :
418
- import statsmodels .api as sm
419
- except ImportError :
420
- raise ImportError ('fit_pvsyst_iec61853_sandia requires statsmodels' )
421
-
422
417
is_g_stc = np .isclose (effective_irradiance , 1000 , rtol = 0 ,
423
418
atol = irradiance_tolerance )
424
419
is_t_stc = np .isclose (temp_cell , 25 , rtol = 0 ,
@@ -440,11 +435,10 @@ def fit_pvsyst_iec61853_sandia(effective_irradiance, temp_cell,
440
435
)
441
436
442
437
if R_s is None :
443
- R_s = _fit_series_resistance_pvsyst_iec61853_sandia (sm , v_oc ,
444
- i_mp , v_mp )
438
+ R_s = _fit_series_resistance_pvsyst_iec61853_sandia (v_oc , i_mp , v_mp )
445
439
446
440
gamma_ref , mu_gamma = _fit_diode_ideality_factor_pvsyst_iec61853_sandia (
447
- sm , i_sc [is_t_stc ], v_oc [is_t_stc ], i_mp [is_t_stc ], v_mp [is_t_stc ],
441
+ i_sc [is_t_stc ], v_oc [is_t_stc ], i_mp [is_t_stc ], v_mp [is_t_stc ],
448
442
effective_irradiance [is_t_stc ], temp_cell [is_t_stc ],
449
443
R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series
450
444
)
@@ -455,14 +449,14 @@ def fit_pvsyst_iec61853_sandia(effective_irradiance, temp_cell,
455
449
)
456
450
457
451
I_L_ref = _fit_photocurrent_pvsyst_iec61853_sandia (
458
- sm , i_sc , effective_irradiance , temp_cell , alpha_sc ,
452
+ i_sc , effective_irradiance , temp_cell , alpha_sc ,
459
453
gamma_ref , mu_gamma ,
460
454
I_o_ref , R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series , EgRef
461
455
)
462
456
463
457
gamma_ref , mu_gamma = \
464
458
_fit_diode_ideality_factor_post_pvsyst_iec61853_sandia (
465
- sm , i_mp , v_mp , effective_irradiance , temp_cell , alpha_sc , I_L_ref ,
459
+ i_mp , v_mp , effective_irradiance , temp_cell , alpha_sc , I_L_ref ,
466
460
I_o_ref , R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series , EgRef )
467
461
468
462
fitted_params = dict (
@@ -524,21 +518,20 @@ def _fit_shunt_resistances_pvsyst_iec61853_sandia(
524
518
return Rshref , Rsh0 , Rshexp
525
519
526
520
527
- def _fit_series_resistance_pvsyst_iec61853_sandia (sm , v_oc , i_mp , v_mp ):
521
+ def _fit_series_resistance_pvsyst_iec61853_sandia (v_oc , i_mp , v_mp ):
528
522
# Stein et al 2014, https://doi.org/10.1109/PVSC.2014.6925326
529
523
530
524
# Eq 13
531
- x = np .array ([i_mp , np .log (i_mp ), v_mp ]).T
532
- x = sm .add_constant (x )
525
+ x = np .array ([np .ones (len (i_mp )), i_mp , np .log (i_mp ), v_mp ]).T
533
526
y = v_oc
534
527
535
- results = sm . OLS ( endog = y , exog = x ). fit ( )
536
- R_s = results . params [ 'x1' ]
528
+ coeff , _ , _ , _ = np . linalg . lstsq ( x , y , rcond = None )
529
+ R_s = coeff [ 1 ]
537
530
return R_s
538
531
539
532
540
533
def _fit_diode_ideality_factor_pvsyst_iec61853_sandia (
541
- sm , i_sc , v_oc , i_mp , v_mp , effective_irradiance , temp_cell ,
534
+ i_sc , v_oc , i_mp , v_mp , effective_irradiance , temp_cell ,
542
535
R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series ):
543
536
544
537
NsVth = _pvsyst_nNsVth (temp_cell , gamma = 1 , cells_in_series = cells_in_series )
@@ -552,8 +545,8 @@ def _fit_diode_ideality_factor_pvsyst_iec61853_sandia(
552
545
x = np .array ([x1 ]).T
553
546
y = v_mp + i_mp * R_s - v_oc
554
547
555
- results = sm . OLS ( endog = y , exog = x ). fit ( )
556
- gamma_ref = results . params [ 'x1' ]
548
+ coeff , _ , _ , _ = np . linalg . lstsq ( x , y , rcond = None )
549
+ gamma_ref = coeff [ 0 ]
557
550
return gamma_ref , 0
558
551
559
552
@@ -576,7 +569,7 @@ def _fit_saturation_current_pvsyst_iec61853_sandia(
576
569
577
570
578
571
def _fit_photocurrent_pvsyst_iec61853_sandia (
579
- sm , i_sc , effective_irradiance , temp_cell , alpha_sc , gamma_ref ,
572
+ i_sc , effective_irradiance , temp_cell , alpha_sc , gamma_ref ,
580
573
mu_gamma , I_o_ref , R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series ,
581
574
EgRef ):
582
575
R_sh = _pvsyst_Rsh (effective_irradiance , R_sh_ref , R_sh_0 , R_sh_exp )
@@ -590,13 +583,13 @@ def _fit_photocurrent_pvsyst_iec61853_sandia(
590
583
# Eq 20
591
584
x = np .array ([effective_irradiance / 1000 ]).T
592
585
y = I_L_est - effective_irradiance / 1000 * alpha_sc * (temp_cell - 25 )
593
- results = sm . OLS ( endog = y , exog = x ). fit ( )
594
- I_L_ref = results . params [ 'x1' ]
586
+ coeff , _ , _ , _ = np . linalg . lstsq ( x , y , rcond = None )
587
+ I_L_ref = coeff [ 0 ]
595
588
return I_L_ref
596
589
597
590
598
591
def _fit_diode_ideality_factor_post_pvsyst_iec61853_sandia (
599
- sm , i_mp , v_mp , effective_irradiance , temp_cell , alpha_sc , I_L_ref ,
592
+ i_mp , v_mp , effective_irradiance , temp_cell , alpha_sc , I_L_ref ,
600
593
I_o_ref , R_sh_ref , R_sh_0 , R_sh_exp , R_s , cells_in_series , EgRef ):
601
594
602
595
Rsh = _pvsyst_Rsh (effective_irradiance , R_sh_ref , R_sh_0 , R_sh_exp )
@@ -620,10 +613,9 @@ def _fit_diode_ideality_factor_post_pvsyst_iec61853_sandia(
620
613
gamma_est = numerator / denominator
621
614
622
615
# Eq 22
623
- x = np .array ([temp_cell - 25 ]).T
624
- x = sm .add_constant (x )
616
+ x = np .array ([np .ones (len (i_mp )), temp_cell - 25 ]).T
625
617
y = gamma_est
626
618
627
- results = sm . OLS ( endog = y , exog = x ). fit ( )
628
- gamma_ref , mu_gamma = results . params
619
+ coeff , _ , _ , _ = np . linalg . lstsq ( x , y , rcond = None )
620
+ gamma_ref , mu_gamma = coeff
629
621
return gamma_ref , mu_gamma
0 commit comments