Skip to content

Commit 241c272

Browse files
committed
restructure lookup and test
1 parent 98846e6 commit 241c272

2 files changed

Lines changed: 75 additions & 76 deletions

File tree

pvlib/pvarray.py

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -225,65 +225,54 @@ def adr_wrapper(xdata, *params):
225225
return popt
226226

227227

228-
def _infer_k_huld(cell_type, pdc0):
229-
# from PVGIS documentation, "PVGIS data sources & calculation methods",
230-
# Section 5.2.3, accessed 12/22/2023
231-
# The parameters in PVGIS' documentation are for a version of Huld's
232-
# equation that has factored Pdc0 out of the polynomial:
233-
# P = G/1000 * Pdc0 * (1 + k1 log(Geff) + ...) so these parameters are
234-
# multiplied by pdc0
235-
huld_params = {'csi': (-0.017237, -0.040465, -0.004702, 0.000149,
236-
0.000170, 0.000005),
237-
'cis': (-0.005554, -0.038724, -0.003723, -0.000905,
238-
-0.001256, 0.000001),
239-
'cdte': (-0.046689, -0.072844, -0.002262, 0.000276,
240-
0.000159, -0.000006)}
241-
k = tuple([x*pdc0 for x in huld_params[cell_type.lower()]])
242-
return k
243-
244-
245-
def _infer_k_huld_eu_jrc(cell_type, pdc0):
246-
"""
228+
def _infer_k_huld(cell_type, pdc0, k_version):
229+
r"""
247230
Get the EU JRC updated coefficients for the Huld model.
231+
248232
Parameters
249233
----------
250234
cell_type : str
251235
Must be one of 'csi', 'cis', or 'cdte'
252236
pdc0 : numeric
253237
Power of the modules at reference conditions [W]
238+
k_version : str
239+
Either '2011' or '2025'.
240+
254241
Returns
255242
-------
256243
tuple
257244
The six coefficients (k1-k6) for the Huld model, scaled by pdc0
258-
Notes
259-
-----
260-
These coefficients are from the EU JRC paper [1]_. The coefficients are
261-
for the version of Huld's equation that has factored Pdc0 out of the
262-
polynomial, so they are multiplied by pdc0 before being returned.
263-
References
264-
----------
265-
.. [1] EU JRC paper, "Updated coefficients for the Huld model",
266-
https://doi.org/10.1002/pip.3926
267245
"""
268-
# Updated coefficients from EU JRC paper
269-
huld_params = {'csi': (-0.017162, -0.040289, -0.004681, 0.000148,
270-
0.000169, 0.000005),
271-
'cis': (-0.005521, -0.038576, -0.003711, -0.000901,
272-
-0.001251, 0.000001),
273-
'cdte': (-0.046477, -0.072509, -0.002252, 0.000275,
274-
0.000158, -0.000006)}
246+
# from PVGIS documentation, "PVGIS data sources & calculation methods",
247+
# Section 5.2.3, accessed 12/22/2023
248+
# The parameters in PVGIS' documentation are for a version of Huld's
249+
# equation that has factored Pdc0 out of the polynomial:
250+
# P = G/1000 * Pdc0 * (1 + k1 log(Geff) + ...) so these parameters are
251+
# multiplied by pdc0
252+
if k_version=='2011':
253+
huld_params = {'csi': (-0.017237, -0.040465, -0.004702, 0.000149,
254+
0.000170, 0.000005),
255+
'cis': (-0.005554, -0.038724, -0.003723, -0.000905,
256+
-0.001256, 0.000001),
257+
'cdte': (-0.046689, -0.072844, -0.002262, 0.000276,
258+
0.000159, -0.000006)}
259+
elif k_version=='2025':
260+
# Updated coefficients from EU JRC paper
261+
huld_params = {'csi': (-0.017162, -0.040289, -0.004681, 0.000148,
262+
0.000169, 0.000005),
263+
'cis': (-0.005521, -0.038576, -0.003711, -0.000901,
264+
-0.001251, 0.000001),
265+
'cdte': (-0.046477, -0.072509, -0.002252, 0.000275,
266+
0.000158, -0.000006)}
267+
else:
268+
raise ValueError(f'Invalid k_version={k_version}: must be either '
269+
'"2011" or "2025"')
275270
k = tuple([x*pdc0 for x in huld_params[cell_type.lower()]])
276271
return k
277272

278273

279-
def huld(
280-
effective_irradiance,
281-
temp_mod,
282-
pdc0,
283-
k=None,
284-
cell_type=None,
285-
use_eu_jrc=False
286-
):
274+
def huld(effective_irradiance, temp_mod, pdc0, k=None, cell_type=None,
275+
k_version=None):
287276
r"""
288277
Power (DC) using the Huld model.
289278
@@ -315,9 +304,10 @@ def huld(
315304
cell_type : str, optional
316305
If provided, must be one of ``'cSi'``, ``'CIS'``, or ``'CdTe'``.
317306
Used to look up default values for ``k`` if ``k`` is not specified.
318-
use_eu_jrc : bool, default False
319-
If True, use the updated coefficients from the EU JRC paper [2]_.
320-
Only used if ``k`` is not provided and ``cell_type`` is specified.
307+
k_version : str, optional
308+
Either `'2011'` (default) or `'2025'`. Used to select default values
309+
for ``k`` if ``k`` is not specified. If `'2011'`, values from [1]_
310+
are used; if `'2025'` values are from [2]_.
321311
322312
Returns
323313
-------
@@ -372,19 +362,21 @@ def huld(
372362
373363
References
374364
----------
375-
.. [1] T. Huld, G. Friesen, A. Skoczek, R. Kenny, T. Sample, M. Field,
376-
E. Dunlop. A power-rating model for crystalline silicon PV modules.
377-
Solar Energy Materials and Solar Cells 95, (2011), pp. 3359-3369.
378-
:doi:`10.1016/j.solmat.2011.07.026`.
379-
.. [2] EU JRC paper, "Updated coefficients for the Huld model",
380-
https://doi.org/10.1002/pip.3926
365+
.. [1] T. Huld, G. Friesen, A. Skoczek, R. Kenny, T. Sample, M. Field, and
366+
E. Dunlop, "A power-rating model for crystalline silicon PV
367+
modules," Solar Energy Materials and Solar Cells 95, (2011),
368+
pp. 3359-3369. :doi:`10.1016/j.solmat.2011.07.026`.
369+
.. [2] A. Chatzipanagi, N. Taylor, I. Suarez, A. Martinez, T. Lyubenova,
370+
and E. Dunlop, "An Updated Simplified Energy Yield Model for Recent
371+
Photovoltaic Module Technologies,"
372+
Progress in Photovoltaics: Research and Applications 33,
373+
no. 8 (2025): 905–917, :doi:`10.1002/pip.3926`.
381374
"""
382375
if k is None:
383376
if cell_type is not None:
384-
if use_eu_jrc:
385-
k = _infer_k_huld_eu_jrc(cell_type, pdc0)
386-
else:
387-
k = _infer_k_huld(cell_type, pdc0)
377+
if k_version is None:
378+
k_version = '2011'
379+
k = _infer_k_huld(cell_type, pdc0, k_version)
388380
else:
389381
raise ValueError('Either k or cell_type must be specified')
390382

tests/test_pvarray.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,37 @@ def test_huld():
7171
res = pvarray.huld(1000, 25, 100)
7272

7373

74-
def test_huld_eu_jrc():
75-
"""Test the EU JRC updated coefficients for the Huld model."""
74+
def test_huld_params():
75+
"""Test Huld with built-in coefficients."""
7676
pdc0 = 100
7777
# Use non-reference values so coefficients affect the result
7878
eff_irr = 800 # W/m^2 (not 1000)
7979
temp_mod = 35 # deg C (not 25)
80-
# Test that EU JRC coefficients give different results
81-
# than original for all cell types
82-
for cell_type in ['cSi', 'CIS', 'CdTe']:
83-
res_orig = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type)
84-
res_eu_jrc = pvarray.huld(
85-
eff_irr, temp_mod, pdc0, cell_type=cell_type, use_eu_jrc=True
86-
)
87-
assert not np.isclose(res_orig, res_eu_jrc), (
88-
f"Results should differ for {cell_type}: "
89-
f"{res_orig} vs {res_eu_jrc}"
80+
# calculated by C. Hansen using Excel, 2025
81+
expected = {
82+
'2011': {
83+
'csi': 79.964051,
84+
'cis': 79.970860,
85+
'cdte': 79.986428
86+
},
87+
'2025': {
88+
'csi': 79.964214,
89+
'cis': 79.970951,
90+
'cdte': 79.986485
91+
}
92+
}
93+
# Test with 2011 coefficients for all cell types
94+
for yr in expected:
95+
for cell_type in expected[yr]:
96+
result = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type,
97+
k_version=yr)
98+
assert np.isclose(result, expected[yr][cell_type])
99+
# Check errors for incorrect cell_type and incorrect k_version
100+
with pytest.raises(KeyError):
101+
pvarray.huld(
102+
eff_irr, temp_mod, pdc0, cell_type='invalid', k_version='2011'
90103
)
91-
# Also check that all cell types are supported
92-
# and error is raised for invalid type
93-
try:
104+
with pytest.raises(ValueError, match='Invalid k_version="2021"'):
94105
pvarray.huld(
95-
eff_irr, temp_mod, pdc0, cell_type='invalid', use_eu_jrc=True
106+
eff_irr, temp_mod, pdc0, cell_type='csi', k_version='2021'
96107
)
97-
except KeyError:
98-
pass
99-
else:
100-
assert False, "Expected KeyError for invalid cell_type"

0 commit comments

Comments
 (0)