Skip to content

Commit b678ccd

Browse files
Removing applyConversion option from field.eval
Keeping it only for VectorField.eval()
1 parent aa16654 commit b678ccd

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

docs/user_guide/v4-migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Version 4 of Parcels is unreleased at the moment. The information in this migrat
3939

4040
- `Field.eval()` returns an array of floats instead of a single float (related to the vectorization)
4141
- `Field.eval()` does not throw OutOfBounds or other errors
42+
- `applyConversion` has been renamed to `apply_conversion` and only works for VectorFields. Conversion of units should be handled in Kernels.
4243

4344
## GridSet
4445

src/parcels/_core/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _check_velocitysampling(self):
177177
stacklevel=2,
178178
)
179179

180-
def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
180+
def eval(self, time: datetime, z, y, x, particles=None):
181181
"""Interpolate field values in space and time.
182182
183183
We interpolate linearly in time and apply implicit unit

tests/test_field.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,31 +201,31 @@ def test_field_unstructured_z_linear():
201201

202202
# Test above first cell center - for piecewise constant, should return the depth of the first cell center
203203
assert np.isclose(
204-
P.eval(time=[0], z=[10.0], y=[30.0], x=[30.0], applyConversion=False),
204+
P.eval(time=[0], z=[10.0], y=[30.0], x=[30.0]),
205205
55.555557,
206206
)
207207
# Test below first cell center, but in the first layer - for piecewise constant, should return the depth of the first cell center
208208
assert np.isclose(
209-
P.eval(time=[0], z=[65.0], y=[30.0], x=[30.0], applyConversion=False),
209+
P.eval(time=[0], z=[65.0], y=[30.0], x=[30.0]),
210210
55.555557,
211211
)
212212
# Test bottom layer - for piecewise constant, should return the depth of the of the bottom layer cell center
213213
assert np.isclose(
214-
P.eval(time=[0], z=[900.0], y=[30.0], x=[30.0], applyConversion=False),
214+
P.eval(time=[0], z=[900.0], y=[30.0], x=[30.0]),
215215
944.44445801,
216216
)
217217

218218
W = Field(name="W", data=ds.W, grid=grid, interp_method=UxPiecewiseLinearNode)
219219
assert np.isclose(
220-
W.eval(time=[0], z=[10.0], y=[30.0], x=[30.0], applyConversion=False),
220+
W.eval(time=[0], z=[10.0], y=[30.0], x=[30.0]),
221221
10.0,
222222
)
223223
assert np.isclose(
224-
W.eval(time=[0], z=[65.0], y=[30.0], x=[30.0], applyConversion=False),
224+
W.eval(time=[0], z=[65.0], y=[30.0], x=[30.0]),
225225
65.0,
226226
)
227227
assert np.isclose(
228-
W.eval(time=[0], z=[900.0], y=[30.0], x=[30.0], applyConversion=False),
228+
W.eval(time=[0], z=[900.0], y=[30.0], x=[30.0]),
229229
900.0,
230230
)
231231

@@ -239,13 +239,12 @@ def test_field_constant_in_time():
239239

240240
# Assert that the field can be evaluated at any time, and returns the same value
241241
time = np.datetime64("2000-01-01T00:00:00")
242-
P1 = P.eval(time=time, z=[10.0], y=[30.0], x=[30.0], applyConversion=False)
242+
P1 = P.eval(time=time, z=[10.0], y=[30.0], x=[30.0])
243243
P2 = P.eval(
244244
time=time + np.timedelta64(1, "D"),
245245
z=[10.0],
246246
y=[30.0],
247247
x=[30.0],
248-
applyConversion=False,
249248
)
250249
assert np.isclose(P1, P2)
251250

tests/test_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_interpolation_mesh_type(mesh, npart=10):
176176
time = 0.0
177177
u_expected = 1.0 if mesh == "flat" else 1.0 / (1852 * 60 * np.cos(np.radians(lat)))
178178

179-
assert fieldset.U.eval(time, 0, lat, 0, applyConversion=False) == 1.0
179+
assert fieldset.U.eval(time, 0, lat, 0) == 1.0
180180
assert fieldset.V[time, 0, lat, 0] == 0.0
181181

182182
u, v = fieldset.UV[time, 0, lat, 0]

tests/test_uxarray_fieldset.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,29 @@ def test_fesom2_square_delaunay_uniform_z_coordinate_eval():
122122
P = Field(name="p", data=ds.p, grid=grid, interp_method=UxPiecewiseLinearNode)
123123
fieldset = FieldSet([UVW, P, UVW.U, UVW.V, UVW.W])
124124

125+
(u, v, w) = fieldset.UVW.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0], applyConversion=False)
126+
assert np.allclose([u.item(), v.item(), w.item()], [1.0, 1.0, 0.0], rtol=1e-3, atol=1e-6)
127+
125128
assert np.isclose(
126-
fieldset.U.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0], applyConversion=False),
129+
fieldset.U.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0]),
127130
1.0,
128131
rtol=1e-3,
129132
atol=1e-6,
130133
)
131134
assert np.isclose(
132-
fieldset.V.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0], applyConversion=False),
135+
fieldset.V.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0]),
133136
1.0,
134137
rtol=1e-3,
135138
atol=1e-6,
136139
)
137140
assert np.isclose(
138-
fieldset.W.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0], applyConversion=False),
141+
fieldset.W.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0]),
139142
0.0,
140143
rtol=1e-3,
141144
atol=1e-6,
142145
)
143146
assert np.isclose(
144-
fieldset.p.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0], applyConversion=False),
147+
fieldset.p.eval(time=[0.0], z=[1.0], y=[30.0], x=[30.0]),
145148
1.0,
146149
rtol=1e-3,
147150
atol=1e-6,
@@ -163,7 +166,7 @@ def test_fesom2_square_delaunay_antimeridian_eval():
163166
)
164167
fieldset = FieldSet([P])
165168

166-
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[-170.0], applyConversion=False), 1.0)
167-
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[-180.0], applyConversion=False), 1.0)
168-
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[180.0], applyConversion=False), 1.0)
169-
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[170.0], applyConversion=False), 1.0)
169+
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[-170.0]), 1.0)
170+
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[-180.0]), 1.0)
171+
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[180.0]), 1.0)
172+
assert np.isclose(fieldset.p.eval(time=[0], z=[1.0], y=[30.0], x=[170.0]), 1.0)

0 commit comments

Comments
 (0)