Skip to content

Commit 90e73df

Browse files
[#2031] Add nz coordinate and vertical velocity to stommel gyre example
`nz` coordinate, which is the vertical face locations of the vertical grid are required for the `UxGrid` vertical search
1 parent c973693 commit 90e73df

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

parcels/_datasets/unstructured/generic.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def _stommel_gyre_delaunay():
2424
lon, lat = np.meshgrid(np.linspace(0, 60.0, Nx, dtype=np.float32), np.linspace(0, 60.0, Nx, dtype=np.float32))
2525
lon_flat = lon.ravel()
2626
lat_flat = lat.ravel()
27+
zf = np.linspace(0.0, 1000.0, 2, endpoint=True, dtype=np.float32) # Vertical element faces
28+
zc = 0.5 * (zf[:-1] + zf[1:]) # Vertical element centers
29+
nz = zf.size
30+
nz1 = zc.size
2731

2832
# mask any point on one of the boundaries
2933
mask = (
@@ -40,9 +44,10 @@ def _stommel_gyre_delaunay():
4044
uxgrid.attrs["Conventions"] = "UGRID-1.0"
4145

4246
# Define arrays U (zonal), V (meridional) and P (sea surface height)
43-
U = np.zeros((1, 1, lat.size), dtype=np.float64)
44-
V = np.zeros((1, 1, lat.size), dtype=np.float64)
45-
P = np.zeros((1, 1, lat.size), dtype=np.float64)
47+
U = np.zeros((1, nz1, lat.size), dtype=np.float64)
48+
V = np.zeros((1, nz1, lat.size), dtype=np.float64)
49+
W = np.zeros((1, nz, lat.size), dtype=np.float64)
50+
P = np.zeros((1, nz1, lat.size), dtype=np.float64)
4651

4752
for i, (x, y) in enumerate(zip(lon_flat, lat_flat, strict=False)):
4853
xi = x / 60.0
@@ -72,7 +77,20 @@ def _stommel_gyre_delaunay():
7277
dims=["time", "nz1", "n_node"],
7378
coords=dict(
7479
time=(["time"], [TIME[0]]),
75-
nz1=(["nz1"], [0]),
80+
nz1=(["nz1"], zc),
81+
),
82+
attrs=dict(
83+
description="meridional velocity", units="m/s", location="node", mesh="delaunay", Conventions="UGRID-1.0"
84+
),
85+
)
86+
w = ux.UxDataArray(
87+
data=W,
88+
name="W",
89+
uxgrid=uxgrid,
90+
dims=["time", "nz", "n_node"],
91+
coords=dict(
92+
time=(["time"], [TIME[0]]),
93+
nz=(["nz"], zf),
7694
),
7795
attrs=dict(
7896
description="meridional velocity", units="m/s", location="node", mesh="delaunay", Conventions="UGRID-1.0"
@@ -85,12 +103,12 @@ def _stommel_gyre_delaunay():
85103
dims=["time", "nz1", "n_node"],
86104
coords=dict(
87105
time=(["time"], [TIME[0]]),
88-
nz1=(["nz1"], [0]),
106+
nz1=(["nz1"], zc),
89107
),
90108
attrs=dict(description="pressure", units="N/m^2", location="node", mesh="delaunay", Conventions="UGRID-1.0"),
91109
)
92110

93-
return ux.UxDataset({"U": u, "V": v, "p": p}, uxgrid=uxgrid)
111+
return ux.UxDataset({"U": u, "V": v, "W": w, "p": p}, uxgrid=uxgrid)
94112

95113

96114
def _fesom2_square_delaunay_uniform_z_coordinate():

0 commit comments

Comments
 (0)