1- import json
21import os
32import re
43import sys
1817from netCDF4 import Dataset
1918from scipy .interpolate import NearestNDInterpolator , interpn
2019
21- from compass .step import add_input_file
22-
2320
2421def mpas_flood_fill (seed_mask , grow_mask , cellsOnCell , nEdgesOnCell ,
2522 grow_iters = sys .maxsize ):
@@ -520,7 +517,7 @@ def get_dist_to_edge_and_gl(self, thk, topg, x, y,
520517
521518
522519def build_cell_width (self , section_name , gridded_dataset ,
523- flood_fill_start = [None , None ]):
520+ flood_fill_start = [None , None ], calc_geom_bnds = True ):
524521 """
525522 Determine MPAS mesh cell size based on user-defined density function.
526523
@@ -545,6 +542,11 @@ def build_cell_width(self, section_name, gridded_dataset,
545542 fill. Most cases will use ``[None, None]``, which will just start the
546543 flood fill in the center of the gridded dataset.
547544
545+ calc_geom_bnds : logical
546+ Option to calculate geom_points and geom_edges needed for jigsaw within
547+ build_cell_width. Default is to perform calculation, but the user may
548+ opt out if these are determined elsewhere (e.g., using a geojson file)
549+
548550 Returns
549551 -------
550552 cell_width : numpy.ndarray
@@ -583,49 +585,8 @@ def build_cell_width(self, section_name, gridded_dataset,
583585
584586 f .close ()
585587
586- # Get bounds defined by user, or use bound of gridded dataset
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 :
588+ # If necessary, get bounds defined by user or use bound of gridded dataset
589+ if calc_geom_bnds :
629590 bnds = [np .min (x1 ), np .max (x1 ), np .min (y1 ), np .max (y1 )]
630591 bnds_options = ['x_min' , 'x_max' , 'y_min' , 'y_max' ]
631592 for index , option in enumerate (bnds_options ):
@@ -655,8 +616,12 @@ def build_cell_width(self, section_name, gridded_dataset,
655616 flood_fill_iStart = flood_fill_start [0 ],
656617 flood_fill_jStart = flood_fill_start [1 ])
657618
658- return (cell_width .astype ('float64' ), x1 .astype ('float64' ),
659- y1 .astype ('float64' ), geom_points , geom_edges , flood_mask )
619+ if not calc_geom_bnds :
620+ return (cell_width .astype ('float64' ), x1 .astype ('float64' ),
621+ y1 .astype ('float64' ), flood_mask )
622+ else :
623+ return (cell_width .astype ('float64' ), x1 .astype ('float64' ),
624+ y1 .astype ('float64' ), geom_points , geom_edges , flood_mask )
660625
661626
662627def build_mali_mesh (self , cell_width , x1 , y1 , geom_points ,
0 commit comments