Skip to content

Commit 48e4df9

Browse files
committed
add option to provide init guess
1 parent a6995c3 commit 48e4df9

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

pvlib/ivtools/sdm.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ def fit_cec_sam(celltype, v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc,
120120

121121
def fit_desoto(v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc, cells_in_series,
122122
EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000,
123-
root_kwargs={}):
123+
init_guess=None, root_kwargs={}):
124124
"""
125125
Calculates the parameters for the De Soto single diode model.
126126
127-
This procedure (described in [1]_) has the advantage of
128-
using common specifications given by manufacturers in the
127+
This procedure (described in [1]_) fits the De Soto model [2]_ using
128+
common specifications given by manufacturers in the
129129
datasheets of PV modules.
130130
131-
The solution is found using the scipy.optimize.root() function,
132-
with the corresponding default solver method 'hybr'.
133-
No restriction is put on the fit variables, i.e. series
131+
The solution is found using :py:func:`scipy.optimize.root`,
132+
with the default solver method 'hybr'.
133+
No restriction is put on the fit variables, e.g. series
134134
or shunt resistance could go negative. Nevertheless, if it happens,
135-
check carefully the inputs and their units; alpha_sc and beta_voc are
136-
often given in %/K in manufacturers datasheets and should be given
137-
in A/K and V/K here.
135+
check carefully the inputs and their units. For example, ``alpha_sc`` and
136+
``beta_voc`` are often given in %/K in manufacturers datasheets but should
137+
be given in A/K and V/K here.
138138
139139
The parameters returned by this function can be used by
140-
:py:func:`pvlib.pvsystem.calcparams_desoto` to calculate the values at
141-
different irradiance and cell temperature.
140+
:py:func:`pvlib.pvsystem.calcparams_desoto` to calculate single diode
141+
equation parameters at different irradiance and cell temperature.
142142
143143
Parameters
144144
----------
@@ -166,6 +166,9 @@ def fit_desoto(v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc, cells_in_series,
166166
Reference temperature condition [C]
167167
irrad_ref: float, default 1000
168168
Reference irradiance condition [W/m2]
169+
init_guess: dict, optional
170+
Initial values for optimization, must have keys `'Rsh_0'`, `'a_0'`,
171+
`'IL_0'`, `'Io_0'`, `'Rs_0'`.
169172
root_kwargs : dictionary, optional
170173
Dictionary of arguments to pass onto scipy.optimize.root()
171174
@@ -203,22 +206,33 @@ def fit_desoto(v_mp, i_mp, v_oc, i_sc, alpha_sc, beta_voc, cells_in_series,
203206
204207
References
205208
----------
206-
.. [1] W. De Soto et al., "Improvement and validation of a model for
209+
.. [1] J. A Duffie, W. A Beckman, "Solar Engineering of Thermal Processes",
210+
4th ed., Wiley, 2013. :doi:`10.1002/9781118671603`
211+
.. [2] W. De Soto et al., "Improvement and validation of a model for
207212
photovoltaic array performance", Solar Energy, vol 80, pp. 78-88,
208213
2006. :doi:`10.1016/j.solener.2005.06.010`
214+
209215
"""
210216

211217
# Constants
212218
k = constants.value('Boltzmann constant in eV/K') # in eV/K
213219
Tref = temp_ref + 273.15 # [K]
214220

215-
# initial guesses of variables for computing convergence:
216-
# Values are taken from [2], p753
217-
Rsh_0 = 100.0
218-
a_0 = 1.5*k*Tref*cells_in_series
219-
IL_0 = i_sc
220-
Io_0 = i_sc * np.exp(-v_oc/a_0)
221-
Rs_0 = (a_0*np.log1p((IL_0-i_mp)/Io_0) - v_mp)/i_mp
221+
if init_guess is None:
222+
# initial guesses of variables for computing convergence:
223+
# Values are taken from [2], p753
224+
IL_0 = i_sc
225+
a_0 = 1.5*k*Tref*cells_in_series
226+
Io_0 = i_sc * np.exp(-v_oc/a_0)
227+
Rs_0 = (a_0*np.log1p((IL_0-i_mp)/Io_0) - v_mp)/i_mp
228+
Rsh_0 = 100.0
229+
else:
230+
IL_0 = init_guess['IL_0']
231+
Io_0 = init_guess['Io_0']
232+
Rs_0 = init_guess['Rs_0']
233+
Rsh_0 = init_guess['Rsh_0']
234+
a_0 = init_guess['a_0']
235+
222236
# params_i : initial values vector
223237
params_i = np.array([IL_0, Io_0, Rs_0, Rsh_0, a_0])
224238

pvlib/tests/ivtools/test_sdm.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ def test_fit_desoto():
8080
rtol=1e-4)
8181

8282

83+
def test_fit_desoto_init_guess():
84+
init_guess = {'IL_0': 9.43, 'Io_0': 6.04e-7, 'Rs_0': 0.155, 'Rsh_0': 100.,
85+
'a_0': 2.312}
86+
result, _ = sdm.fit_desoto(v_mp=31.0, i_mp=8.71, v_oc=38.3, i_sc=9.43,
87+
alpha_sc=0.005658, beta_voc=-0.13788,
88+
cells_in_series=60, init_guess=init_guess)
89+
result_expected = {'I_L_ref': 9.45232,
90+
'I_o_ref': 3.22460e-10,
91+
'R_s': 0.297814,
92+
'R_sh_ref': 125.798,
93+
'a_ref': 1.59128,
94+
'alpha_sc': 0.005658,
95+
'EgRef': 1.121,
96+
'dEgdT': -0.0002677,
97+
'irrad_ref': 1000,
98+
'temp_ref': 25}
99+
assert np.allclose(pd.Series(result), pd.Series(result_expected),
100+
rtol=1e-4)
101+
102+
83103
def test_fit_desoto_failure():
84104
with pytest.raises(RuntimeError) as exc:
85105
sdm.fit_desoto(v_mp=31.0, i_mp=8.71, v_oc=38.3, i_sc=9.43,

0 commit comments

Comments
 (0)