Skip to content

Commit

Permalink
Merge pull request #658 from xylar/landice-to-python-masking
Browse files Browse the repository at this point in the history
Switch to python masking for culling landice meshes
  • Loading branch information
trhille committed Aug 3, 2023
2 parents 198d0c9 + 0e4817d commit 5a4d3ce
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 26 deletions.
17 changes: 13 additions & 4 deletions compass/landice/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ def build_cell_width(self, section_name, gridded_dataset,

def build_mali_mesh(self, cell_width, x1, y1, geom_points,
geom_edges, mesh_name, section_name,
gridded_dataset, projection, geojson_file=None):
gridded_dataset, projection, geojson_file=None,
cores=1):
"""
Create the MALI mesh based on final cell widths determined by
:py:func:`compass.landice.mesh.build_cell_width()`, using Jigsaw and
Expand Down Expand Up @@ -603,8 +604,11 @@ def build_mali_mesh(self, cell_width, x1, y1, geom_points,
Projection to be used for setting lat-long fields.
Likely ``'gis-gimp'`` or ``'ais-bedmap2'``
geojson_file : str
geojson_file : str, optional
Name of geojson file that defines regional domain extent.
cores : int, optional
The number of cores to use for mask creation
"""

logger = self.logger
Expand Down Expand Up @@ -653,8 +657,13 @@ def build_mali_mesh(self, cell_width, x1, y1, geom_points,

check_call(args, logger=logger)

args = ['MpasMaskCreator.x', 'grid_preCull.nc',
'mask.nc', '-f', geojson_file]
args = ['compute_mpas_region_masks',
'-m', 'grid_preCull.nc',
'-o', 'mask.nc',
'-g', geojson_file,
'--process_count', f'{cores}',
'--format', mpas_tools.io.default_format,
'--engine', mpas_tools.io.default_engine]

check_call(args, logger=logger)

Expand Down
2 changes: 1 addition & 1 deletion compass/landice/tests/antarctica/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, test_case):
The test case this step belongs to
"""
super().__init__(test_case=test_case, name='mesh', cpus_per_task=64,
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.mesh_filename = 'Antarctica.nc'
Expand Down
15 changes: 12 additions & 3 deletions compass/landice/tests/antarctica/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from compass.testcase import TestCase
from compass.landice.tests.antarctica.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
"""
The default test case for the Antarctica test group simply creates the
mesh and initial condition.
"""

def __init__(self, test_group):
Expand All @@ -17,7 +17,6 @@ def __init__(self, test_group):
----------
test_group : compass.landice.tests.antarctica.Antarctica
The test group that this test case belongs to
"""
name = 'mesh_gen'
subdir = name
Expand All @@ -26,3 +25,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/Antarctica.nc')
3 changes: 2 additions & 1 deletion compass/landice/tests/greenland/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def __init__(self, test_case):
mesh_type : str
The resolution or mesh type of the test case
"""
super().__init__(test_case=test_case, name='mesh')
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.add_output_file(filename='graph.info')
self.add_output_file(filename='GIS.nc')
Expand Down
12 changes: 12 additions & 0 deletions compass/landice/tests/greenland/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from compass.landice.tests.greenland.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
Expand All @@ -13,6 +14,7 @@ class MeshGen(TestCase):
def __init__(self, test_group):
"""
Create the test case
Parameters
----------
test_group : compass.landice.tests.greenland.Greenland
Expand All @@ -25,3 +27,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/GIS.nc')
6 changes: 4 additions & 2 deletions compass/landice/tests/humboldt/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def __init__(self, test_case):
mesh_type : str
The resolution or mesh type of the test case
"""
super().__init__(test_case=test_case, name='mesh')
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.add_output_file(filename='graph.info')
self.add_output_file(filename='Humboldt.nc')
Expand Down Expand Up @@ -60,7 +61,8 @@ def run(self):
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=mesh_name, section_name=section_name,
gridded_dataset='humboldt_1km_2020_04_20.epsg3413.icesheetonly.nc',
projection='gis-gimp', geojson_file='Humboldt.geojson')
projection='gis-gimp', geojson_file='Humboldt.geojson',
cores=self.cpus_per_task)

logger.info('creating graph.info')
make_graph_file(mesh_filename=mesh_name,
Expand Down
15 changes: 12 additions & 3 deletions compass/landice/tests/humboldt/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from compass.testcase import TestCase
from compass.landice.tests.humboldt.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
"""
The MeshGen test case for the humboldt test group simply creates the
mesh and initial condition.
"""

def __init__(self, test_group):
Expand All @@ -17,7 +17,6 @@ def __init__(self, test_group):
----------
test_group : compass.landice.tests.humboldt.Humboldt
The test group that this test case belongs to
"""
name = 'mesh_gen'
subdir = name
Expand All @@ -26,3 +25,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/Humboldt.nc')
6 changes: 4 additions & 2 deletions compass/landice/tests/kangerlussuaq/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def __init__(self, test_case):
mesh_type : str
The resolution or mesh type of the test case
"""
super().__init__(test_case=test_case, name='mesh')
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.add_output_file(filename='graph.info')
self.add_output_file(filename='Kangerlussuaq.nc')
Expand Down Expand Up @@ -61,7 +62,8 @@ def run(self):
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=mesh_name, section_name=section_name,
gridded_dataset='greenland_1km_2020_04_20.epsg3413.icesheetonly.nc', # noqa
projection='gis-gimp', geojson_file='Kangerlussuaq.geojson')
projection='gis-gimp', geojson_file='Kangerlussuaq.geojson',
cores=self.cpus_per_task)

logger.info('creating graph.info')
make_graph_file(mesh_filename=mesh_name,
Expand Down
15 changes: 12 additions & 3 deletions compass/landice/tests/kangerlussuaq/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from compass.testcase import TestCase
from compass.landice.tests.kangerlussuaq.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
"""
The default test case for the Kangerlussuaq test group simply creates the
mesh and initial condition.
"""

def __init__(self, test_group):
Expand All @@ -17,7 +17,6 @@ def __init__(self, test_group):
----------
test_group : compass.landice.tests.kangerlussuaq.Kangerlussuaq
The test group that this test case belongs to
"""
name = 'mesh_gen'
subdir = name
Expand All @@ -26,3 +25,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/Kangerlussuaq.nc')
6 changes: 4 additions & 2 deletions compass/landice/tests/koge_bugt_s/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def __init__(self, test_case):
mesh_type : str
The resolution or mesh type of the test case
"""
super().__init__(test_case=test_case, name='mesh')
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.add_output_file(filename='graph.info')
self.add_output_file(filename='Koge_Bugt_S.nc')
Expand Down Expand Up @@ -61,7 +62,8 @@ def run(self):
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=mesh_name, section_name=section_name,
gridded_dataset='greenland_1km_2020_04_20.epsg3413.icesheetonly.nc', # noqa
projection='gis-gimp', geojson_file='Koge_Bugt_S.geojson')
projection='gis-gimp', geojson_file='Koge_Bugt_S.geojson',
cores=self.cpus_per_task)

logger.info('creating graph.info')
make_graph_file(mesh_filename=mesh_name,
Expand Down
15 changes: 12 additions & 3 deletions compass/landice/tests/koge_bugt_s/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from compass.testcase import TestCase
from compass.landice.tests.koge_bugt_s.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
"""
The default test case for the Koge_Bugt_S test group simply creates the
mesh and initial condition.
"""

def __init__(self, test_group):
Expand All @@ -17,7 +17,6 @@ def __init__(self, test_group):
----------
test_group : compass.landice.tests.koge_bugt_s.KogeBugtS
The test group that this test case belongs to
"""
name = 'mesh_gen'
subdir = name
Expand All @@ -26,3 +25,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/Koge_Bugt_S.nc')
6 changes: 4 additions & 2 deletions compass/landice/tests/thwaites/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self, test_case):
test_case : compass.TestCase
The test case this step belongs to
"""
super().__init__(test_case=test_case, name='mesh')
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
min_cpus_per_task=1)

self.add_output_file(filename='graph.info')
self.add_output_file(filename='Thwaites.nc')
Expand Down Expand Up @@ -50,7 +51,8 @@ def run(self):
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=mesh_name, section_name=section_name,
gridded_dataset='antarctica_1km_2020_10_20_ASE.nc',
projection='ais-bedmap2', geojson_file='thwaites_minimal.geojson')
projection='ais-bedmap2', geojson_file='thwaites_minimal.geojson',
cores=self.cpus_per_task)

logger.info('creating graph.info')
make_graph_file(mesh_filename=mesh_name,
Expand Down
12 changes: 12 additions & 0 deletions compass/landice/tests/thwaites/mesh_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from compass.landice.tests.thwaites.mesh import Mesh
from compass.testcase import TestCase
from compass.validate import compare_variables


class MeshGen(TestCase):
Expand All @@ -13,6 +14,7 @@ class MeshGen(TestCase):
def __init__(self, test_group):
"""
Create the test case
Parameters
----------
test_group : compass.landice.tests.thwaites.Thwaites
Expand All @@ -25,3 +27,13 @@ def __init__(self, test_group):

self.add_step(
Mesh(test_case=self))

def validate(self):
"""
Compare ``thickness``, ``bedTopography``, ``iceMask`` and
``beta`` with a baseline if one was provided.
"""
variables = ['thickness', 'bedTopography', 'iceMask',
'beta']
compare_variables(test_case=self, variables=variables,
filename1='mesh/Thwaites.nc')

0 comments on commit 5a4d3ce

Please sign in to comment.