Skip to content

Commit 7e34a32

Browse files
authored
Extract private functions for each PVsyst SDM auxiliary equation in calcparams_pvsyst (#2428)
* private functions for PVsyst SDM auxiliary equations * fix typo
1 parent 56911ee commit 7e34a32

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

pvlib/ivtools/sdm/_fit_desoto_pvsyst_sandia.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pvlib.pvsystem import singlediode, v_from_i
1111
from pvlib.ivtools.utils import rectify_iv_curve, _numdiff
12+
from pvlib.pvsystem import _pvsyst_Rsh
1213

1314

1415
def _initial_iv_params(ivcurves, ee, voc, isc, rsh, nnsvth):
@@ -167,7 +168,10 @@ def _extract_sdm_params(ee, tc, iph, io, rs, rsh, n, u, specs, const,
167168
# Find parameters for Rsh equation
168169

169170
def fun_rsh(x, rshexp, ee, e0, rsh):
170-
tf = np.log10(_rsh_pvsyst(x, R_sh_exp, ee, e0)) - np.log10(rsh)
171+
tf = (
172+
np.log10(_pvsyst_Rsh(ee, x[1], x[0], R_sh_exp, e0))
173+
- np.log10(rsh)
174+
)
171175
return tf
172176

173177
x0 = np.array([grsh0, grshref])
@@ -293,20 +297,6 @@ def _update_io(voc, iph, io, rs, rsh, nnsvth):
293297
return new_io
294298

295299

296-
def _rsh_pvsyst(x, rshexp, g, go):
297-
# computes rsh for PVsyst model where the parameters are in vector xL
298-
# x[0] = Rsh0
299-
# x[1] = Rshref
300-
301-
rsho = x[0]
302-
rshref = x[1]
303-
304-
rshb = np.maximum(
305-
(rshref - rsho * np.exp(-rshexp)) / (1. - np.exp(-rshexp)), 0.)
306-
rsh = rshb + (rsho - rshb) * np.exp(-rshexp * g / go)
307-
return rsh
308-
309-
310300
def _filter_params(ee, isc, io, rs, rsh):
311301
# Function _filter_params identifies bad parameter sets. A bad set contains
312302
# Nan, non-positive or imaginary values for parameters; Rs > Rsh; or data

pvlib/pvsystem.py

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,31 +1948,17 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
19481948
19491949
'''
19501950

1951-
# Boltzmann constant in J/K
1952-
k = constants.k
1951+
gamma = _pvsyst_gamma(temp_cell, gamma_ref, mu_gamma, temp_ref)
19531952

1954-
# elementary charge in coulomb
1955-
q = constants.e
1953+
nNsVth = _pvsyst_nNsVth(temp_cell, gamma, cells_in_series)
19561954

1957-
# reference temperature
1958-
Tref_K = temp_ref + 273.15
1959-
Tcell_K = temp_cell + 273.15
1960-
1961-
gamma = gamma_ref + mu_gamma * (Tcell_K - Tref_K)
1962-
nNsVth = gamma * k / q * cells_in_series * Tcell_K
1963-
1964-
IL = effective_irradiance / irrad_ref * \
1965-
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
1955+
IL = _pvsyst_IL(effective_irradiance, temp_cell, I_L_ref, alpha_sc,
1956+
irrad_ref, temp_ref)
19661957

1967-
I0 = I_o_ref * ((Tcell_K / Tref_K) ** 3) * \
1968-
(np.exp((q * EgRef) / (k * gamma) * (1 / Tref_K - 1 / Tcell_K)))
1958+
I0 = _pvsyst_Io(temp_cell, gamma, I_o_ref, EgRef, temp_ref)
19691959

1970-
Rsh_tmp = \
1971-
(R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
1972-
Rsh_base = np.maximum(0.0, Rsh_tmp)
1973-
1974-
Rsh = Rsh_base + (R_sh_0 - Rsh_base) * \
1975-
np.exp(-R_sh_exp * effective_irradiance / irrad_ref)
1960+
Rsh = _pvsyst_Rsh(effective_irradiance, R_sh_ref, R_sh_0, R_sh_exp,
1961+
irrad_ref)
19761962

19771963
Rs = R_s
19781964

@@ -1992,6 +1978,54 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
19921978
return tuple(pd.Series(a, index=index).rename(None) for a in out)
19931979

19941980

1981+
def _pvsyst_Rsh(effective_irradiance, R_sh_ref, R_sh_0, R_sh_exp=5.5,
1982+
irrad_ref=1000):
1983+
Rsh_tmp = \
1984+
(R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
1985+
Rsh_base = np.maximum(0.0, Rsh_tmp)
1986+
1987+
Rsh = Rsh_base + (R_sh_0 - Rsh_base) * \
1988+
np.exp(-R_sh_exp * effective_irradiance / irrad_ref)
1989+
1990+
return Rsh
1991+
1992+
1993+
def _pvsyst_IL(effective_irradiance, temp_cell, I_L_ref, alpha_sc,
1994+
irrad_ref=1000, temp_ref=25):
1995+
Tref_K = temp_ref + 273.15
1996+
Tcell_K = temp_cell + 273.15
1997+
IL = effective_irradiance / irrad_ref * \
1998+
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
1999+
return IL
2000+
2001+
2002+
def _pvsyst_Io(temp_cell, gamma, I_o_ref, EgRef, temp_ref=25):
2003+
k = constants.k # Boltzmann constant in J/K
2004+
q = constants.e # elementary charge in coulomb
2005+
2006+
Tref_K = temp_ref + 273.15
2007+
Tcell_K = temp_cell + 273.15
2008+
2009+
Io = I_o_ref * ((Tcell_K / Tref_K) ** 3) * \
2010+
(np.exp((q * EgRef) / (k * gamma) * (1 / Tref_K - 1 / Tcell_K)))
2011+
2012+
return Io
2013+
2014+
2015+
def _pvsyst_gamma(temp_cell, gamma_ref, mu_gamma, temp_ref=25):
2016+
gamma = gamma_ref + mu_gamma * (temp_cell - temp_ref)
2017+
return gamma
2018+
2019+
2020+
def _pvsyst_nNsVth(temp_cell, gamma, cells_in_series):
2021+
k = constants.k # Boltzmann constant in J/K
2022+
q = constants.e # elementary charge in coulomb
2023+
Tcell_K = temp_cell + 273.15
2024+
2025+
nNsVth = gamma * k / q * cells_in_series * Tcell_K
2026+
return nNsVth
2027+
2028+
19952029
def retrieve_sam(name=None, path=None):
19962030
"""
19972031
Retrieve latest module and inverter info from a file bundled with pvlib,

0 commit comments

Comments
 (0)