Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions mesh_generation/generate_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,31 @@
EARTH_R = 6.37122e6


def mom6_mask_detection(ds, minimum_depth=None, masking_depth=None):
def mom6_mask_detection(ds, minimum_depth=0, masking_depth=None):
"""
Detect and generate an ocean mask (1 = wet, 0 = land) from a topog.nc.
https://github.com/ACCESS-NRI/MOM6/blob/569ba3126835bfcdea5e39c46eeae01938f5413c/src/initialization/MOM_grid_initialize.F90#L1180
"""

# check arguments
if "depth" not in ds:
raise ValueError("Cannot detect topog: dataset lacks 'depth' variable!")
if minimum_depth < 0:
raise ValueError("minimum depth cannot be negative")

depth = ds["depth"]

# topog contains nans
is_wet = ~np.isnan(depth)

if masking_depth is None and minimum_depth is None:
mask = is_wet
elif masking_depth is None:
mask = (depth > minimum_depth) & is_wet
elif minimum_depth is None:
mask = (depth > masking_depth) & is_wet
else:
if masking_depth is not None:
if masking_depth > minimum_depth:
raise ValueError(
"MASKING_DEPTH must be less than or equal to MINIMUM_DEPTH!"
)
mask = (depth > masking_depth) & is_wet
else:
mask = (depth > minimum_depth) & is_wet

return mask.astype(np.int8).values

Expand Down Expand Up @@ -231,7 +230,7 @@ def __init__(
lon_name=None,
lat_name=None,
area_name=None,
minimum_depth=None,
minimum_depth=0,
masking_depth=None,
):
"""
Expand Down Expand Up @@ -324,7 +323,7 @@ def __init__(
lon_name=None,
lat_name=None,
area_name=None,
minimum_depth=None,
minimum_depth=0,
masking_depth=None,
):
"""
Expand Down Expand Up @@ -516,7 +515,7 @@ def main():
parser.add_argument(
"--minimum-depth",
type=float,
default=None,
default=0,
help=(
"MINIMUM_DEPTH in metres. When a topography file is "
"provided, any grid cell with depth <= MINIMUM_DEPTH is treated as land "
Expand Down
27 changes: 26 additions & 1 deletion rof_pattern_generation/generate_rofi_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ def main():
required=True,
help="Path to the model topography file, which is used to generate the model mask.",
)
regrid_aq.parser.add_argument(
"--minimum-depth",
type=float,
default=0,
help=(
"MINIMUM_DEPTH in metres. When a topography file is "
"provided, any grid cell with depth <= MINIMUM_DEPTH is treated as land "
"unless --masking-depth is also supplied."
),
)
regrid_aq.parser.add_argument(
"--masking-depth",
type=float,
default=None,
help=(
"MASKING_DEPTH in metres. If set, cells with depth <= MASKING_DEPTH "
"become land, while cells with MASKING_DEPTH < depth < MINIMUM_DEPTH remain wet "
"but their depth will be raised to MINIMUM_DEPTH at runtime. "
"If omitted, MINIMUM_DEPTH alone controls the land-sea mask."
),
)

regrid_aq.parse_cli()

Expand Down Expand Up @@ -162,7 +183,11 @@ def main():

# find the ocean mask using the bathymetry
topo = xr.open_dataset(regrid.args.topog_file)
mask = mom6_mask_detection(topo)
mask = mom6_mask_detection(
topo,
minimum_depth=regrid.args.minimum_depth,
masking_depth=regrid.args.masking_depth,
)

# After doing the regridding, map any runoff on land cells into the ocean
weights_da = move_runoff_on_land(
Expand Down
Loading