Skip to content

Commit 864d0c5

Browse files
committed
Pre-cull mesh with geojson file
1 parent ad38e20 commit 864d0c5

File tree

1 file changed

+59
-4
lines changed
  • compass/landice/tests/uummannaq_disko

1 file changed

+59
-4
lines changed

compass/landice/tests/uummannaq_disko/mesh.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import json
12
import os
23

4+
import jigsawpy
35
import numpy as np
46
import xarray as xr
57
from mpas_tools.scrip.from_mpas import scrip_from_mpas
@@ -90,10 +92,19 @@ def run(self):
9092

9193
logger.info('calling build_cell_width')
9294

93-
cell_width, x1, y1, geom_points, geom_edges, floodMask = \
94-
build_cell_width(
95-
self, section_name=section_name,
96-
gridded_dataset=source_gridded_dataset_2km)
95+
if section_gis.get("define_bnds_by_geojson") == 'True':
96+
geom_points, geom_edges = set_geojson_geom_points_and_edges(self)
97+
98+
cell_width, x1, y1, floodMask = \
99+
build_cell_width(self,
100+
section_name=section_name,
101+
gridded_dataset=source_gridded_dataset_2km,
102+
calc_geom_bnds=False)
103+
else:
104+
cell_width, x1, y1, geom_points, geom_edges, floodMask = \
105+
build_cell_width(
106+
self, section_name=section_name,
107+
gridded_dataset=source_gridded_dataset_2km)
97108

98109
build_mali_mesh(
99110
self, cell_width, x1, y1, geom_points, geom_edges,
@@ -156,3 +167,47 @@ def run(self):
156167
ds["observedThicknessTendencyUncertainty"] = dHdtErr
157168
# Write the data to disk
158169
ds.to_netcdf(self.mesh_filename, 'a')
170+
171+
172+
def set_geojson_geom_points_and_edges(self):
173+
self.add_input_file(filename='UummannaqDisko.geojson',
174+
package='compass.landice.tests.uummannaq_disko',
175+
target='UummannaqDisko.geojson',
176+
database=None)
177+
178+
with open('UummannaqDisko.geojson', 'r') as meshMarginFile:
179+
geojson_data = json.load(meshMarginFile)
180+
181+
x = []
182+
y = []
183+
start_edge = []
184+
end_edge = []
185+
ct = 0
186+
187+
for feature in geojson_data['features']:
188+
geometry = feature['geometry']
189+
for coord in geometry['coordinates']:
190+
for sub_coord in coord:
191+
x.append(sub_coord[0])
192+
y.append(sub_coord[1])
193+
194+
start_edge.append(ct)
195+
end_edge.append(ct + 1)
196+
ct = ct + 1
197+
x = np.array(x)
198+
y = np.array(y)
199+
start_edge = np.array(start_edge)
200+
end_edge = np.array(end_edge)
201+
202+
start_edge[-1] = ct - 1
203+
end_edge[-1] = 0
204+
205+
geom_points = np.array([((x[i], y[i]), 0)
206+
for i in range(len(y))],
207+
dtype=jigsawpy.jigsaw_msh_t.VERT2_t)
208+
209+
geom_edges = np.array([((start_edge[i], end_edge[i]), 0)
210+
for i in range(len(start_edge))],
211+
dtype=jigsawpy.jigsaw_msh_t.EDGE2_t)
212+
213+
return (geom_points, geom_edges)

0 commit comments

Comments
 (0)