Skip to content

Commit 0f98aa6

Browse files
committed
patch indexerror
1 parent 6cbc6e5 commit 0f98aa6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

parcels/_interpolation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,26 @@ def _linear_invdist_land_tracer_3d(ctx: InterpolationContext3D) -> float:
229229
return (1 - ctx.zeta) * f0 + ctx.zeta * f1
230230

231231

232-
def _get_3d_f0_f1(*, eta: float, xsi: float, data: np.ndarray, zi: int, yi: int, xi: int):
232+
def _get_3d_f0_f1(*, eta: float, xsi: float, data: np.ndarray, zi: int, yi: int, xi: int) -> tuple[float, float | None]:
233233
data_2d = data[zi, :, :]
234234
f0 = _unit_square_to_target(eta=eta, xsi=xsi, data=data_2d, yi=yi, xi=xi)
235-
data_2d = data[zi + 1, :, :]
236-
f1 = _unit_square_to_target(eta=eta, xsi=xsi, data=data_2d, yi=yi, xi=xi)
235+
try:
236+
data_2d = data[zi + 1, :, :]
237+
except IndexError:
238+
f1 = None # POP indexing at edge of domain
239+
else:
240+
f1 = _unit_square_to_target(eta=eta, xsi=xsi, data=data_2d, yi=yi, xi=xi)
241+
237242
return f0, f1
238243

239244

240-
def _z_layer_interp(*, zeta: float, f0: float, f1: float, zi: int, zdim: int, gridindexingtype: GridIndexingType):
245+
def _z_layer_interp(
246+
*, zeta: float, f0: float, f1: float | None, zi: int, zdim: int, gridindexingtype: GridIndexingType
247+
):
241248
if gridindexingtype == "pop" and zi >= zdim - 2:
242249
# Since POP is indexed at cell top, allow linear interpolation of W to zero in lowest cell
243250
return (1 - zeta) * f0
251+
assert f1 is not None, "f1 should not be None for gridindexingtype != 'pop'"
244252
if gridindexingtype == "mom5" and zi == -1:
245253
# Since MOM5 is indexed at cell bottom, allow linear interpolation of W to zero in uppermost cell
246254
return zeta * f1

0 commit comments

Comments
 (0)