Skip to content

Commit 7798fdd

Browse files
committed
Quhall error fix
1 parent 63bf266 commit 7798fdd

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

mhkit/river/io/d3d.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,34 @@ def variable_interpolation(
650650

651651
if not isinstance(to_pandas, bool):
652652
raise TypeError(f"to_pandas must be of type bool. Got: {type(to_pandas)}")
653+
654+
#Avoid Quhall errors by filling in bad sigma values with -1 for the surface or 0 for the waterbed based on neighboring values
655+
if "mesh2d_interface_sigma" in data.variables:
656+
sigma = data["mesh2d_interface_sigma"].values
657+
bad = ~np.isfinite(sigma) | (np.abs(sigma) > 0.1)
658+
if bad.any():
659+
# Check neighboring values to determine if sigma should be -1 or 0
660+
for idx in np.where(bad)[0]:
661+
neighbors = []
662+
if idx > 0:
663+
neighbors.append(sigma[idx - 1])
664+
if idx < len(sigma) - 1:
665+
neighbors.append(sigma[idx + 1])
666+
667+
if neighbors:
668+
avg_neighbor = np.mean(neighbors)
669+
if np.abs(avg_neighbor - (-1.0)) < np.abs(avg_neighbor):
670+
sigma[idx] = -1.0
671+
else:
672+
sigma[idx] = 0.0
673+
else:
674+
sigma[idx] = -1.0
675+
676+
data["mesh2d_interface_sigma"] = xr.DataArray(
677+
sigma,
678+
dims=data["mesh2d_interface_sigma"].dims,
679+
attrs=data["mesh2d_interface_sigma"].attrs,
680+
)
653681

654682
data_raw = {}
655683
for var in variables:

0 commit comments

Comments
 (0)