Skip to content

Commit 5f9bd7c

Browse files
committed
more sapm doc and pep8. now works with dict input
1 parent a50c8c6 commit 5f9bd7c

File tree

2 files changed

+83
-52
lines changed

2 files changed

+83
-52
lines changed

pvlib/pvsystem.py

Lines changed: 80 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -565,56 +565,68 @@ def _parse_raw_sam_df(csvdata):
565565

566566

567567

568-
def sapm(Module, Eb, Ediff, Tcell, AM, AOI):
568+
def sapm(module, poa_direct, poa_diffuse, temp_cell, airmass_absolute, aoi):
569569
'''
570570
The Sandia PV Array Performance Model (SAPM) generates 5 points on a PV
571571
module's I-V curve (Voc, Isc, Ix, Ixx, Vmp/Imp) according to
572572
SAND2004-3535. Assumes a reference cell temperature of 25 C.
573573
574574
Parameters
575575
----------
576-
Module : Series
577-
A DataFrame defining the SAPM performance parameters
576+
module : Series or dict
577+
A DataFrame defining the SAPM performance parameters.
578578
579-
Eb : Series
580-
The direct irradiance incident upon the module (suns). Any Ee<0
581-
are set to 0.
579+
poa_direct : Series
580+
The direct irradiance incident upon the module (W/m^2).
582581
583-
Ediff : Series
582+
poa_diffuse : Series
584583
The diffuse irradiance incident on module.
585584
586-
Tcell : Series
585+
temp_cell : Series
587586
The cell temperature (degrees C).
588587
589-
AM : Series
588+
airmass_absolute : Series
590589
Absolute airmass.
591590
592-
AOI : Series
591+
aoi : Series
593592
Angle of incidence.
594593
595594
Returns
596595
-------
597-
A DataFrame with the columns Isc, Imp, Ix, Ixx, Voc, Vmp, Pmp.
596+
A DataFrame with the columns:
597+
598+
* Isc : Short-circuit current (A)
599+
* Imp : Current at the maximum-power point (A)
600+
* Voc : Open-circuit voltage (V)
601+
* Vmp : Voltage at maximum-power point (V)
602+
* Pmp : Power at maximum-power point (W)
603+
* Ix : Current at module V = 0.5Voc, defines 4th point on I-V curve for modeling curve shape
604+
* Ixx : Current at module V = 0.5(Voc+Vmp), defines 5th point on I-V curve for modeling curve shape
598605
599606
Notes
600607
-----
601-
The coefficients from SAPM which are required in Module are:
602-
603-
================ ======================================================================================================================
604-
Module field Description
605-
================ ======================================================================================================================
606-
Module.c 1x8 vector with the C coefficients Module.c(1) = C0
607-
Module.Isc0 Short circuit current at reference condition (amps)
608-
Module.Imp0 Maximum power current at reference condition (amps)
609-
Module.AlphaIsc Short circuit current temperature coefficient at reference condition (1/C)
610-
Module.AlphaImp Maximum power current temperature coefficient at reference condition (1/C)
611-
Module.BetaVoc Open circuit voltage temperature coefficient at reference condition (V/C)
612-
Module.mBetaVoc Coefficient providing the irradiance dependence for the BetaVoc temperature coefficient at reference irradiance (V/C)
613-
Module.BetaVmp Maximum power voltage temperature coefficient at reference condition
614-
Module.mBetaVmp Coefficient providing the irradiance dependence for the BetaVmp temperature coefficient at reference irradiance (V/C)
615-
Module.n Empirically determined "diode factor" (dimensionless)
616-
Module.Ns Number of cells in series in a module's cell string(s)
617-
================ ======================================================================================================================
608+
The coefficients from SAPM which are required in ``module`` are:
609+
610+
======== ======================================================================================================================
611+
Key Description
612+
======== ======================================================================================================================
613+
A0-A4 The airmass coefficients used in calculating effective irradiance
614+
B0-B5 The angle of incidence coefficients used in calculating effective irradiance
615+
C0-C7 The empirically determined coefficients relating Imp, Vmp, Ix, and Ixx to effective irradiance
616+
Isco Short circuit current at reference condition (amps)
617+
Impo Maximum power current at reference condition (amps)
618+
Aisc Short circuit current temperature coefficient at reference condition (1/C)
619+
Aimp Maximum power current temperature coefficient at reference condition (1/C)
620+
Bvoc Open circuit voltage temperature coefficient at reference condition (V/C)
621+
Mbvoc Coefficient providing the irradiance dependence for the BetaVoc temperature coefficient at reference irradiance (V/C)
622+
Bvmpo Maximum power voltage temperature coefficient at reference condition
623+
Mbvmp Coefficient providing the irradiance dependence for the BetaVmp temperature coefficient at reference irradiance (V/C)
624+
N Empirically determined "diode factor" (dimensionless)
625+
#Series Number of cells in series in a module's cell string(s)
626+
IXO Ix at reference conditions
627+
IXXO Ixx at reference conditions
628+
FD Fraction of diffuse irradiance used by module
629+
======== ======================================================================================================================
618630
619631
References
620632
----------
@@ -628,40 +640,56 @@ def sapm(Module, Eb, Ediff, Tcell, AM, AOI):
628640
'''
629641

630642
T0 = 25
631-
q = 1.60218e-19
632-
k = 1.38066e-23
643+
q = 1.60218e-19 # Elementary charge in units of coulombs
644+
kb = 1.38066e-23 # Boltzmann's constant in units of J/K
633645
E0 = 1000
634646

