Skip to content

Commit 2b5750a

Browse files
committed
lint
1 parent 015500d commit 2b5750a

3 files changed

Lines changed: 84 additions & 83 deletions

File tree

pvlib/bifacial/ants2d.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _shaded_fraction(tracker_rotation, phi, gcr, x0=0, x1=1):
6060
# apply it here.
6161
# also, we have PSZA instead of solar position, so use fake azimuths to
6262
# trick shaded_fraction1d into accepting it as-is.
63-
# direction of positive phi by right-hand rule:
63+
# direction of positive phi by right-hand rule:
6464
f_s = shaded_fraction1d(phi, solar_azimuth=90,
6565
axis_azimuth=0,
6666
shaded_row_rotation=tracker_rotation,
@@ -129,17 +129,17 @@ def _ants2d_singleside(tracker_rotation, cos_aoi, phi, gcr, height, pitch,
129129
Position on the row's slant length, as a fraction of the slant length.
130130
``x1=1`` corresponds to the right side of the row.
131131
``x1`` should be greater than ``x0``. If specified as array, it
132-
must have the same length as ``x0``.[unitless]
132+
must have the same length as ``x0``. [unitless]
133133
g0 : numeric
134134
Position on the ground surface, as a fraction of the row-to-row
135135
spacing. ``g0=0`` corresponds to ground underneath the middle of the
136136
left row. ``g0`` should be less than ``g1``. If specified as array, it
137-
must have the same length as ``g1``.[unitless]
137+
must have the same length as ``g1``. [unitless]
138138
g1 : numeric
139139
Position on the ground surface, as a fraction of the row-to-row
140140
spacing. ``g1=1`` corresponds to ground underneath the middle of the
141-
right row. ``g1`` should be greater than ``g0``. If specified as array, it
142-
must have the same length as ``g0``.[unitless]
141+
right row. ``g1`` should be greater than ``g0``. If specified as
142+
array, it must have the same length as ``g0``. [unitless]
143143
max_rows : int
144144
Number of array units (sky wedges, ground segments, etc) to consider.
145145
[unitless]
@@ -174,13 +174,11 @@ def _ants2d_singleside(tracker_rotation, cos_aoi, phi, gcr, height, pitch,
174174
poa_direct = dni * projection * (1 - row_shaded_fraction)
175175
poa_direct = poa_direct[0] # drop ground segment dimension
176176

177-
178177
# in-plane sky diffuse component
179178
vf_row_sky = utils.vf_row_sky_2d_integ(tracker_rotation, gcr, x0, x1)
180179
poa_sky_diffuse = vf_row_sky * dhi
181180
poa_sky_diffuse = poa_sky_diffuse[0] # drop ground segment dimension
182181

183-
184182
# in-plane ground-reflected component
185183
vf_row_ground = utils.vf_row_ground_2d_integ(surface_tilt=tracker_rotation,
186184
gcr=gcr, height=height,
@@ -191,7 +189,6 @@ def _ants2d_singleside(tracker_rotation, cos_aoi, phi, gcr, height, pitch,
191189
# sum over ground segments
192190
poa_ground_diffuse = np.sum(poa_ground_diffuse, axis=0)
193191

194-
195192
# add sky and ground-reflected irradiance on the row by irradiance
196193
# component
197194
poa_diffuse = poa_ground_diffuse + poa_sky_diffuse
@@ -268,7 +265,8 @@ def _apply_ground_slope(height, pitch, gcr, tracker_rotation, ghi, dni, dhi,
268265
pitch = pitch / cosd(cross_axis_slope)
269266
gcr = gcr * cosd(cross_axis_slope)
270267
tracker_rotation = tracker_rotation - cross_axis_slope
271-
tracker_rotation = ((tracker_rotation + 180) % 360) - 180 # put back to [-180, 180]
268+
# put back to [-180, 180]:
269+
tracker_rotation = ((tracker_rotation + 180) % 360) - 180
272270

273271
ghi = dhi + dni * np.maximum(
274272
aoi_projection(slope_tilt, slope_azimuth,
@@ -277,8 +275,6 @@ def _apply_ground_slope(height, pitch, gcr, tracker_rotation, ghi, dni, dhi,
277275
# dhi: no need to adjust; the blocked view is only near the
278276
# the horizon, and that part of the sky is blocked by rows anyway
279277
# dni: no adjustment needed; the measurement plane is not affected
280-
#dhi = dhi
281-
#dni = dni
282278
return height, pitch, gcr, tracker_rotation, ghi
283279

284280

pvlib/bifacial/utils.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _unshaded_ground_fraction(surface_tilt, phi, gcr, height=None,
110110

111111
g0 = np.atleast_1d(g0)[np.newaxis, :, np.newaxis]
112112
g1 = np.atleast_1d(g1)[np.newaxis, :, np.newaxis]
113-
113+
114114
# TODO seems like this should be np.arange(-max_rows, max_rows+1)?
115115
# see GH #1867
116116
k = np.arange(-max_rows, max_rows)[:, np.newaxis, np.newaxis]
@@ -124,12 +124,12 @@ def _unshaded_ground_fraction(surface_tilt, phi, gcr, height=None,
124124
# d, c: left/right shading module edges
125125
c = (k*pitch + 0.5 * Lcostheta, height + 0.5 * Lsintheta)
126126
d = (k*pitch - 0.5 * Lcostheta, height - 0.5 * Lsintheta)
127-
127+
128128
cp = c[0] + c[1] * tanphi
129129
dp = d[0] + d[1] * tanphi
130130
swap = dp > cp
131131
cp, dp = np.where(swap, dp, cp), np.where(swap, cp, dp)
132-
132+
133133
a = g0*pitch
134134
b = g1*pitch
135135

@@ -142,11 +142,11 @@ def _unshaded_ground_fraction(surface_tilt, phi, gcr, height=None,
142142
fs = np.where((a < dp) & (dp < b) & (a < cp) & (cp < b),
143143
(cp - dp) / (b - a), fs)
144144
fs = np.where((dp > b) & (cp > b), 0.0, fs)
145-
145+
146146
# total shaded fraction is sum of individuals; note that shadows
147147
# never overlap in this model, except when shaded fraction is 100% anyway
148148
f_gnd_beam = 1 - np.clip(np.sum(fs, axis=0), 0, 1) # sum along k dimension
149-
149+
150150
# using phi is more convenient, and I think better, than using zenith
151151
phi = phi[0, :, :] # drop k dimension for the next line
152152
f_gnd_beam = np.where(np.abs(phi) > max_zenith, 0., f_gnd_beam)
@@ -302,11 +302,12 @@ def vf_ground_sky_2d_integ(tracker_rotation, gcr, height, pitch, g0=0, g1=1,
302302

303303
# dimensions: k/max_rows, ground segment, time
304304

305-
tracker_rotation = np.atleast_1d(tracker_rotation)[np.newaxis, np.newaxis, :]
306-
305+
tracker_rotation = \
306+
np.atleast_1d(tracker_rotation)[np.newaxis, np.newaxis, :]
307+
307308
g0 = np.atleast_1d(g0)[np.newaxis, :, np.newaxis]
308309
g1 = np.atleast_1d(g1)[np.newaxis, :, np.newaxis]
309-
310+
310311
# TODO seems like this should be np.arange(-max_rows, max_rows+1)?
311312
# see GH #1867
312313
k = np.arange(-max_rows, max_rows)[:, np.newaxis, np.newaxis]
@@ -325,7 +326,7 @@ def vf_ground_sky_2d_integ(tracker_rotation, gcr, height, pitch, g0=0, g1=1,
325326
d = (c[0] - pitch, c[1])
326327

327328
# view obstruction points (module edges, but need to figure out which ones)
328-
329+
329330
# first decide whether the left obstruction is the left or right mod edge
330331
left = (k*pitch - 0.5 * Lcostheta, height - 0.5 * Lsintheta)
331332
right = (k*pitch + 0.5 * Lcostheta, height + 0.5 * Lsintheta)
@@ -335,7 +336,7 @@ def vf_ground_sky_2d_integ(tracker_rotation, gcr, height, pitch, g0=0, g1=1,
335336
np.where(angle_left > angle_right, right[0], left[0]),
336337
np.where(angle_left > angle_right, right[1], left[1])
337338
)
338-
339+
339340
# now for the right obstruction
340341
left = (left[0] + pitch, left[1])
341342
right = (right[0] + pitch, right[1])
@@ -432,8 +433,8 @@ def vf_row_sky_2d_integ(surface_tilt, gcr, x0=0, x1=1):
432433
Ratio of the row slant length to the row spacing (pitch). [unitless]
433434
x0 : numeric, default 0
434435
Position on the row's slant length, as a fraction of the slant length.
435-
``x0=0`` corresponds to the bottom of the row. ``x0`` should be less than
436-
``x1``. [unitless]
436+
``x0=0`` corresponds to the bottom of the row. ``x0`` should be less
437+
than ``x1``. [unitless]
437438
x1 : numeric, default 1
438439
Position on the row's slant length, as a fraction of the slant length.
439440
``x1`` should be greater than ``x0``. [unitless]
@@ -453,9 +454,9 @@ def vf_row_sky_2d_integ(surface_tilt, gcr, x0=0, x1=1):
453454
squeeze.append(1)
454455

455456
# dimensions: row segment, time
456-
457+
457458
surface_tilt = np.atleast_1d(surface_tilt)[np.newaxis, :]
458-
459+
459460
x0 = np.atleast_1d(x0)[:, np.newaxis]
460461
x1 = np.atleast_1d(x1)[:, np.newaxis]
461462

@@ -574,19 +575,20 @@ def vf_row_ground_2d_integ(surface_tilt, gcr, height=None, pitch=None,
574575
# cheat a little to prevent numerical issues with surface_tilt==180, -180
575576
surface_tilt = np.where(surface_tilt == 180, 179.9999, surface_tilt)
576577
surface_tilt = np.where(surface_tilt == -180, -179.9999, surface_tilt)
577-
578-
surface_tilt = np.atleast_1d(surface_tilt)[np.newaxis, np.newaxis, np.newaxis, :]
579-
578+
579+
surface_tilt = \
580+
np.atleast_1d(surface_tilt)[np.newaxis, np.newaxis, np.newaxis, :]
581+
580582
x0 = np.atleast_1d(x0)[np.newaxis, np.newaxis, :, np.newaxis]
581583
x1 = np.atleast_1d(x1)[np.newaxis, np.newaxis, :, np.newaxis]
582584
g0 = np.atleast_1d(g0)[np.newaxis, :, np.newaxis, np.newaxis]
583585
g1 = np.atleast_1d(g1)[np.newaxis, :, np.newaxis, np.newaxis]
584-
586+
585587
# TODO seems like this should be np.arange(-max_rows, max_rows+1)?
586588
# see GH #1867
587589
k = np.arange(-max_rows, max_rows)[:, np.newaxis, np.newaxis, np.newaxis]
588-
589-
collector_width = pitch * gcr
590+
591+
collector_width = pitch * gcr
590592
Lcostheta = collector_width * cosd(surface_tilt)
591593
Lsintheta = collector_width * sind(surface_tilt)
592594

@@ -595,7 +597,7 @@ def vf_row_ground_2d_integ(surface_tilt, gcr, height=None, pitch=None,
595597
# be a nonzero distance from all points the VF could be calculated from
596598
ob_right = (-pitch - 0.5001 * Lcostheta, height - 0.5001 * abs(Lsintheta))
597599
ob_left = (ob_right[0] + pitch, ob_right[1])
598-
600+
599601
invert = surface_tilt < 0
600602
temp = ob_right[0]
601603
ob_right = (np.where(invert, -ob_left[0], ob_right[0]), ob_right[1])
@@ -614,7 +616,7 @@ def vf_row_ground_2d_integ(surface_tilt, gcr, height=None, pitch=None,
614616
ac, ad, bc, bd = _obstructed_string_lengths(a, b, c, d, ob_left, ob_right)
615617

616618
# crossed string formula for VF
617-
vf_slats = 0.5 * (1/((x1 - x0) * collector_width)) * ((ac + bd) - (bc + ad))
619+
vf_slats = 1 / (2 * (x1 - x0) * collector_width) * ((ac + bd) - (bc + ad))
618620
vf_total = np.sum(np.maximum(vf_slats, 0), axis=0) # sum along k dimension
619621

620622
# dimensions are now ground_segment, row_segment, time

tests/bifacial/test_ants2d.py

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
def test__shaded_fraction():
15-
1615
# special angles
1716
tracker_rotation = np.array([60, 60, 60, 60])
1817
phi = np.array([60, 60, 60, 60])
@@ -84,7 +83,6 @@ def test__apply_sky_diffuse_model(model):
8483
poa_direct + poa_sky_diffuse + poa_ground, abs=1e-10)
8584

8685

87-
8886
def test__apply_sky_diffuse_model_errors():
8987
with pytest.raises(ValueError, match='Must supply dni_extra'):
9088
ants2d._apply_sky_diffuse_model(0, 0, 'haydavies', None,
@@ -208,11 +206,12 @@ def test_get_irradiance_return_type(ants_params):
208206
# verify pandas in -> pandas out, and shapes of numpy outputs
209207
out = ants2d.get_irradiance(**ants_params, row_segments=1)
210208
assert isinstance(out, pd.DataFrame) # DataFrame, since n_row_segments=1
211-
expected_keys = ['poa_front', 'poa_front_direct', 'poa_front_diffuse',
212-
'poa_front_sky_diffuse', 'poa_front_ground_diffuse',
213-
'shaded_fraction_front', 'poa_back', 'poa_back_direct',
214-
'poa_back_diffuse', 'poa_back_sky_diffuse', 'poa_back_ground_diffuse',
215-
'shaded_fraction_back']
209+
expected_keys = [
210+
'poa_front', 'poa_front_direct', 'poa_front_diffuse',
211+
'poa_front_sky_diffuse', 'poa_front_ground_diffuse',
212+
'shaded_fraction_front', 'poa_back', 'poa_back_direct',
213+
'poa_back_diffuse', 'poa_back_sky_diffuse', 'poa_back_ground_diffuse',
214+
'shaded_fraction_back']
216215
assert set(out.columns) == set(expected_keys)
217216
assert len(out) == 2 # 2 timestamps
218217

@@ -245,9 +244,10 @@ def test_get_irradiance_vertical(ants_params, solar_zenith, tracker_rotation):
245244
out = ants2d.get_irradiance(**ants_params, row_segments=1)
246245
# inputs are symmetrical morning/afternoon, so morning front should equal
247246
# afternoon back, and vice versa
248-
front_keys = ['poa_front', 'poa_front_direct', 'poa_front_diffuse',
249-
'poa_front_sky_diffuse', 'poa_front_ground_diffuse',
250-
'shaded_fraction_front']
247+
front_keys = [
248+
'poa_front', 'poa_front_direct', 'poa_front_diffuse',
249+
'poa_front_sky_diffuse', 'poa_front_ground_diffuse',
250+
'shaded_fraction_front']
251251
for front_key in front_keys:
252252
back_key = front_key.replace("front", "back")
253253
np.testing.assert_allclose(out.iloc[0][front_key],
@@ -288,9 +288,9 @@ def test_get_irradiance_limit(ants_params):
288288
model='isotropic')
289289
# 15 W/m2 happens to be just below the difference (determined empirically)
290290
diff_sky = irrad['poa_sky_diffuse'] - ants['poa_front_sky_diffuse']
291-
diff_ground = irrad['poa_ground_diffuse'] - ants['poa_front_ground_diffuse']
291+
diff_grd = irrad['poa_ground_diffuse'] - ants['poa_front_ground_diffuse']
292292
assert all(diff_sky > 15)
293-
assert all(diff_ground > 15)
293+
assert all(diff_grd > 15)
294294

295295
# but as pitch->infinity, front-side irradiance converges to
296296
# output of get_total_irradiance
@@ -305,7 +305,7 @@ def test_get_irradiance_limit(ants_params):
305305
'poa_front_ground_diffuse': 'poa_ground_diffuse'}
306306
ants_front = ants[list(colmap)].rename(columns=colmap)
307307
pd.testing.assert_frame_equal(ants_front, irrad, atol=0.1)
308-
308+
309309

310310
@pytest.fixture
311311
def ants_params_fixed():
@@ -452,43 +452,46 @@ def test_get_irradiance_nonuniform_albedo_limit():
452452

453453

454454
@pytest.mark.parametrize('model,expected', [
455-
('isotropic', {'poa_front': 1006.3548761345762,
456-
'poa_front_direct': 833.3333333333335,
457-
'poa_front_diffuse': 173.0215428012428,
458-
'poa_front_sky_diffuse': 172.27247024391784,
459-
'poa_front_ground_diffuse': 0.7490725573249604,
460-
'shaded_fraction_front': 0.035915234551783914,
461-
'poa_back': 23.626216052516494,
462-
'poa_back_direct': 0.0,
463-
'poa_back_diffuse': 23.626216052516494,
464-
'poa_back_sky_diffuse': 8.509173579096064,
465-
'poa_back_ground_diffuse': 15.11704247342043,
466-
'shaded_fraction_back': 0.035915234551784025}),
467-
('haydavies', {'poa_front': 1124.2311927022897,
468-
'poa_front_direct': 1078.4313725490197,
469-
'poa_front_diffuse': 45.79982015327015,
470-
'poa_front_sky_diffuse': 45.60153624103707,
471-
'poa_front_ground_diffuse': 0.19828391223307773,
472-
'shaded_fraction_front': 0.035915234551783914,
473-
'poa_back': 6.2539983668426,
474-
'poa_back_direct': 0.0,
475-
'poa_back_diffuse': 6.2539983668426,
476-
'poa_back_sky_diffuse': 2.252428300348958,
477-
'poa_back_ground_diffuse': 4.001570066493642,
478-
'shaded_fraction_back': 0.035915234551784025}),
479-
('perez', {'poa_front': 1060.3368384162613,
480-
'poa_front_direct': 945.5770264984124,
481-
'poa_front_diffuse': 114.75981191784896,
482-
'poa_front_sky_diffuse': 114.26297537137229,
483-
'poa_front_ground_diffuse': 0.4968365464766687,
484-
'shaded_fraction_front': 0.035915234551783914,
485-
'poa_back': 15.670534816764919,
486-
'poa_back_direct': 0.0,
487-
'poa_back_diffuse': 15.670534816764919,
488-
'poa_back_sky_diffuse': 5.643870374194696,
489-
'poa_back_ground_diffuse': 10.026664442570222,
490-
'shaded_fraction_back': 0.035915234551784025})
491-
])
455+
('isotropic', {
456+
'poa_front': 1006.3548761345762,
457+
'poa_front_direct': 833.3333333333335,
458+
'poa_front_diffuse': 173.0215428012428,
459+
'poa_front_sky_diffuse': 172.27247024391784,
460+
'poa_front_ground_diffuse': 0.7490725573249604,
461+
'shaded_fraction_front': 0.035915234551783914,
462+
'poa_back': 23.626216052516494,
463+
'poa_back_direct': 0.0,
464+
'poa_back_diffuse': 23.626216052516494,
465+
'poa_back_sky_diffuse': 8.509173579096064,
466+
'poa_back_ground_diffuse': 15.11704247342043,
467+
'shaded_fraction_back': 0.035915234551784025}),
468+
('haydavies', {
469+
'poa_front': 1124.2311927022897,
470+
'poa_front_direct': 1078.4313725490197,
471+
'poa_front_diffuse': 45.79982015327015,
472+
'poa_front_sky_diffuse': 45.60153624103707,
473+
'poa_front_ground_diffuse': 0.19828391223307773,
474+
'shaded_fraction_front': 0.035915234551783914,
475+
'poa_back': 6.2539983668426,
476+
'poa_back_direct': 0.0,
477+
'poa_back_diffuse': 6.2539983668426,
478+
'poa_back_sky_diffuse': 2.252428300348958,
479+
'poa_back_ground_diffuse': 4.001570066493642,
480+
'shaded_fraction_back': 0.035915234551784025}),
481+
('perez', {
482+
'poa_front': 1060.3368384162613,
483+
'poa_front_direct': 945.5770264984124,
484+
'poa_front_diffuse': 114.75981191784896,
485+
'poa_front_sky_diffuse': 114.26297537137229,
486+
'poa_front_ground_diffuse': 0.4968365464766687,
487+
'shaded_fraction_front': 0.035915234551783914,
488+
'poa_back': 15.670534816764919,
489+
'poa_back_direct': 0.0,
490+
'poa_back_diffuse': 15.670534816764919,
491+
'poa_back_sky_diffuse': 5.643870374194696,
492+
'poa_back_ground_diffuse': 10.026664442570222,
493+
'shaded_fraction_back': 0.035915234551784025})
494+
])
492495
def test_get_irradiance_regression(model, expected, ants_params_fixed):
493496
# values computed for typical but arbitrary inputs, to verify that output
494497
# is stable over time

0 commit comments

Comments
 (0)