Skip to content

Commit

Permalink
Merge pull request #217 from NREL/gb/regrid_speed
Browse files Browse the repository at this point in the history
fix performance issue with slow listcomp on regrid indexing
  • Loading branch information
grantbuster authored Jun 5, 2024
2 parents 54b7176 + 5b765eb commit 4eb5022
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sup3r/utilities/regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ def __call__(self, data):
data = data.reshape((data.shape[0] * data.shape[1], -1))
msg = 'Input data must be 2D (spatial, temporal)'
assert len(data.shape) == 2, msg
vals = [
data[np.array(self.indices), i][np.newaxis]
for i in range(data.shape[-1])
]
vals = np.concatenate(vals, axis=0)
return np.einsum('ijk,jk->ij', vals, self.weights).T

vals = data[np.array(self.indices), :] # index to (space, 4, time)
vals = np.transpose(vals, (2, 0, 1)) # shuffle to (time, space, 4)

out = np.einsum('ijk,jk->ij', vals, self.weights).T
return out


class WindRegridder(Regridder):
Expand Down

0 comments on commit 4eb5022

Please sign in to comment.