Skip to content

Commit aad5481

Browse files
committed
[Hotfix] Fix ICON masking
1 parent 76c2dbd commit aad5481

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

examples/basic_triangular_mesh.ipynb

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

src/implicit_filter/icon_filter.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def prepare_from_data_array(
5151
Metric terms inclusion flag (default: False).
5252
mask : np.ndarray | bool, optional
5353
Land-sea mask specification:
54-
- np.ndarray: Precomputed mask array
54+
- np.ndarray: Precomputed mask array where true is ocean
5555
- True: Auto-detect from 'cell_sea_land_mask'
5656
- False: All ocean cells (default)
5757
gpu : bool, optional
@@ -74,17 +74,19 @@ def prepare_from_data_array(
7474
ycoord = grid2d["vlat"].values * 180.0 / np.pi # Location of nodes, in degrees
7575
tri = grid2d["vertex_of_cell"].values.T.astype(int) - 1
7676
tri = tri.astype(int)
77-
mask_transform = False
7877

7978
if isinstance(mask, np.ndarray):
8079
pass
8180
elif mask:
8281
if "cell_sea_land_mask" in grid2d:
83-
mask = grid2d["cell_sea_land_mask"].values
84-
mask_transform = True
82+
mask = grid2d["cell_sea_land_mask"].values * -1
83+
mask[mask == 2] = 1
84+
mask[mask == -2] = -1
85+
mask = grid2d["cell_sea_land_mask"].values * -1
86+
mask = mask.astype(np.bool)
8587
else:
8688
raise KeyError(
87-
f"In the file {grid_file} there's no ocean mask under default name {'cell_sea_land_mask'}"
89+
f"In the file grid file there's no ocean mask under default name 'cell_sea_land_mask'"
8890
)
8991
else:
9092
mask = np.ones(len(tri[:, 1]))

src/implicit_filter/triangular_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def prepare(
250250
cartesian: bool = True,
251251
cyclic_length: float = 360.0 * pi / 180.0,
252252
full: bool = False,
253-
mask: np.ndarray = None,
253+
mask: np.ndarray | None = None,
254254
gpu: bool = False,
255255
):
256256
"""
@@ -280,7 +280,7 @@ def prepare(
280280
full : bool, optional
281281
True to include metric terms in operator (default: False).
282282
mask : np.ndarray, optional
283-
Element mask where True indicates land (default: all ocean).
283+
Element mask where True indicates ocean (default: all ocean).
284284
gpu : bool, optional
285285
True to enable GPU acceleration (default: False).
286286

0 commit comments

Comments
 (0)