Skip to content

Commit 69fbf46

Browse files
committed
Create option for high res in ocean for gis mesh
This commit creates the option to maintain high resolution in all ocean cells (same resolution as what is prescribed at outlet glacier termini). This is necessary to resolve the fjord geometry that thermal forcing parameterizations rely on. To reduce time when generating these higher resolution meshes, this commit also introduces an option to do an initial cull of the bedMachine dataset using the extent of the contintental shelf before generating the GIS mesh.
1 parent 964589a commit 69fbf46

File tree

2 files changed

+395
-30
lines changed

2 files changed

+395
-30
lines changed

compass/landice/mesh.py

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import re
34
import sys
@@ -17,6 +18,8 @@
1718
from netCDF4 import Dataset
1819
from scipy.interpolate import NearestNDInterpolator, interpn
1920

21+
from compass.step import add_input_file
22+
2023

2124
def mpas_flood_fill(seed_mask, grow_mask, cellsOnCell, nEdgesOnCell,
2225
grow_iters=sys.maxsize):
@@ -265,9 +268,6 @@ def set_cell_width(self, section_name, thk, bed=None, vx=None, vy=None,
265268
low_bed = section.getfloat('low_bed')
266269
high_bed = section.getfloat('high_bed')
267270

268-
# convert km to m
269-
cull_distance = section.getfloat('cull_distance') * 1.e3
270-
271271
# Cell spacing function based on union of masks
272272
if section.get('use_bed') == 'True':
273273
logger.info('Using bed elevation for spacing.')
@@ -379,25 +379,6 @@ def set_cell_width(self, section_name, thk, bed=None, vx=None, vy=None,
379379
for width in [spacing_bed, spacing_speed, spacing_edge, spacing_gl]:
380380
cell_width = np.minimum(cell_width, width)
381381

382-
# Set large cell_width in areas we are going to cull anyway (speeds
383-
# up whole process). If max_res_in_ocn is True, then use a larger
384-
# multiplier to ensure ocean cells are not accidentally coarsened
385-
# within the final domain. Otherwise, we can get away with
386-
# something smaller, like 3x the cull_distance, to avoid this
387-
# affecting the cell size in the final mesh. There may eventually
388-
# be a more rigorous way to set this distance.
389-
if dist_to_edge is not None:
390-
if section.get('max_res_in_ocn') == 'True':
391-
mask = np.logical_and(
392-
# Try 20x cull_distance for now
393-
thk == 0.0, dist_to_edge > (20. * cull_distance))
394-
else:
395-
mask = np.logical_and(
396-
thk == 0.0, dist_to_edge > (3. * cull_distance))
397-
logger.info('Setting cell_width in outer regions to max_spac '
398-
f'for {mask.sum()} cells')
399-
cell_width[mask] = max_spac
400-
401382
return cell_width
402383

403384

@@ -603,14 +584,56 @@ def build_cell_width(self, section_name, gridded_dataset,
603584
f.close()
604585

605586
# Get bounds defined by user, or use bound of gridded dataset
606-
bnds = [np.min(x1), np.max(x1), np.min(y1), np.max(y1)]
607-
bnds_options = ['x_min', 'x_max', 'y_min', 'y_max']
608-
for index, option in enumerate(bnds_options):
609-
bnd = section.get(option)
610-
if bnd != 'None':
611-
bnds[index] = float(bnd)
612-
613-
geom_points, geom_edges = set_rectangular_geom_points_and_edges(*bnds)
587+
if section.get('define_bnds_by_geojson') == 'True':
588+
# change file location either to compass or geometric_features
589+
add_input_file(filename='gis_contShelfExtent.geojson',
590+
package='compass.landice.tests.greenland',
591+
target='gis_contShelfExtent.geojson',
592+
database=None)
593+
594+
with open('gis_contShelfExtent.geojson', 'r') as meshMarginFile:
595+
geojson_data = json.load(meshMarginFile)
596+
597+
lon = []
598+
lat = []
599+
start_edge = []
600+
end_edge = []
601+
ct = 0
602+
603+
for feature in geojson_data['features']:
604+
geometry = feature['geometry']
605+
for coord in geometry['coordinates']:
606+
for sub_coord in coord:
607+
lon.append(sub_coord[0])
608+
lat.append(sub_coord[1])
609+
610+
start_edge.append(ct)
611+
end_edge.append(ct + 1)
612+
ct = ct + 1
613+
lon = np.array(lon)
614+
lat = np.array(lat)
615+
start_edge = np.array(start_edge)
616+
end_edge = np.array(end_edge)
617+
618+
start_edge[-1] = ct - 1
619+
end_edge[-1] = 0
620+
621+
geom_points = np.array([((lon[i], lat[i]), 0)
622+
for i in range(len(lat))],
623+
dtype=jigsawpy.jigsaw_msh_t.VERT2_t)
624+
625+
geom_edges = np.array([((start_edge[i], end_edge[i]), 0)
626+
for i in range(len(start_edge))],
627+
dtype=jigsawpy.jigsaw_msh_t.EDGE2_t)
628+
else:
629+
bnds = [np.min(x1), np.max(x1), np.min(y1), np.max(y1)]
630+
bnds_options = ['x_min', 'x_max', 'y_min', 'y_max']
631+
for index, option in enumerate(bnds_options):
632+
bnd = section.get(option)
633+
if bnd != 'None':
634+
bnds[index] = float(bnd)
635+
636+
geom_points, geom_edges = set_rectangular_geom_points_and_edges(*bnds)
614637

615638
# Remove ice not connected to the ice sheet.
616639
flood_mask = gridded_flood_fill(thk)

0 commit comments

Comments
 (0)