Skip to content

Fix2461 #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix2461 #2486

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions pvlib/pvarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
the reference conditions. [unitless]

k_d : numeric, negative
Dark irradiance or diode coefficient which influences the voltage
"Dark irradiance" or diode coefficient which influences the voltage
increase with irradiance. [unitless]

tc_d : numeric
Expand Down Expand Up @@ -242,7 +242,45 @@
return k


def huld(effective_irradiance, temp_mod, pdc0, k=None, cell_type=None):
def _infer_k_huld_eu_jrc(cell_type, pdc0):
"""
Get the EU JRC updated coefficients for the Huld model.

Check failure on line 248 in pvlib/pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

W293 blank line contains whitespace
Parameters
----------
cell_type : str
Must be one of 'csi', 'cis', or 'cdte'
pdc0 : numeric
Power of the modules at reference conditions [W]

Check failure on line 255 in pvlib/pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

W293 blank line contains whitespace
Returns
-------
tuple
The six coefficients (k1-k6) for the Huld model, scaled by pdc0

Check failure on line 260 in pvlib/pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

W293 blank line contains whitespace
Notes
-----
These coefficients are from the EU JRC paper [1]_. The coefficients are
for the version of Huld's equation that has factored Pdc0 out of the
polynomial, so they are multiplied by pdc0 before being returned.

Check failure on line 266 in pvlib/pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

W293 blank line contains whitespace
References
----------
.. [1] EU JRC paper, "Updated coefficients for the Huld model",
https://doi.org/10.1002/pip.3926
"""
# Updated coefficients from EU JRC paper
huld_params = {'csi': (-0.017162, -0.040289, -0.004681, 0.000148,
0.000169, 0.000005),
'cis': (-0.005521, -0.038576, -0.003711, -0.000901,
-0.001251, 0.000001),
'cdte': (-0.046477, -0.072509, -0.002252, 0.000275,
0.000158, -0.000006)}
k = tuple([x*pdc0 for x in huld_params[cell_type.lower()]])
return k


def huld(effective_irradiance, temp_mod, pdc0, k=None, cell_type=None, use_eu_jrc=False):

Check failure on line 283 in pvlib/pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (89 > 79 characters)
r"""
Power (DC) using the Huld model.

Expand Down Expand Up @@ -274,6 +312,9 @@
cell_type : str, optional
If provided, must be one of ``'cSi'``, ``'CIS'``, or ``'CdTe'``.
Used to look up default values for ``k`` if ``k`` is not specified.
use_eu_jrc : bool, default False
If True, use the updated coefficients from the EU JRC paper [2]_.
Only used if ``k`` is not provided and ``cell_type`` is specified.

Returns
-------
Expand Down Expand Up @@ -332,10 +373,15 @@
E. Dunlop. A power-rating model for crystalline silicon PV modules.
Solar Energy Materials and Solar Cells 95, (2011), pp. 3359-3369.
:doi:`10.1016/j.solmat.2011.07.026`.
.. [2] EU JRC paper, "Updated coefficients for the Huld model",
https://doi.org/10.1002/pip.3926
Comment on lines +376 to +377
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you didn't change this to fit the IEEE citation format nor the :doi: directive (see the citation just above).

I recommend you to read https://pvlib-python.readthedocs.io/en/latest/contributing/style_guide.html

"""
if k is None:
if cell_type is not None:
k = _infer_k_huld(cell_type, pdc0)
if use_eu_jrc:
k = _infer_k_huld_eu_jrc(cell_type, pdc0)
else:
k = _infer_k_huld(cell_type, pdc0)
else:
raise ValueError('Either k or cell_type must be specified')

Expand Down
20 changes: 20 additions & 0 deletions tests/test_pvarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,23 @@
with pytest.raises(ValueError,
match='Either k or cell_type must be specified'):
res = pvarray.huld(1000, 25, 100)


def test_huld_eu_jrc():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check for some specific values, up to 4-5 decimals? It would be better if you calculate them outside of your Python implementation.

"""Test the EU JRC updated coefficients for the Huld model."""
pdc0 = 100
# Use non-reference values so coefficients affect the result
eff_irr = 800 # W/m^2 (not 1000)
temp_mod = 35 # deg C (not 25)
# Test that EU JRC coefficients give different results than original for all cell types

Check failure on line 80 in tests/test_pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (91 > 79 characters)
for cell_type in ['cSi', 'CIS', 'CdTe']:
res_orig = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type)
res_eu_jrc = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type, use_eu_jrc=True)

Check failure on line 83 in tests/test_pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (96 > 79 characters)
assert not np.isclose(res_orig, res_eu_jrc), f"Results should differ for {cell_type}: {res_orig} vs {res_eu_jrc}"

Check failure on line 84 in tests/test_pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (121 > 79 characters)
# Also check that all cell types are supported and error is raised for invalid type

Check failure on line 85 in tests/test_pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (87 > 79 characters)
try:
pvarray.huld(eff_irr, temp_mod, pdc0, cell_type='invalid', use_eu_jrc=True)

Check failure on line 87 in tests/test_pvarray.py

View workflow job for this annotation

GitHub Actions / flake8-linter

E501 line too long (83 > 79 characters)
except KeyError:
pass
else:
assert False, "Expected KeyError for invalid cell_type"

Check warning on line 91 in tests/test_pvarray.py

View check run for this annotation

Codecov / codecov/patch

tests/test_pvarray.py#L91

Added line #L91 was not covered by tests
Loading