Skip to content

Commit 4502c12

Browse files
implementing time-interpolation in _linear_3d
1 parent 722fecd commit 4502c12

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

parcels/_interpolation.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,17 @@ def _z_layer_interp(
274274
@register_3d_interpolator("linear")
275275
@register_3d_interpolator("partialslip")
276276
@register_3d_interpolator("freeslip")
277-
def _linear_3d(ctx: InterpolationContext3D) -> float: # TODO make time-varying
277+
def _linear_3d(ctx: InterpolationContext3D) -> float:
278278
zdim = ctx.data.shape[1]
279279
data_3d = ctx.data[ctx.ti, :, :, :]
280-
f0, f1 = _get_3d_f0_f1(eta=ctx.eta, xsi=ctx.xsi, data=data_3d, zi=ctx.zi, yi=ctx.yi, xi=ctx.xi)
281-
282-
return _z_layer_interp(zeta=ctx.zeta, f0=f0, f1=f1, zi=ctx.zi, zdim=zdim, gridindexingtype=ctx.gridindexingtype)
280+
fz0, fz1 = _get_3d_f0_f1(eta=ctx.eta, xsi=ctx.xsi, data=data_3d, zi=ctx.zi, yi=ctx.yi, xi=ctx.xi)
281+
if ctx.tau > EPS and ctx.ti < ctx.data.shape[0] - 1:
282+
data_3d = ctx.data[ctx.ti + 1, :, :, :]
283+
fz0_t1, fz1_t1 = _get_3d_f0_f1(eta=ctx.eta, xsi=ctx.xsi, data=data_3d, zi=ctx.zi, yi=ctx.yi, xi=ctx.xi)
284+
fz0 = (1 - ctx.tau) * fz0 + ctx.tau * fz0_t1
285+
fz1 = (1 - ctx.tau) * fz1 + ctx.tau * fz1_t1
286+
287+
return _z_layer_interp(zeta=ctx.zeta, f0=fz0, f1=fz1, zi=ctx.zi, zdim=zdim, gridindexingtype=ctx.gridindexingtype)
283288

284289

285290
@register_3d_interpolator("bgrid_velocity")

tests/test_interpolation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def data_2d():
6868
)
6969
def test_raw_2d_interpolation(data_2d, func, eta, xsi, expected):
7070
"""Test the 2D interpolation functions on the raw arrays."""
71-
ti = 0
71+
tau, ti = 0, 0
7272
yi, xi = 1, 1
73-
ctx = interpolation.InterpolationContext2D(data_2d, eta, xsi, ti, yi, xi)
73+
ctx = interpolation.InterpolationContext2D(data_2d, tau, eta, xsi, ti, yi, xi)
7474
assert func(ctx) == expected
7575

7676

0 commit comments

Comments
 (0)