Skip to content

Commit 3e484c5

Browse files
Merge pull request #2294 from Parcels-code/removing_applyconversion_from_vectorinterpolation
Removing applyConversion in VectorField API
2 parents aa90e1c + 126088e commit 3e484c5

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

src/parcels/_core/field.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,18 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
316316
w = self.W._interp_method(self.W, ti, position, tau, time, z, y, x)
317317
else:
318318
w = 0.0
319-
320-
if applyConversion:
321-
u = self.U.units.to_target(u, z, y, x)
322-
v = self.V.units.to_target(v, z, y, x)
323-
324319
else:
325-
(u, v, w) = self._vector_interp_method(self, ti, position, tau, time, z, y, x, applyConversion)
320+
(u, v, w) = self._vector_interp_method(self, ti, position, tau, time, z, y, x)
321+
322+
if applyConversion:
323+
u = self.U.units.to_target(u, z, y, x)
324+
v = self.V.units.to_target(v, z, y, x)
325+
if "3D" in self.vector_type:
326+
w = self.W.units.to_target(w, z, y, x)
326327

327328
for vel in (u, v, w):
328329
_update_particle_states_interp_value(particles, vel)
329330

330-
if applyConversion and ("3D" in self.vector_type):
331-
w = self.W.units.to_target(w, z, y, x) if self.W else 0.0
332-
333331
if "3D" in self.vector_type:
334332
return (u, v, w)
335333
else:

src/parcels/interpolators.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def ZeroInterpolator_Vector(
5252
z: np.float32 | np.float64,
5353
y: np.float32 | np.float64,
5454
x: np.float32 | np.float64,
55-
applyConversion: bool,
5655
) -> np.float32 | np.float64:
5756
"""Template function used for the signature check of the interpolation methods for velocity fields."""
5857
return 0.0
@@ -158,7 +157,6 @@ def CGrid_Velocity(
158157
z: np.float32 | np.float64,
159158
y: np.float32 | np.float64,
160159
x: np.float32 | np.float64,
161-
applyConversion: bool,
162160
):
163161
"""
164162
Interpolation kernel for velocity fields on a C-Grid.
@@ -276,11 +274,7 @@ def CGrid_Velocity(
276274
U = (1 - xsi) * U0 + xsi * U1
277275
V = (1 - eta) * V0 + eta * V1
278276

279-
deg2m = 1852 * 60.0
280-
if applyConversion:
281-
meshJac = (deg2m * deg2m * np.cos(np.deg2rad(y))) if grid._mesh == "spherical" else 1
282-
else:
283-
meshJac = deg2m if grid._mesh == "spherical" else 1
277+
meshJac = 1852 * 60.0 if grid._mesh == "spherical" else 1
284278

285279
jac = i_u._compute_jacobian_determinant(py, px, eta, xsi) * meshJac
286280

@@ -533,7 +527,6 @@ def XFreeslip(
533527
z: np.float32 | np.float64,
534528
y: np.float32 | np.float64,
535529
x: np.float32 | np.float64,
536-
applyConversion: bool,
537530
):
538531
"""Free-slip boundary condition interpolation for velocity fields."""
539532
return _Spatialslip(vectorfield, ti, position, tau, t, z, y, x, a=1.0, b=0.0)
@@ -548,7 +541,6 @@ def XPartialslip(
548541
z: np.float32 | np.float64,
549542
y: np.float32 | np.float64,
550543
x: np.float32 | np.float64,
551-
applyConversion: bool,
552544
):
553545
"""Partial-slip boundary condition interpolation for velocity fields."""
554546
return _Spatialslip(vectorfield, ti, position, tau, t, z, y, x, a=0.5, b=0.5)

tests/test_advection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def test_nemo_curvilinear_fieldset():
457457
U = parcels.Field("U", ds["U"], grid)
458458
V = parcels.Field("V", ds["V"], grid)
459459
U.units = parcels.GeographicPolar()
460-
V.units = parcels.Geographic()
460+
V.units = parcels.GeographicPolar() # U and V need GoegraphicPolar for C-Grid interpolation to work correctly
461461
UV = parcels.VectorField("UV", U, V, vector_interp_method=CGrid_Velocity)
462462
fieldset = parcels.FieldSet([U, V, UV])
463463

@@ -543,7 +543,7 @@ def test_nemo_3D_curvilinear_fieldset(method):
543543
V = parcels.Field("V", ds["V"], grid)
544544
W = parcels.Field("W", ds["W"], grid)
545545
U.units = parcels.GeographicPolar()
546-
V.units = parcels.Geographic()
546+
V.units = parcels.GeographicPolar() # U and V need GoegraphicPolar for C-Grid interpolation to work correctly
547547
UV = parcels.VectorField("UV", U, V, vector_interp_method=CGrid_Velocity)
548548
UVW = parcels.VectorField("UVW", U, V, W, vector_interp_method=CGrid_Velocity)
549549
fieldset = parcels.FieldSet([U, V, W, UV, UVW])

tests/test_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_vectorfield_invalid_interpolator():
159159
ds = datasets_structured["ds_2d_left"]
160160
grid = XGrid.from_dataset(ds)
161161

162-
def invalid_interpolator_wrong_signature(self, ti, position, tau, t, z, y, applyConversion, invalid):
162+
def invalid_interpolator_wrong_signature(self, ti, position, tau, t, z, y, invalid):
163163
return 0.0
164164

165165
# Create component fields

0 commit comments

Comments
 (0)