Skip to content

Commit 027ecce

Browse files
committed
Review edits
1 parent 1e4a8b1 commit 027ecce

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

tests/test_interpolation.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import xarray as xr
44

55
import parcels._interpolation as interpolation
6-
from parcels import AdvectionRK4_3D, JITParticle, ParticleSet, ScipyParticle
6+
from parcels import AdvectionRK4_3D, FieldSet, JITParticle, ParticleSet, ScipyParticle
77
from tests.utils import create_fieldset_zeros_3d
88

99

@@ -50,6 +50,29 @@ def create_interpolation_data():
5050
return xr.DataArray([spatial_data, spatial_data, spatial_data], dims=("time", "depth", "lat", "lon"))
5151

5252

53+
def create_interpolation_data_with_land():
54+
tdim, zdim, ydim, xdim = 20, 5, 10, 10
55+
ds = xr.Dataset(
56+
{
57+
"U": (("time", "depth", "lat", "lon"), np.random.random((tdim, zdim, ydim, xdim))),
58+
"V": (("time", "depth", "lat", "lon"), np.random.random((tdim, zdim, ydim, xdim))),
59+
"W": (("time", "depth", "lat", "lon"), np.random.random((tdim, zdim, ydim, xdim))),
60+
},
61+
coords={
62+
"time": np.linspace(0, tdim - 1, tdim),
63+
"depth": np.linspace(0, 1, zdim),
64+
"lat": np.linspace(0, 1, ydim),
65+
"lon": np.linspace(0, 1, xdim),
66+
},
67+
)
68+
# Set a land point (for testing freeslip)
69+
ds["U"][:, :, 2, 5] = 0.0
70+
ds["V"][:, :, 2, 5] = 0.0
71+
ds["W"][:, :, 2, 5] = 0.0
72+
73+
return ds
74+
75+
5376
@pytest.fixture
5477
def data_2d():
5578
"""2D slice of the reference data at depth=0."""
@@ -131,12 +154,11 @@ def test_interpolator2(ctx: interpolation.InterpolationContext3D):
131154
@pytest.mark.parametrize("interp_method", ["linear", "freeslip", "nearest", "cgrid_velocity"])
132155
def test_scipy_vs_jit(interp_method):
133156
"""Test that the scipy and JIT versions of the interpolation are the same."""
134-
fieldset = create_fieldset_zeros_3d()
135-
# Randomize the field data and set the interpolation method
136-
rng = np.random.default_rng(1636)
137-
for field in [fieldset.U, fieldset.V, fieldset.W]:
138-
field.data = rng.random(fieldset.U.data.shape, dtype=np.float32)
139-
field.data[:, 3, 2, 5] = 0.0 # Set a land point (for testing freeslip)
157+
variables = {"U": "U", "V": "V", "W": "W"}
158+
dimensions = {"time": "time", "lon": "lon", "lat": "lat", "depth": "depth"}
159+
fieldset = FieldSet.from_xarray_dataset(create_interpolation_data_with_land(), variables, dimensions, mesh="flat")
160+
161+
for field in [fieldset.U, fieldset.V, fieldset.W]: # Set a land point (for testing freeslip)
140162
field.interp_method = interp_method
141163

142164
x, y, z = np.meshgrid(np.linspace(0, 1, 7), np.linspace(0, 1, 13), np.linspace(0, 1, 5))

0 commit comments

Comments
 (0)