Skip to content

Commit c311fba

Browse files
Fixing applyConversion for VectorFields
1 parent 39e2b1b commit c311fba

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

parcels/_core/field.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,26 +312,18 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
312312
w = self.W._interp_method(self.W, ti, position, tau, time, z, y, x)
313313
else:
314314
w = 0.0
315-
316-
if applyConversion:
317-
u = self.U.units.to_target(u, z, y, x)
318-
v = self.V.units.to_target(v, z, y, x)
319-
320315
else:
321316
(u, v, w) = self._vector_interp_method(self, ti, position, tau, time, z, y, x)
322-
if applyConversion and self.grid._mesh == "spherical":
323-
deg2m = 1852 * 60.0
324-
meshJac = deg2m * deg2m * np.cos(np.deg2rad(y))
325-
u = u / meshJac
326-
v = v / meshJac
327-
print(u, v)
317+
318+
if applyConversion:
319+
u = self.U.units.to_target(u, z, y, x)
320+
v = self.V.units.to_target(v, z, y, x)
321+
if "3D" in self.vector_type:
322+
w = self.W.units.to_target(w, z, y, x)
328323

329324
for vel in (u, v, w):
330325
_update_particle_states_interp_value(particles, vel)
331326

332-
if applyConversion and ("3D" in self.vector_type):
333-
w = self.W.units.to_target(w, z, y, x) if self.W else 0.0
334-
335327
if "3D" in self.vector_type:
336328
return (u, v, w)
337329
else:

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])

0 commit comments

Comments
 (0)