Skip to content

Commit bb32273

Browse files
Fixing bug where velocities in Peninsula on C-grid were calculated wrongly
1 parent 57fafe0 commit bb32273

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/examples/example_peninsula.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ def peninsula_fieldset(xdim, ydim, mesh="flat", grid_type="A"):
5959
x, y = np.meshgrid(La, Wa, sparse=True, indexing="xy")
6060
P = (u0 * R**2 * y / ((x - x0) ** 2 + y**2) - u0 * y) / 1e3
6161

62+
# Set land points to zero
63+
landpoints = P >= 0.0
64+
P[landpoints] = 0.0
65+
6266
if grid_type == "A":
6367
U = u0 - u0 * R**2 * ((x - x0) ** 2 - y**2) / (((x - x0) ** 2 + y**2) ** 2)
6468
V = -2 * u0 * R**2 * ((x - x0) * y) / (((x - x0) ** 2 + y**2) ** 2)
69+
U[landpoints] = 0.0
70+
V[landpoints] = 0.0
6571
elif grid_type == "C":
6672
U = np.zeros(P.shape)
6773
V = np.zeros(P.shape)
68-
V[:, 1:] = P[:, 1:] - P[:, :-1]
69-
U[1:, :] = -(P[1:, :] - P[:-1, :])
74+
V[:, 1:] = (P[:, 1:] - P[:, :-1]) / (La[1] - La[0]) * 1e3
75+
U[1:, :] = -(P[1:, :] - P[:-1, :]) / (Wa[1] - Wa[0]) * 1e3
7076
else:
7177
raise RuntimeError(f"Grid_type {grid_type} is not a valid option")
7278

73-
# Set land points to NaN
74-
landpoints = P >= 0.0
75-
P[landpoints] = np.nan
76-
U[landpoints] = np.nan
77-
V[landpoints] = np.nan
78-
7979
# Convert from m to lat/lon for spherical meshes
8080
lon = La / 1852.0 / 60.0 if mesh == "spherical" else La
8181
lat = Wa / 1852.0 / 60.0 if mesh == "spherical" else Wa

0 commit comments

Comments
 (0)