Skip to content

Commit 0e2066c

Browse files
Merge pull request #935 from trhille/fix_grounding_line_mask
Fix grounding line mask definition when creating landice meshes This merge fixes grounding line mask definition, which previously marked the entire ocean as the grounding line used for setting cell widths. It also saves maps of the margin and grounding-line masks, which will be helpful for debugging purposes when new maps are added or mask definitions are changed.
2 parents 71ea7cf + dc22f87 commit 0e2066c

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

compass/landice/mesh.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from shutil import copyfile
77

88
import jigsawpy
9+
import matplotlib.pyplot as plt
910
import mpas_tools.io
1011
import numpy as np
1112
import xarray
@@ -514,23 +515,36 @@ def get_dist_to_edge_and_gl(self, thk, topg, x, y,
514515
[1, 1], [-1, 1], [1, -1], [-1, -1]])
515516

516517
ice_mask = thk > 0.0
517-
grounded_mask = thk > (-1028.0 / 910.0 * topg)
518+
grounded_mask = np.logical_and(thk > (-1028.0 / 910.0 * topg),
519+
ice_mask)
520+
float_mask = np.logical_and(thk < (-1028.0 / 910.0 * topg),
521+
ice_mask)
518522
margin_mask = np.zeros(sz, dtype='i')
519523
grounding_line_mask = np.zeros(sz, dtype='i')
520524

521525
for n in neighbors:
522-
not_ice_mask = np.logical_not(np.roll(ice_mask, n, axis=[0, 1]))
523-
margin_mask = np.logical_or(margin_mask, not_ice_mask)
526+
shifted_ice = np.roll(ice_mask, n, axis=[0, 1])
527+
margin_mask = np.logical_or(margin_mask, ~shifted_ice)
524528

525-
not_grounded_mask = np.logical_not(np.roll(grounded_mask,
526-
n, axis=[0, 1]))
529+
shifted_grounded = np.roll(grounded_mask, n, axis=[0, 1])
530+
shifted_float = np.roll(float_mask, n, axis=[0, 1])
531+
not_grounded_mask = (~shifted_grounded) & shifted_float
527532
grounding_line_mask = np.logical_or(grounding_line_mask,
528533
not_grounded_mask)
529534

530535
# where ice exists and neighbors non-ice locations
531536
margin_mask = np.logical_and(margin_mask, ice_mask)
532-
# optional - plot mask
533-
# plt.pcolor(margin_mask); plt.show()
537+
# where grounded ice exists and neighbors floating ice
538+
grounding_line_mask = np.logical_and(grounding_line_mask, grounded_mask)
539+
540+
fig, ax = plt.subplots(1, 2, sharex=True, sharey=True, figsize=(6, 3))
541+
margin_plot = ax[0].pcolor(margin_mask)
542+
gl_plot = ax[1].pcolor(grounding_line_mask) # noqa F841
543+
ax[0].set_title("margin mask")
544+
ax[1].set_title("grounding line mask")
545+
plt.colorbar(margin_plot, ax=[ax[0], ax[1]], shrink=0.7)
546+
[ax.set_aspect('equal') for ax in ax]
547+
fig.savefig("masks.png", dpi=400)
534548

535549
# Calculate dist to margin and grounding line
536550
[XPOS, YPOS] = np.meshgrid(x, y)

0 commit comments

Comments
 (0)