-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_infinite_sheds.py
More file actions
317 lines (297 loc) · 13.2 KB
/
test_infinite_sheds.py
File metadata and controls
317 lines (297 loc) · 13.2 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
"""
test infinite sheds
"""
import numpy as np
import pandas as pd
from pvlib.bifacial import infinite_sheds
from ..conftest import assert_series_equal
import pytest
@pytest.fixture
def test_system():
syst = {'height': 1.0,
'pitch': 2.,
'surface_tilt': 30.,
'surface_azimuth': 180.,
'rotation': -30.} # rotation of right edge relative to horizontal
syst['gcr'] = 1.0 / syst['pitch']
pts = np.linspace(0, 1, num=3)
sqr3 = np.sqrt(3) / 4
# c_i,j = cos(angle from point i to edge of row j), j=0 is row = -1
# c_i,j = cos(angle from point i to edge of row j), j=0 is row = -1
c00 = (-2 - sqr3) / np.sqrt(1.25**2 + (2 + sqr3)**2) # right edge row -1
c01 = -sqr3 / np.sqrt(1.25**2 + sqr3**2) # right edge row 0
c02 = sqr3 / np.sqrt(0.75**2 + sqr3**2) # left edge of row 0
c03 = (2 - sqr3) / np.sqrt(1.25**2 + (2 - sqr3)**2) # right edge of row 1
vf_0 = 0.5 * (c03 - c02 + c01 - c00) # vf at point 0
c10 = (-3 - sqr3) / np.sqrt(1.25**2 + (3 + sqr3)**2) # right edge row -1
c11 = (-1 - sqr3) / np.sqrt(1.25**2 + (1 + sqr3)**2) # right edge row 0
c12 = (-1 + sqr3) / np.sqrt(0.75**2 + (-1 + sqr3)**2) # left edge row 0
c13 = (1 - sqr3) / np.sqrt(1.25**2 + (1 - sqr3)**2) # right edge row
vf_1 = 0.5 * (c13 - c12 + c11 - c10) # vf at point 1
c20 = -(4 + sqr3) / np.sqrt(1.25**2 + (4 + sqr3)**2) # right edge row -1
c21 = (-2 + sqr3) / np.sqrt(0.75**2 + (-2 + sqr3)**2) # left edge row 0
c22 = (-2 - sqr3) / np.sqrt(1.25**2 + (2 + sqr3)**2) # right edge row 0
c23 = (0 - sqr3) / np.sqrt(1.25**2 + (0 - sqr3)**2) # right edge row 1
vf_2 = 0.5 * (c23 - c22 + c21 - c20) # vf at point 1
vfs_ground_sky = np.array([vf_0, vf_1, vf_2])
return syst, pts, vfs_ground_sky
def test__poa_ground_shadows():
poa_ground, f_gnd_beam, df, vf_gnd_sky = (300., 0.5, 0.5, 0.2)
result = infinite_sheds._poa_ground_shadows(
poa_ground, f_gnd_beam, df, vf_gnd_sky)
expected = 300. * (0.5 * 0.5 + 0.5 * 0.2)
assert np.isclose(result, expected)
# vector inputs
poa_ground = np.array([300., 300.])
f_gnd_beam = np.array([0.5, 0.5])
df = np.array([0.5, 0.])
vf_gnd_sky = np.array([0.2, 0.2])
result = infinite_sheds._poa_ground_shadows(
poa_ground, f_gnd_beam, df, vf_gnd_sky)
expected_vec = np.array([expected, 300. * 0.5])
assert np.allclose(result, expected_vec)
def test__shaded_fraction_floats():
result = infinite_sheds._shaded_fraction(
solar_zenith=60., solar_azimuth=180., surface_tilt=60.,
surface_azimuth=180., gcr=1.0)
assert np.isclose(result, 0.5)
def test__shaded_fraction_array():
solar_zenith = np.array([0., 60., 90., 60.])
solar_azimuth = np.array([180., 180., 180., 180.])
surface_azimuth = np.array([180., 180., 180., 210.])
surface_tilt = np.array([30., 60., 0., 30.])
gcr = 1.0
result = infinite_sheds._shaded_fraction(
solar_zenith, solar_azimuth, surface_tilt, surface_azimuth, gcr)
x = 0.75 + np.sqrt(3) / 2
expected = np.array([0.0, 0.5, 0., (x - 1) / x])
assert np.allclose(result, expected)
def test_get_irradiance_poa():
# singleton inputs
solar_zenith = 0.
solar_azimuth = 180.
surface_tilt = 0.
surface_azimuth = 180.
gcr = 0.5
height = 1.
pitch = 1
ghi = 1000
dhi = 300
dni = 700
albedo = 0
iam = 1.0
npoints = 100
res = infinite_sheds.get_irradiance_poa(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni,
albedo, iam=iam, npoints=npoints)
expected_diffuse = np.array([300.])
expected_direct = np.array([700.])
expected_global = expected_diffuse + expected_direct
expected_shaded_fraction = np.array([0.])
assert np.isclose(res['poa_global'], expected_global)
assert np.isclose(res['poa_diffuse'], expected_diffuse)
assert np.isclose(res['poa_direct'], expected_direct)
assert np.isclose(res['shaded_fraction'], expected_shaded_fraction)
# vector inputs
surface_tilt = np.array([0., 0., 0., 0.])
height = 1.
surface_azimuth = np.array([180., 180., 180., 180.])
gcr = 0.5
pitch = 1
solar_zenith = np.array([0., 45., 45., 90.])
solar_azimuth = np.array([180., 180., 135., 180.])
expected_diffuse = np.array([300., 300., 300., 300.])
expected_direct = np.array(
[700., 350. * np.sqrt(2), 350. * np.sqrt(2), 0.])
expected_global = expected_diffuse + expected_direct
expected_shaded_fraction = np.array(
[0., 0., 0., 0.])
res = infinite_sheds.get_irradiance_poa(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni,
albedo, iam=iam, npoints=npoints)
assert np.allclose(res['poa_global'], expected_global)
assert np.allclose(res['poa_diffuse'], expected_diffuse)
assert np.allclose(res['poa_direct'], expected_direct)
assert np.allclose(res['shaded_fraction'], expected_shaded_fraction)
# series inputs
surface_tilt = pd.Series(surface_tilt)
surface_azimuth = pd.Series(data=surface_azimuth, index=surface_tilt.index)
solar_zenith = pd.Series(solar_zenith, index=surface_tilt.index)
solar_azimuth = pd.Series(data=solar_azimuth, index=surface_tilt.index)
expected_diffuse = pd.Series(
data=expected_diffuse, index=surface_tilt.index)
expected_direct = pd.Series(
data=expected_direct, index=surface_tilt.index)
expected_global = expected_diffuse + expected_direct
expected_global.name = 'poa_global' # to match output Series
expected_shaded_fraction = pd.Series(
data=expected_shaded_fraction, index=surface_tilt.index)
expected_shaded_fraction.name = 'shaded_fraction' # to match output Series
res = infinite_sheds.get_irradiance_poa(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni,
albedo, iam=iam, npoints=npoints)
assert isinstance(res, pd.DataFrame)
assert_series_equal(res['poa_global'], expected_global)
assert_series_equal(res['shaded_fraction'], expected_shaded_fraction)
assert all(k in res.columns for k in [
'poa_global', 'poa_diffuse', 'poa_direct', 'poa_ground_diffuse',
'poa_sky_diffuse', 'shaded_fraction'])
def test__backside_tilt():
tilt = np.array([0., 30., 30., 180.])
system_azimuth = np.array([180., 150., 270., 0.])
back_tilt, back_az = infinite_sheds._backside(tilt, system_azimuth)
assert np.allclose(back_tilt, np.array([180., 150., 150., 0.]))
assert np.allclose(back_az, np.array([0., 330., 90., 180.]))
@pytest.mark.parametrize("vectorize", [True, False])
def test_get_irradiance(vectorize):
# singleton inputs
solar_zenith = 0.
solar_azimuth = 180.
surface_tilt = 0.
surface_azimuth = 180.
gcr = 0.5
height = 1.
pitch = 1.
ghi = 1000.
dhi = 300.
dni = 700.
albedo = 0.
iam_front = 1.0
iam_back = 1.0
npoints = 100
result = infinite_sheds.get_irradiance(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni, albedo, iam_front, iam_back,
bifaciality=0.8, shade_factor=-0.02, transmission_factor=0,
npoints=npoints, vectorize=vectorize)
expected_front_diffuse = np.array([300.])
expected_front_direct = np.array([700.])
expected_front_global = expected_front_diffuse + expected_front_direct
expected_shaded_fraction_front = np.array([0.])
expected_shaded_fraction_back = np.array([0.])
assert np.isclose(result['poa_front'], expected_front_global)
assert np.isclose(result['poa_front_diffuse'], expected_front_diffuse)
assert np.isclose(result['poa_front_direct'], expected_front_direct)
assert np.isclose(result['poa_global'], result['poa_front'])
assert np.isclose(result['shaded_fraction_front'],
expected_shaded_fraction_front)
assert np.isclose(result['shaded_fraction_back'],
expected_shaded_fraction_back)
# series inputs
ghi = pd.Series([1000., 500., 500., np.nan])
dhi = pd.Series([300., 500., 500., 500.], index=ghi.index)
dni = pd.Series([700., 0., 0., 700.], index=ghi.index)
solar_zenith = pd.Series([0., 0., 0., 135.], index=ghi.index)
surface_tilt = pd.Series([0., 0., 90., 0.], index=ghi.index)
result = infinite_sheds.get_irradiance(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni, albedo, iam_front, iam_back,
bifaciality=0.8, shade_factor=-0.02, transmission_factor=0,
npoints=npoints, vectorize=vectorize)
result_front = infinite_sheds.get_irradiance_poa(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni,
albedo, iam=iam_front, vectorize=vectorize)
assert isinstance(result, pd.DataFrame)
expected_poa_global = pd.Series(
[1000., 500., result_front['poa_global'][2] * (1 + 0.8 * 0.98),
np.nan], index=ghi.index, name='poa_global')
expected_shaded_fraction = pd.Series(
result_front['shaded_fraction'], index=ghi.index,
name='shaded_fraction_front')
assert_series_equal(result['poa_global'], expected_poa_global)
assert_series_equal(result['shaded_fraction_front'],
expected_shaded_fraction)
def test_get_irradiance_limiting_gcr():
# test confirms that irradiance on widely spaced rows is approximately
# the same as for a single row array
solar_zenith = 0.
solar_azimuth = 180.
surface_tilt = 90.
surface_azimuth = 180.
gcr = 0.00001
height = 1.
pitch = 100.
ghi = 1000.
dhi = 300.
dni = 700.
albedo = 1.
iam_front = 1.0
iam_back = 1.0
npoints = 100
result = infinite_sheds.get_irradiance(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni, albedo, iam_front, iam_back,
bifaciality=1., shade_factor=-0.00, transmission_factor=0.,
npoints=npoints)
expected_ground_diffuse = np.array([500.])
expected_sky_diffuse = np.array([150.])
expected_direct = np.array([0.])
expected_diffuse = expected_ground_diffuse + expected_sky_diffuse
expected_poa = expected_diffuse + expected_direct
expected_shaded_fraction_front = np.array([0.])
expected_shaded_fraction_back = np.array([0.])
assert np.isclose(result['poa_front'], expected_poa, rtol=0.01)
assert np.isclose(result['poa_front_diffuse'], expected_diffuse, rtol=0.01)
assert np.isclose(result['poa_front_direct'], expected_direct)
assert np.isclose(result['poa_front_sky_diffuse'], expected_sky_diffuse,
rtol=0.01)
assert np.isclose(result['poa_front_ground_diffuse'],
expected_ground_diffuse, rtol=0.01)
assert np.isclose(result['poa_front'], result['poa_back'])
assert np.isclose(result['poa_front_diffuse'], result['poa_back_diffuse'])
assert np.isclose(result['poa_front_direct'], result['poa_back_direct'])
assert np.isclose(result['poa_front_sky_diffuse'],
result['poa_back_sky_diffuse'])
assert np.isclose(result['poa_front_ground_diffuse'],
result['poa_back_ground_diffuse'])
assert np.isclose(result['shaded_fraction_front'],
expected_shaded_fraction_front)
assert np.isclose(result['shaded_fraction_back'],
expected_shaded_fraction_back)
def test_get_irradiance_with_haydavies():
# singleton inputs
solar_zenith = 0.
solar_azimuth = 180.
surface_tilt = 0.
surface_azimuth = 180.
gcr = 0.5
height = 1.
pitch = 1.
ghi = 1000.
dhi = 300.
dni = 700.
albedo = 0.
dni_extra = 1413.
model = 'haydavies'
iam_front = 1.0
iam_back = 1.0
npoints = 100
result = infinite_sheds.get_irradiance(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni, albedo, model, dni_extra,
iam_front, iam_back, bifaciality=0.8, shade_factor=-0.02,
transmission_factor=0, npoints=npoints)
expected_front_diffuse = np.array([151.38])
expected_front_direct = np.array([848.62])
expected_front_global = expected_front_diffuse + expected_front_direct
expected_shaded_fraction_front = np.array([0.])
expected_shaded_fraction_back = np.array([0.])
assert np.isclose(result['poa_front'], expected_front_global)
assert np.isclose(result['poa_front_diffuse'], expected_front_diffuse)
assert np.isclose(result['poa_front_direct'], expected_front_direct)
assert np.isclose(result['poa_global'], result['poa_front'])
assert np.isclose(result['shaded_fraction_front'],
expected_shaded_fraction_front)
assert np.isclose(result['shaded_fraction_back'],
expected_shaded_fraction_back)
# test for when dni_extra is not supplied
with pytest.raises(ValueError, match='supply dni_extra for haydavies'):
result = infinite_sheds.get_irradiance(
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
gcr, height, pitch, ghi, dhi, dni, albedo, model, None,
iam_front, iam_back, bifaciality=0.8, shade_factor=-0.02,
transmission_factor=0, npoints=npoints)