Skip to content

Commit 00d0689

Browse files
Merge branch 'bugfix/2568-output-fenceposting' of github.com:Parcels-Code/Parcels into bugfix/2568-output-fenceposting
2 parents 9fb895c + 626675c commit 00d0689

2 files changed

Lines changed: 32 additions & 36 deletions

File tree

src/parcels/_datasets/unstructured/generic.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def _icon_square_delaunay_uniform_z_coordinate():
404404

405405
return ux.UxDataset({"U": u, "V": v, "W": w, "p": p}, uxgrid=uxgrid)
406406

407+
407408
def _ux_constant_flow_face_centered_2D():
408409
NX = 10
409410
NT = 2
@@ -412,39 +413,51 @@ def _ux_constant_flow_face_centered_2D():
412413
np.linspace(0, 20, NX, dtype=np.float64),
413414
)
414415
lon_flat, lat_flat = lon.ravel(), lat.ravel()
415-
mask = (
416-
np.isclose(lon_flat, 0) | np.isclose(lon_flat, 20)
417-
| np.isclose(lat_flat, 0) | np.isclose(lat_flat, 20)
418-
)
416+
mask = np.isclose(lon_flat, 0) | np.isclose(lon_flat, 20) | np.isclose(lat_flat, 0) | np.isclose(lat_flat, 20)
419417
uxgrid = ux.Grid.from_points(
420418
(lon_flat, lat_flat),
421419
method="regional_delaunay",
422420
boundary_points=np.flatnonzero(mask),
423421
)
424422
uxgrid.attrs["Conventions"] = "UGRID-1.0"
425-
423+
426424
# --- Uniform velocity field on face centers ---
427425
U0 = 0.001 # degrees/s
428426
V0 = 0.0
429427
TIME = xr.date_range("2000-01-01", periods=NT, freq="1h")
430428
zf = np.array([0.0, 1.0])
431429
zc = np.array([0.5])
432-
430+
433431
U = np.full((NT, 1, uxgrid.n_face), U0)
434432
V = np.full((NT, 1, uxgrid.n_face), V0)
435433
W = np.zeros((NT, 2, uxgrid.n_node))
436-
437-
ds = ux.UxDataset({
438-
"U": ux.UxDataArray(U, uxgrid=uxgrid, dims=["time", "zc", "n_face"],
439-
coords=dict(time=(["time"], TIME), zc=(["zc"], zc)),
440-
attrs=dict(location="face", mesh="delaunay", Conventions="UGRID-1.0")),
441-
"V": ux.UxDataArray(V, uxgrid=uxgrid, dims=["time", "zc", "n_face"],
442-
coords=dict(time=(["time"], TIME), zc=(["zc"], zc)),
443-
attrs=dict(location="face", mesh="delaunay", Conventions="UGRID-1.0")),
444-
"W": ux.UxDataArray(W, uxgrid=uxgrid, dims=["time", "zf", "n_node"],
445-
coords=dict(time=(["time"], TIME), nz=(["zf"], zf)),
446-
attrs=dict(location="node", mesh="delaunay", Conventions="UGRID-1.0")),
447-
}, uxgrid=uxgrid)
434+
435+
ds = ux.UxDataset(
436+
{
437+
"U": ux.UxDataArray(
438+
U,
439+
uxgrid=uxgrid,
440+
dims=["time", "zc", "n_face"],
441+
coords=dict(time=(["time"], TIME), zc=(["zc"], zc)),
442+
attrs=dict(location="face", mesh="delaunay", Conventions="UGRID-1.0"),
443+
),
444+
"V": ux.UxDataArray(
445+
V,
446+
uxgrid=uxgrid,
447+
dims=["time", "zc", "n_face"],
448+
coords=dict(time=(["time"], TIME), zc=(["zc"], zc)),
449+
attrs=dict(location="face", mesh="delaunay", Conventions="UGRID-1.0"),
450+
),
451+
"W": ux.UxDataArray(
452+
W,
453+
uxgrid=uxgrid,
454+
dims=["time", "zf", "n_node"],
455+
coords=dict(time=(["time"], TIME), nz=(["zf"], zf)),
456+
attrs=dict(location="node", mesh="delaunay", Conventions="UGRID-1.0"),
457+
),
458+
},
459+
uxgrid=uxgrid,
460+
)
448461
return ds
449462

450463

tests/test_uxadvection.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
import numpy as np
22
import pytest
3-
import xarray as xr
43

54
import parcels
6-
from parcels import (
7-
Field,
8-
FieldSet,
9-
Particle,
10-
ParticleFile,
11-
ParticleSet,
12-
StatusCode,
13-
Variable,
14-
VectorField,
15-
UxGrid,
16-
convert,
17-
)
18-
from parcels._core.utils.time import timedelta_to_float
195
from parcels._datasets.unstructured.generic import datasets as datasets_unstructured
20-
216
from parcels.kernels import (
227
AdvectionEE,
238
AdvectionRK2,
249
AdvectionRK4,
2510
)
26-
from tests.utils import DEFAULT_PARTICLES
2711

2812

29-
@pytest.mark.parametrize("integrator", [AdvectionEE, AdvectionRK2,AdvectionRK4])
13+
@pytest.mark.parametrize("integrator", [AdvectionEE, AdvectionRK2, AdvectionRK4])
3014
def test_ux_constant_flow_face_centered_2D(integrator):
3115
ds = datasets_unstructured["ux_constant_flow_face_centered_2D"]
3216
T = np.timedelta64(3600, "s")
@@ -39,4 +23,3 @@ def test_ux_constant_flow_face_centered_2D(integrator):
3923
pset.execute(integrator, runtime=T, dt=dt, output_file=pfile, verbose_progress=False)
4024
expected_lon = 8.6
4125
np.testing.assert_allclose(pset.lon, expected_lon, atol=1e-5)
42-

0 commit comments

Comments
 (0)