|
| 1 | +import json |
1 | 2 | import os
|
2 | 3 |
|
| 4 | +import jigsawpy |
3 | 5 | import numpy as np
|
4 | 6 | import xarray as xr
|
5 | 7 | from mpas_tools.scrip.from_mpas import scrip_from_mpas
|
@@ -90,10 +92,19 @@ def run(self):
|
90 | 92 |
|
91 | 93 | logger.info('calling build_cell_width')
|
92 | 94 |
|
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) |
97 | 108 |
|
98 | 109 | build_mali_mesh(
|
99 | 110 | self, cell_width, x1, y1, geom_points, geom_edges,
|
@@ -156,3 +167,47 @@ def run(self):
|
156 | 167 | ds["observedThicknessTendencyUncertainty"] = dHdtErr
|
157 | 168 | # Write the data to disk
|
158 | 169 | 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