Skip to content

Commit 928207e

Browse files
committed
Refactor Huld model tests for EU JRC coefficients
- Updated the test for the Huld model to use non-reference values for irradiance and temperature. - Enhanced the test to verify that results differ for all supported cell types when using EU JRC coefficients. - Added checks to ensure all cell types are supported and that a KeyError is raised for invalid cell types. (cherry picked from commit 7c0feba)
1 parent 4b66810 commit 928207e

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

tests/test_pvarray.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,18 @@ def test_huld():
7474
def test_huld_eu_jrc():
7575
"""Test the EU JRC updated coefficients for the Huld model."""
7676
pdc0 = 100
77-
78-
# Test that EU JRC coefficients give different results than original
79-
res_orig = pvarray.huld(1000, 25, pdc0, cell_type='cSi')
80-
res_eu_jrc = pvarray.huld(1000, 25, pdc0, cell_type='cSi', use_eu_jrc=True)
81-
assert not np.isclose(res_orig, res_eu_jrc)
82-
83-
# Test that coefficients are properly scaled by pdc0
84-
k_orig = pvarray._infer_k_huld('cSi', pdc0)
85-
k_eu_jrc = pvarray._infer_k_huld_eu_jrc('cSi', pdc0)
86-
assert len(k_orig) == len(k_eu_jrc) == 6
87-
assert all(np.isclose(k1/pdc0, k2/pdc0) for k1, k2 in zip(k_orig, k_eu_jrc))
88-
89-
# Test that all cell types are supported
90-
for cell_type in ['csi', 'cis', 'cdte']:
91-
k = pvarray._infer_k_huld_eu_jrc(cell_type, pdc0)
92-
assert len(k) == 6
93-
assert all(isinstance(x, float) for x in k)
94-
95-
# Test invalid cell type
96-
with pytest.raises(KeyError):
97-
pvarray._infer_k_huld_eu_jrc('invalid', pdc0)
77+
# Use non-reference values so coefficients affect the result
78+
eff_irr = 800 # W/m^2 (not 1000)
79+
temp_mod = 35 # deg C (not 25)
80+
# Test that EU JRC coefficients give different results than original for all cell types
81+
for cell_type in ['cSi', 'CIS', 'CdTe']:
82+
res_orig = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type)
83+
res_eu_jrc = pvarray.huld(eff_irr, temp_mod, pdc0, cell_type=cell_type, use_eu_jrc=True)
84+
assert not np.isclose(res_orig, res_eu_jrc), f"Results should differ for {cell_type}: {res_orig} vs {res_eu_jrc}"
85+
# Also check that all cell types are supported and error is raised for invalid type
86+
try:
87+
pvarray.huld(eff_irr, temp_mod, pdc0, cell_type='invalid', use_eu_jrc=True)
88+
except KeyError:
89+
pass
90+
else:
91+
assert False, "Expected KeyError for invalid cell_type"

0 commit comments

Comments
 (0)