Skip to content

Commit

Permalink
got blockwise operations working with _lin_interp. squeaking out a li…
Browse files Browse the repository at this point in the history
…ttle more speed.
  • Loading branch information
bnb32 committed Nov 4, 2024
1 parent 3f8802f commit b8d75ec
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions sup3r/utilities/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,22 @@ def get_level_masks(cls, lev_array, level):
@classmethod
def _lin_interp(cls, lev_samps, var_samps, level):
"""Linearly interpolate between levels."""
diff = lev_samps[1] - lev_samps[0]
alpha = da.where(diff == 0, 0, (level - lev_samps[0]) / diff)
return var_samps[0] * (1 - alpha) + var_samps[1] * alpha
diff = da.map_blocks(lambda x, y: x - y, lev_samps[1], lev_samps[0])
alpha = da.where(
diff == 0,
0,
da.map_blocks(lambda x, y: x / y, (level - lev_samps[0]), diff),
)
return da.blockwise(
lambda x, y, a: x * (1 - a) + y * a,
'ijk',
var_samps[0],
'ijk',
var_samps[1],
'ijk',
alpha,
'ijk',
)

@classmethod
def _log_interp(cls, lev_samps, var_samps, level):
Expand Down

0 comments on commit b8d75ec

Please sign in to comment.