635-
AMcoeff = [Module['A4'], Module['A3'], Module['A2'], Module['A1'],
636-
Module['A0']]
637-
AOIcoeff = [Module['B5'], Module['B4'], Module['B3'], Module['B2'],
638-
Module['B1'], Module['B0']]
647+
am_coeff = [module['A4'], module['A3'], module['A2'], module['A1'],
648+
module['A0']]
649+
aoi_coeff = [module['B5'], module['B4'], module['B3'], module['B2'],
650+
module['B1'], module['B0']]
639651

640-
F1 = np.polyval(AMcoeff, AM)
641-
F2 = np.polyval(AOIcoeff, AOI)
642-
Ee= F1*((Eb*F2+Module['FD']*Ediff)/E0)
643-
Ee.fillna(0)
652+
F1 = np.polyval(am_coeff, airmass_absolute)
653+
F2 = np.polyval(aoi_coeff, aoi)
654+
655+
# Ee is the "effective irradiance"
656+
Ee = F1 * ( (poa_direct*F2 + module['FD']*poa_diffuse) / E0 )
657+
Ee.fillna(0, inplace=True)
644658
Ee[Ee < 0] = 0
645659

646-
Filt = Ee[Ee >= 0.001]
660+
Bvmpo = module['Bvmpo'] + module['Mbvmp']*(1 - Ee)
661+
Bvoco = module['Bvoco'] + module['Mbvoc']*(1 - Ee)
662+
delta = module['N'] * kb * (temp_cell + 273.15) / q
647663

648-
Isc = Module.ix['Isco']*(Ee)*((1 + Module.ix['Aisc']*((Tcell - T0))))
664+
dfout = pd.DataFrame(index=Ee.index)
649665

650-
DFOut = pd.DataFrame({'Isc':Isc})
666+
dfout['Isc'] = (
667+
module['Isco'] * Ee * (1 + module['Aisc']*(temp_cell - T0)) )
651668

652-
DFOut['Imp'] = Module.ix['Impo']*((Module.ix['C0']*(Ee) + Module.ix['C1'] * (Ee ** 2)))*((1 + Module.ix['Aimp']*((Tcell - T0))))
653-
Bvoco = Module.ix['Bvoco'] + Module.ix['Mbvoc']*((1 - Ee))
654-
delta = Module.ix['N']*(k)*((Tcell + 273.15)) / q
655-
DFOut['Voc'] = (Module.ix['Voco'] + Module.ix['#Series']*(delta)*(np.log(Ee)) + Bvoco*((Tcell - T0)))
656-
Bvmpo = Module.ix['Bvmpo'] + Module.ix['Mbvmp']*((1 - Ee))
657-
DFOut['Vmp'] = (Module.ix['Vmpo'] + Module.ix['C2']*(Module.ix['#Series'])*(delta)*(np.log(Ee)) + Module.ix['C3']*(Module.ix['#Series'])*((delta*(np.log(Ee))) ** 2) + Bvmpo*((Tcell - T0)))
658-
DFOut['Vmp'][DFOut['Vmp'] < 0] = 0
659-
DFOut['Pmp'] = DFOut.Imp*DFOut.Vmp
660-
DFOut['Ix'] = Module.ix['IXO'] * (Module.ix['C4']*(Ee) + Module.ix['C5']*((Ee) ** 2))*((1 + Module.ix['Aisc']*((Tcell - T0))))
661-
DFOut['Ixx'] = Module.ix['IXXO'] * (Module.ix['C6']*(Ee) + Module.ix['C7']*((Ee) ** 2))*((1 + Module.ix['Aisc']*((Tcell - T0))))
669+
dfout['Imp'] = ( module['Impo'] *
670+
(module['C0']*Ee + module['C1']*(Ee**2)) *
671+
(1 + module['Aimp']*(temp_cell - T0)) )
662672

663-
return DFOut
673+
dfout['Voc'] = ( module['Voco'] +
674+
module['#Series']*delta*np.log(Ee) + Bvoco*(temp_cell - T0) )
675+
676+
dfout['Vmp'] = ( module['Vmpo'] +
677+
module['C2']*module['#Series']*delta*np.log(Ee) +
678+
module['C3']*module['#Series']*((delta*np.log(Ee)) ** 2) +
679+
Bvmpo*(temp_cell - T0) ).clip_lower(0)
680+
681+
dfout['Pmp'] = dfout['Imp'] * dfout['Vmp']
682+
683+
dfout['Ix'] = ( module['IXO'] *
684+
(module['C4']*Ee + module['C5']*(Ee**2)) *
685+
(1 + module['Aisc']*(temp_cell - T0)) )
686+
687+
# the Ixx calculation in King 2004 has a typo (mixes up Aisc and Aimp)
688+
dfout['Ixx'] = ( module['IXXO'] *
689+
(module['C6']*Ee + module['C7']*(Ee**2)) *
690+
(1 + module['Aisc']*(temp_cell - T0)) )
664691

692+
return dfout
665693

666694

667695
def sapm_celltemp(irrad, wind, temp, model='open_rack_cell_glassback'):

pvlib/test/test_pvsystem.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def test_sapm():
111111

112112
sapm = pvsystem.sapm(module, irrad_data.DNI, irrad_data.DHI, 25, am, aoi)
113113

114+
sapm = pvsystem.sapm(module.to_dict(), irrad_data.DNI,
115+
irrad_data.DHI, 25, am, aoi)
116+
114117

115118

116119
def test_calcparams_desoto():

0 commit comments

Comments
 (0)