Skip to content

Commit 4eb5022

Browse files
authored
Merge pull request #217 from NREL/gb/regrid_speed
fix performance issue with slow listcomp on regrid indexing
2 parents 54b7176 + 5b765eb commit 4eb5022

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sup3r/utilities/regridder.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ def __call__(self, data):
390390
data = data.reshape((data.shape[0] * data.shape[1], -1))
391391
msg = 'Input data must be 2D (spatial, temporal)'
392392
assert len(data.shape) == 2, msg
393-
vals = [
394-
data[np.array(self.indices), i][np.newaxis]
395-
for i in range(data.shape[-1])
396-
]
397-
vals = np.concatenate(vals, axis=0)
398-
return np.einsum('ijk,jk->ij', vals, self.weights).T
393+
394+
vals = data[np.array(self.indices), :] # index to (space, 4, time)
395+
vals = np.transpose(vals, (2, 0, 1)) # shuffle to (time, space, 4)
396+
397+
out = np.einsum('ijk,jk->ij', vals, self.weights).T
398+
return out
399399

400400

401401
class WindRegridder(Regridder):

0 commit comments

Comments
 (0)