/
test_snow.py
212 lines (190 loc) · 8.39 KB
/
test_snow.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import numpy as np
import pandas as pd
from .conftest import assert_series_equal
from pvlib import snow
from pvlib.tools import sind
import pytest
def test_fully_covered_nrel():
dt = pd.date_range(start="2019-1-1 12:00:00", end="2019-1-1 18:00:00",
freq='1h')
snowfall_data = pd.Series([1, 5, .6, 4, .23, -5, 19], index=dt)
expected = pd.Series([False, True, False, True, False, False, True],
index=dt)
fully_covered = snow.fully_covered_nrel(snowfall_data)
assert_series_equal(expected, fully_covered)
def test_coverage_nrel_hourly():
surface_tilt = 45
slide_amount_coefficient = 0.197
dt = pd.date_range(start="2019-1-1 10:00:00", end="2019-1-1 17:00:00",
freq='1h')
poa_irradiance = pd.Series([400, 200, 100, 1234, 134, 982, 100, 100],
index=dt)
temp_air = pd.Series([10, 2, 10, 1234, 34, 982, 10, 10], index=dt)
snowfall_data = pd.Series([1, .5, .6, .4, .23, -5, .1, .1], index=dt)
snow_coverage = snow.coverage_nrel(
snowfall_data, poa_irradiance, temp_air, surface_tilt,
threshold_snowfall=0.6)
slide_amt = slide_amount_coefficient * sind(surface_tilt)
covered = 1.0 - slide_amt * np.array([0, 1, 2, 3, 4, 5, 6, 7])
expected = pd.Series(covered, index=dt)
assert_series_equal(expected, snow_coverage)
def test_coverage_nrel_subhourly():
surface_tilt = 45
slide_amount_coefficient = 0.197
dt = pd.date_range(start="2019-1-1 11:00:00", end="2019-1-1 14:00:00",
freq='15T')
poa_irradiance = pd.Series([400, 200, 100, 1234, 134, 982, 100, 100, 100,
100, 100, 100, 0],
index=dt)
temp_air = pd.Series([10, 2, 10, 1234, 34, 982, 10, 10, 10, 10, -10, -10,
10], index=dt)
snowfall_data = pd.Series([1, .5, .6, .4, .23, -5, .1, .1, 0., 1., 0., 0.,
0.], index=dt)
snow_coverage = snow.coverage_nrel(
snowfall_data, poa_irradiance, temp_air, surface_tilt)
slide_amt = slide_amount_coefficient * sind(surface_tilt) * 0.25
covered = np.append(np.array([1., 1., 1., 1.]),
1.0 - slide_amt * np.array([1, 2, 3, 4, 5]))
covered = np.append(covered, np.array([1., 1., 1., 1. - slide_amt]))
expected = pd.Series(covered, index=dt)
assert_series_equal(expected, snow_coverage)
def test_fully_covered_nrel_irregular():
# test when frequency is not specified and can't be inferred
dt = pd.DatetimeIndex(["2019-1-1 11:00:00", "2019-1-1 14:30:00",
"2019-1-1 15:07:00", "2019-1-1 14:00:00"])
snowfall_data = pd.Series([1, .5, .6, .4], index=dt)
snow_coverage = snow.fully_covered_nrel(snowfall_data,
threshold_snowfall=0.5)
covered = np.array([False, False, True, False])
expected = pd.Series(covered, index=dt)
assert_series_equal(expected, snow_coverage)
def test_coverage_nrel_initial():
surface_tilt = 45
slide_amount_coefficient = 0.197
dt = pd.date_range(start="2019-1-1 10:00:00", end="2019-1-1 17:00:00",
freq='1h')
poa_irradiance = pd.Series([400, 200, 100, 1234, 134, 982, 100, 100],
index=dt)
temp_air = pd.Series([10, 2, 10, 1234, 34, 982, 10, 10], index=dt)
snowfall_data = pd.Series([0, .5, .6, .4, .23, -5, .1, .1], index=dt)
snow_coverage = snow.coverage_nrel(
snowfall_data, poa_irradiance, temp_air, surface_tilt,
initial_coverage=0.5, threshold_snowfall=1.)
slide_amt = slide_amount_coefficient * sind(surface_tilt)
covered = 0.5 - slide_amt * np.array([0, 1, 2, 3, 4, 5, 6, 7])
covered = np.where(covered < 0, 0., covered)
expected = pd.Series(covered, index=dt)
assert_series_equal(expected, snow_coverage)
def test_dc_loss_nrel():
num_strings = 8
snow_coverage = pd.Series([1, 1, .5, .6, .2, .4, 0])
expected = pd.Series([1, 1, .5, .625, .25, .5, 0])
actual = snow.dc_loss_nrel(snow_coverage, num_strings)
assert_series_equal(expected, actual)
def test__townsend_effective_snow():
snow_total = np.array([25.4, 25.4, 12.7, 2.54, 0, 0, 0, 0, 0, 0, 12.7,
25.4])
snow_events = np.array([2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3])
expected = np.array([19.05, 19.05, 12.7, 0, 0, 0, 0, 0, 0, 0, 9.525,
254 / 15])
actual = snow._townsend_effective_snow(snow_total, snow_events)
np.testing.assert_allclose(expected, actual, rtol=1e-07)
def test_loss_townsend():
# hand-calculated solution
snow_total = np.array([25.4, 25.4, 12.7, 2.54, 0, 0, 0, 0, 0, 0, 12.7,
25.4])
snow_events = np.array([2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3])
surface_tilt = 20
relative_humidity = np.array([80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80])
temp_air = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
poa_global = np.array([350000, 350000, 350000, 350000, 350000, 350000,
350000, 350000, 350000, 350000, 350000, 350000])
angle_of_repose = 40
string_factor = 1.0
slant_height = 2.54
lower_edge_height = 0.254
expected = np.array([0.07696253, 0.07992262, 0.06216201, 0.01715392, 0, 0,
0, 0, 0, 0, 0.02643821, 0.06068194])
actual = snow.loss_townsend(snow_total, snow_events, surface_tilt,
relative_humidity, temp_air,
poa_global, slant_height,
lower_edge_height, string_factor,
angle_of_repose)
np.testing.assert_allclose(expected, actual, rtol=1e-05)
@pytest.mark.parametrize(
'poa_global,surface_tilt,slant_height,lower_edge_height,string_factor,expected', # noQA: E501
[
(np.asarray(
[60., 80., 100., 125., 175., 225., 225., 210., 175., 125., 90.,
60.], dtype=float) * 1000.,
2.,
79. / 39.37,
3. / 39.37,
1.0,
np.asarray(
[44, 34, 20, 9, 3, 1, 0, 0, 0, 2, 6, 25], dtype=float)
),
(np.asarray(
[60., 80., 100., 125., 175., 225., 225., 210., 175., 125., 90.,
60.], dtype=float) * 1000.,
5.,
316 / 39.37,
120. / 39.37,
0.75,
np.asarray(
[22, 16, 9, 4, 1, 0, 0, 0, 0, 1, 2, 12], dtype=float)
),
(np.asarray(
[60., 80., 100., 125., 175., 225., 225., 210., 175., 125., 90.,
60.], dtype=float) * 1000.,
23.,
158 / 39.27,
12 / 39.37,
0.75,
np.asarray(
[28, 21, 13, 6, 2, 0, 0, 0, 0, 1, 4, 16], dtype=float)
),
(np.asarray(
[80., 100., 125., 150., 225., 300., 300., 275., 225., 150., 115.,
80.], dtype=float) * 1000.,
52.,
39.5 / 39.37,
34. / 39.37,
0.75,
np.asarray(
[7, 5, 3, 1, 0, 0, 0, 0, 0, 0, 1, 4], dtype=float)
),
(np.asarray(
[80., 100., 125., 150., 225., 300., 300., 275., 225., 150., 115.,
80.], dtype=float) * 1000.,
60.,
39.5 / 39.37,
25. / 39.37,
1.,
np.asarray(
[7, 5, 3, 1, 0, 0, 0, 0, 0, 0, 1, 3], dtype=float)
)
]
)
def test_loss_townsend_cases(poa_global, surface_tilt, slant_height,
lower_edge_height, string_factor, expected):
# test cases from Townsend, 1/27/2023, addeed by cwh
# snow_total in inches, convert to cm for pvlib
snow_total = np.asarray(
[20, 15, 10, 4, 1.5, 0, 0, 0, 0, 1.5, 4, 15], dtype=float) * 2.54
# snow events are an average for each month
snow_events = np.asarray(
[5, 4.2, 2.8, 1.3, 0.8, 0, 0, 0, 0, 0.5, 1.5, 4.5], dtype=float)
# air temperature in C
temp_air = np.asarray(
[-6., -2., 1., 4., 7., 10., 13., 16., 14., 12., 7., -3.], dtype=float)
# relative humidity in %
relative_humidity = np.asarray(
[78., 80., 75., 65., 60., 55., 55., 55., 50., 55., 60., 70.],
dtype=float)
actual = snow.loss_townsend(
snow_total, snow_events, surface_tilt, relative_humidity, temp_air,
poa_global, slant_height, lower_edge_height, string_factor)
actual = np.around(actual * 100)
assert np.allclose(expected, actual)