Skip to content

Commit d877d8e

Browse files
committed
Move interpolation call
Try block should only have retrieving the function, not its execution
1 parent 413e66a commit d877d8e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

parcels/field.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,14 +1241,15 @@ def _interpolator2D(self, ti, z, y, x, particle=None):
12411241
ctx = InterpolationContext2D(self.data, eta, xsi, ti, yi, xi)
12421242

12431243
try:
1244-
return interpolator_registry_2d[self.interp_method](ctx)
1244+
f = interpolator_registry_2d[self.interp_method]
12451245
except KeyError:
12461246
if self.interp_method == "cgrid_velocity":
12471247
raise RuntimeError(
12481248
f"{self.name} is a scalar field. cgrid_velocity interpolation method should be used for vector fields (e.g. FieldSet.UV)"
12491249
)
12501250
else:
12511251
raise RuntimeError(self.interp_method + " is not implemented for 2D grids")
1252+
return f(ctx)
12521253

12531254
@deprecated_made_private # TODO: Remove 6 months after v3.1.0
12541255
def interpolator3D(self, *_):
@@ -1260,9 +1261,10 @@ def _interpolator3D(self, ti, z, y, x, time, particle=None):
12601261
ctx = InterpolationContext3D(self.data, zeta, eta, xsi, ti, zi, yi, xi, self.gridindexingtype)
12611262

12621263
try:
1263-
return interpolator_registry_3d[self.interp_method](ctx)
1264+
f = interpolator_registry_3d[self.interp_method]
12641265
except KeyError:
12651266
raise RuntimeError(self.interp_method + " is not implemented for 3D grids")
1267+
return f(ctx)
12661268

12671269
def temporal_interpolate_fullfield(self, ti, time):
12681270
"""Calculate the data of a field between two snapshots using linear interpolation.

0 commit comments

Comments
 (0)