File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments