Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix land-locked cells at calving fronts #752

Merged
merged 2 commits into from
Feb 3, 2024
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
34 changes: 27 additions & 7 deletions compass/ocean/mesh/cull.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ def run(self):
convert_to_cdf5 = config.getboolean('spherical_mesh',
'convert_culled_mesh_to_cdf5')

latitude_threshold = config.getfloat('spherical_mesh',
'latitude_threshold')

sweep_count = config.getint('spherical_mesh', 'sweep_count')

cull_mesh(with_critical_passages=True, logger=logger,
use_progress_bar=use_progress_bar,
preserve_floodplain=preserve_floodplain,
with_cavities=with_ice_shelf_cavities,
process_count=self.cpus_per_task,
convert_to_cdf5=convert_to_cdf5)
convert_to_cdf5=convert_to_cdf5,
latitude_threshold=latitude_threshold,
sweep_count=sweep_count)

if do_inject_bathymetry:
inject_bathymetry(mesh_file='culled_mesh.nc')
Expand All @@ -180,7 +187,8 @@ def run(self):
def cull_mesh(with_cavities=False, with_critical_passages=False,
custom_critical_passages=None, custom_land_blockages=None,
preserve_floodplain=False, logger=None, use_progress_bar=True,
process_count=1, convert_to_cdf5=False):
process_count=1, convert_to_cdf5=False, latitude_threshold=43.,
sweep_count=20):
"""
First step of initializing the global ocean:

Expand Down Expand Up @@ -241,21 +249,29 @@ def cull_mesh(with_cavities=False, with_critical_passages=False,
process_count : int, optional
The number of cores to use to create masks (``None`` to use all
available cores)

convert_to_cdf5 : bool, optional
Convert the culled mesh to PNetCDF CDF-5 format

latitude_threshold : float, optional
Minimum latitude, in degrees, for masking land-locked cells

sweep_count : int, optional
Maximum number of sweeps to search for land-locked cells
"""
with LoggingContext(name=__name__, logger=logger) as logger:
_cull_mesh_with_logging(
logger, with_cavities, with_critical_passages,
custom_critical_passages, custom_land_blockages,
preserve_floodplain, use_progress_bar, process_count,
convert_to_cdf5)
convert_to_cdf5, latitude_threshold, sweep_count)


def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,
custom_critical_passages, custom_land_blockages,
preserve_floodplain, use_progress_bar,
process_count, convert_to_cdf5):
process_count, convert_to_cdf5, latitude_threshold,
sweep_count):
""" Cull the mesh once the logger is defined for sure """

critical_passages = with_critical_passages or \
Expand Down Expand Up @@ -286,9 +302,9 @@ def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,

dsBaseMesh = xr.open_dataset('base_mesh.nc')
dsLandMask = xr.open_dataset('land_mask.nc')
dsLandMask = add_land_locked_cells_to_mask(dsLandMask, dsBaseMesh,
latitude_threshold=43.0,
nSweeps=20)
dsLandMask = add_land_locked_cells_to_mask(
dsLandMask, dsBaseMesh, latitude_threshold=latitude_threshold,
nSweeps=sweep_count)
write_netcdf(dsLandMask, 'land_mask_with_land_locked_cells.nc')

# create seed points for a flood fill of the ocean
Expand Down Expand Up @@ -425,6 +441,10 @@ def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,

dsMask = xr.open_dataset('ice_coverage.nc')

dsMask = add_land_locked_cells_to_mask(
dsMask, dsCulledMesh, latitude_threshold=latitude_threshold,
nSweeps=sweep_count)

Comment on lines +444 to +447
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 lines are the real fix here. The rest is clean up to reduce the number of hard-coded parameters.

landIceMask = dsMask.regionCellMasks.isel(nRegions=0)
dsLandIceMask = xr.Dataset()
dsLandIceMask['landIceMask'] = landIceMask
Expand Down
4 changes: 4 additions & 0 deletions compass/ocean/tests/global_ocean/global_ocean.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ cull_mesh_min_cpus_per_task = 1
cull_mesh_max_memory = 1000
# Whether to convert the culled mesh file to CDF5 format
convert_culled_mesh_to_cdf5 = False
# Minimum latitude, in degrees, for masking land-locked cells
latitude_threshold = 43.0
# Maximum number of sweeps to search for land-locked cells
sweep_count = 20


# Options relate to adjusting the sea-surface height or land-ice pressure
Expand Down
4 changes: 4 additions & 0 deletions compass/ocean/tests/hurricane/hurricane.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
# Config options related to the step for culling land from the mesh
# Whether to convert the culled mesh file to CDF5 format
convert_culled_mesh_to_cdf5 = False
# Minimum latitude, in degrees, for masking land-locked cells
latitude_threshold = 43.0
# Maximum number of sweeps to search for land-locked cells
sweep_count = 20
Loading