|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import re |
3 | 4 | import sys |
|
17 | 18 | from netCDF4 import Dataset |
18 | 19 | from scipy.interpolate import NearestNDInterpolator, interpn |
19 | 20 |
|
| 21 | +from compass.step import add_input_file |
| 22 | + |
20 | 23 |
|
21 | 24 | def mpas_flood_fill(seed_mask, grow_mask, cellsOnCell, nEdgesOnCell, |
22 | 25 | grow_iters=sys.maxsize): |
@@ -265,9 +268,6 @@ def set_cell_width(self, section_name, thk, bed=None, vx=None, vy=None, |
265 | 268 | low_bed = section.getfloat('low_bed') |
266 | 269 | high_bed = section.getfloat('high_bed') |
267 | 270 |
|
268 | | - # convert km to m |
269 | | - cull_distance = section.getfloat('cull_distance') * 1.e3 |
270 | | - |
271 | 271 | # Cell spacing function based on union of masks |
272 | 272 | if section.get('use_bed') == 'True': |
273 | 273 | 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, |
379 | 379 | for width in [spacing_bed, spacing_speed, spacing_edge, spacing_gl]: |
380 | 380 | cell_width = np.minimum(cell_width, width) |
381 | 381 |
|
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 | | - |
401 | 382 | return cell_width |
402 | 383 |
|
403 | 384 |
|
@@ -603,14 +584,56 @@ def build_cell_width(self, section_name, gridded_dataset, |
603 | 584 | f.close() |
604 | 585 |
|
605 | 586 | # 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) |
614 | 637 |
|
615 | 638 | # Remove ice not connected to the ice sheet. |
616 | 639 | flood_mask = gridded_flood_fill(thk) |
|
0 commit comments