-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_degradation.py
184 lines (139 loc) · 5.05 KB
/
test_degradation.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
Using pytest to create unit tests for pvdeg
to run unit tests, run pytest from the command line in the pvdeg directory
to run coverage tests, run py.test --cov-report term-missing --cov=pvdeg
"""
import os
import pandas as pd
import numpy as np
import pytest
import pvdeg
from pvdeg import TEST_DATA_DIR
PSM_FILE = os.path.join(TEST_DATA_DIR, r"psm3_pytest.csv")
weather_df, meta = pvdeg.weather.read(PSM_FILE, "psm")
INPUT_SPECTRA = os.path.join(TEST_DATA_DIR, r"spectra_pytest.csv")
def test_vantHoff_deg():
# test the vantHoff degradation acceleration factor
vantHoff_deg = pvdeg.degradation.vantHoff_deg(
weather_df=weather_df, meta=meta, I_chamber=1000, temp_chamber=60
)
assert vantHoff_deg == pytest.approx(8.178, abs=0.01)
def test_iwa_vantHoff():
# test the vantHoff equivalent weighted average irradiance
irr_weighted_avg = pvdeg.degradation.IwaVantHoff(weather_df=weather_df, meta=meta)
assert irr_weighted_avg == pytest.approx(240.28, abs=0.05)
def test_iwa_vantHoff_no_poa():
poa = pvdeg.spectral.poa_irradiance(weather_df, meta)
irr_weighted_avg_match = pvdeg.degradation.IwaVantHoff(
weather_df=weather_df, meta=meta, poa=poa
)
assert irr_weighted_avg_match == pytest.approx(240.28, abs=0.05)
def test_arrhenius_deg():
# test the arrhenius degradation acceleration factor
rh_chamber = 15
temp_chamber = 60
I_chamber = 1e3
Ea = 40
poa = pvdeg.spectral.poa_irradiance(weather_df, meta)
temp_module = pvdeg.temperature.module(weather_df, meta, poa=poa)
rh_surface = pvdeg.humidity.surface_outside(
rh_ambient=weather_df["relative_humidity"],
temp_ambient=weather_df["temp_air"],
temp_module=temp_module,
)
arrhenius_deg = pvdeg.degradation.arrhenius_deg(
weather_df=weather_df,
meta=meta,
I_chamber=I_chamber,
rh_chamber=rh_chamber,
rh_outdoor=rh_surface,
temp_chamber=temp_chamber,
Ea=Ea,
poa=poa,
)
assert arrhenius_deg == pytest.approx(12.804, abs=0.1)
def test_arrhenius_deg_no_poa():
rh_chamber = 15
temp_chamber = 60
I_chamber = 1e3
Ea = 40
temp_module = pvdeg.temperature.module(weather_df, meta)
rh_surface = pvdeg.humidity.surface_outside(
rh_ambient=weather_df["relative_humidity"],
temp_ambient=weather_df["temp_air"],
temp_module=temp_module,
)
arrhenius_deg = pvdeg.degradation.arrhenius_deg(
weather_df=weather_df,
meta=meta,
I_chamber=I_chamber,
rh_chamber=rh_chamber,
rh_outdoor=rh_surface,
temp_chamber=temp_chamber,
Ea=Ea,
)
assert arrhenius_deg == pytest.approx(12.804, abs=0.1)
def test_iwa_arrhenius():
# test arrhenius equivalent weighted average irradiance
# requires PSM3 weather file
Ea = 40
irr_weighted_avg = pvdeg.degradation.IwaArrhenius(
weather_df=weather_df,
meta=meta,
rh_outdoor=weather_df["relative_humidity"],
Ea=Ea,
)
assert irr_weighted_avg == pytest.approx(199.42, abs=0.1)
def test_iwa_arrhenius_poa():
poa = pvdeg.spectral.poa_irradiance(weather_df=weather_df, meta=meta)
Ea = 40
irr_weighted_avg = pvdeg.degradation.IwaArrhenius(
weather_df=weather_df,
meta=meta,
rh_outdoor=weather_df["relative_humidity"],
Ea=Ea,
poa=poa,
)
assert irr_weighted_avg == pytest.approx(199.42, abs=0.1)
def test_degradation():
# test RH, Temp, Spectral Irradiance sensitive degradation
# requires TMY3-like weather data
# requires spectral irradiance data
data = pd.read_csv(INPUT_SPECTRA)
wavelengths = np.array(range(280, 420, 20))
# convert to expected format
spectra = data["Spectra"]
spectra_df = pd.DataFrame(spectra.tolist(), index=spectra.index)
spectra_df = spectra.str.strip("[]").str.split(",", expand=True).astype(float)
spectra_df.columns = wavelengths
conditions_df = pd.DataFrame(
index=spectra_df.index,
data={
"relative_humidity": data["RH"],
"temperature": data["Temperature"],
}
)
degradation = pvdeg.degradation.degradation(
spectra_df=spectra_df,
conditions_df=conditions_df
)
assert degradation == pytest.approx(4.4969e-38, abs=0.02e-38)
# def test_hours_rh_above_85():
# values = np.arange(0,100)
# rh_linear_df = pd.DataFrame(values, columns=['rh'])
# hours_above_85 = pvdeg.degradation._hoursRH_Above85(rh_linear_df)
# assert hours_above_85 == 14
def test_wh_to_gj():
gj = pvdeg.degradation._whToGJ(wh=1)
assert gj == 3.6e-6
def test_vecArrhenius():
poa_global = pvdeg.spectral.poa_irradiance(weather_df=weather_df, meta=meta)[
"poa_global"
].to_numpy()
module_temp = pvdeg.temperature.temperature(
weather_df=weather_df, meta=meta, cell_or_mod="mod"
).to_numpy()
degradation = pvdeg.degradation.vecArrhenius(
poa_global=poa_global, module_temp=module_temp, ea=30, x=2, lnr0=15
)
pytest.approx(degradation, 6.603006830204657)