Skip to content

Commit 9bf9360

Browse files
committed
sprinkle in some dels
1 parent 0d80d7d commit 9bf9360

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pvlib/bifacial/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def _vf_ground_sky_2d(x, rotation, gcr, pitch, height, max_rows=10):
128128
is the starting angle of each wedge, ``wedge_angles[1,:,:,:]`` is the
129129
end angle. [degree]
130130
"""
131+
# This function creates large float64 arrays of size
132+
# (2*len(x)*len(rotation)*len(max_rows)) or ~100 MB for
133+
# typical time series inputs. This function uses `del` to
134+
# allow python to recapture intermediate variables and
135+
# reduce peak memory usage.
136+
131137
# handle floats:
132138
x = np.atleast_1d(x)[:, np.newaxis, np.newaxis]
133139
rotation = np.atleast_1d(rotation)[np.newaxis, :, np.newaxis]
@@ -136,19 +142,30 @@ def _vf_ground_sky_2d(x, rotation, gcr, pitch, height, max_rows=10):
136142
distance_to_row_centers = (all_k - x) * pitch
137143
dy = width * sind(rotation)
138144
dx = width * cosd(rotation)
145+
139146
# angles from x to right edge of each row
140147
a1 = height + dy
141148
b1 = distance_to_row_centers + dx
142149
phi_1 = np.arctan2(a1, b1) # dimensions: (x, rotation, row)
150+
del a1, b1 # reduce max memory usage
151+
143152
# angles from x to left edge of each row
144153
a2 = height - dy
145154
b2 = distance_to_row_centers - dx
146155
phi_2 = np.arctan2(a2, b2) # dimensions: (x, rotation, row)
156+
del a2, b2 # reduce max memory usage
157+
147158
phi = np.stack([phi_1, phi_2]) # dimensions: (row edge, x, rotation, row)
148159
swap = phi_1 > phi_2
160+
del phi_1, phi_2 # reduce max memory usage
161+
149162
# swap where phi_1 > phi_2 so that phi[0,:,:,:] is the lesser angle
150163
phi = np.where(swap, phi[::-1], phi)
164+
del swap # reduce max memory usage
165+
151166
# right edge of next row - left edge of previous row
152167
wedge_vfs = 0.5 * (np.cos(phi[1, :, :, 1:]) - np.cos(phi[0, :, :, :-1]))
153168
vf = np.sum(np.clip(wedge_vfs, a_min=0., a_max=None), axis=-1)
169+
del wedge_vfs # reduce max memory usage
170+
154171
return vf, np.degrees(phi)

0 commit comments

Comments
 (0)