-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathtest_pvarray.py
87 lines (71 loc) · 3.27 KB
/
test_pvarray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy as np
import pandas as pd
from numpy.testing import assert_allclose
from .conftest import assert_series_equal
import pytest
from pvlib.tests.conftest import requires_statsmodels
from pvlib import pvarray
def test_pvefficiency_adr():
g = [1000, 200, 1000, 200, 1000, 200, 0.0, np.nan]
t = [25, 25, 50, 50, 75, 75, 25, 25]
params = [1.0, -6.651460, 0.018736, 0.070679, 0.054170]
# the expected values were calculated using the new function itself
# hence this test is primarily a regression test
eta = [1.0, 0.949125, 0.928148, 0.876472, 0.855759, 0.803281, 0.0, np.nan]
result = pvarray.pvefficiency_adr(g, t, *params)
assert_allclose(result, eta, atol=1e-6)
def test_fit_pvefficiency_adr():
g = [1000, 200, 1000, 200, 1000, 200]
t = [25, 25, 50, 50, 75, 75]
eta = [1.0, 0.949125, 0.928148, 0.876472, 0.855759, 0.803281]
# the expected values were calculated using the new function itself
# hence this test is primarily a regression test
params = [1.0, -6.651460, 0.018736, 0.070679, 0.054170]
result = pvarray.fit_pvefficiency_adr(g, t, eta, dict_output=False)
# the fitted parameters vary somewhat by platform during the testing
# so the tolerance is higher on the parameters than on the efficiencies
# in the other tests
assert_allclose(result, params, rtol=1e-3)
result = pvarray.fit_pvefficiency_adr(g, t, eta, dict_output=True)
assert 'k_a' in result
def test_pvefficiency_adr_round_trip():
g = [1000, 200, 1000, 200, 1000, 200]
t = [25, 25, 50, 50, 75, 75]
eta = [1.0, 0.949125, 0.928148, 0.876472, 0.855759, 0.803281]
params = pvarray.fit_pvefficiency_adr(g, t, eta, dict_output=False)
result = pvarray.pvefficiency_adr(g, t, *params)
assert_allclose(result, eta, atol=1e-6)
def test_huld():
pdc0 = 100
res = pvarray.huld(1000, 25, pdc0, cell_type='cSi')
assert np.isclose(res, pdc0)
exp_sum = np.exp(1) * (np.sum(pvarray._infer_k_huld('cSi', pdc0)) + pdc0)
res = pvarray.huld(1000*np.exp(1), 26, pdc0, cell_type='cSi')
assert np.isclose(res, exp_sum)
res = pvarray.huld(100, 30, pdc0, k=(1, 1, 1, 1, 1, 1))
exp_100 = 0.1 * (pdc0 + np.log(0.1) + np.log(0.1)**2 + 5 + 5*np.log(0.1)
+ 5*np.log(0.1)**2 + 25)
assert np.isclose(res, exp_100)
# Series input, and irradiance = 0
eff_irr = pd.Series([1000, 100, 0])
tm = pd.Series([25, 30, 30])
expected = pd.Series([pdc0, exp_100, 0])
res = pvarray.huld(eff_irr, tm, pdc0, k=(1, 1, 1, 1, 1, 1))
assert_series_equal(res, expected)
with pytest.raises(ValueError,
match='Either k or cell_type must be specified'):
res = pvarray.huld(1000, 25, 100)
@requires_statsmodels
def test_fit_huld():
# test is to recover the parameters in _infer_huld_k for each cell type
# IEC61853 conditions to make data for fitting
ee, tc = pvarray._build_iec61853()
techs = ['csi', 'cis', 'cdte']
pdc0 = 250
for tech in techs:
k0 = pvarray._infer_k_huld(tech, pdc0)
pdc = pvarray.huld(ee, tc, pdc0, cell_type=tech)
m_pdc0, k = pvarray.fit_huld(ee, tc, pdc)
expected = np.array([pdc0, ] + [v for v in k0], dtype=float)
modeled = np.hstack((m_pdc0, k))
assert_allclose(expected, modeled, rtol=1e-8)