def pnts_to_xA(pnts, datum='MSL'): samples = linestring_utils.upsample_linearring(pnts, 5, closed_ring=False) z = dem(samples) dists = utils.dist_along(samples) z0 = ds.z.sel(datum=datum).item() depths = (z0 - z).clip(0, np.inf) xA = np.trapz(depths, dists) return xA
def test_peninsula(): r = 100 thetas = np.linspace(0, 2 * np.pi, 1000) pen = np.zeros((len(thetas), 2), np.float64) pen[:, 0] = r * (0.2 + np.abs(np.sin(2 * thetas))**0.2) * np.cos(thetas) pen[:, 1] = r * (0.2 + np.abs(np.sin(2 * thetas))**0.2) * np.sin(thetas) density = field.ConstantField(10.0) pen2 = upsample_linearring(pen, density) trifront_wrapper([pen2], density, label='peninsula')
print("Loading DEM for %s" % name) dem = field.GdalGrid(dem_fn) if gen_weirs: print("Generating fixed weirs") fixed_weir_fn = "fixed_weirs-%s.pliz" % name fixed_weirs = [] # suitable for write_pli dx = 5.0 # m. discretize lines at this resolution for i in range(len(lines)): feat = lines[i] if feat['type'] != 'fixed_weir': continue print(f"Processing levee feature {feat['name']}") xy = np.array(feat['geom']) xy = linestring_utils.upsample_linearring(xy, dx, closed_ring=False) z = dem(xy) fixed_weirs.append((feat['name'], np.c_[xy, z, 0 * z, 0 * z])) dio.write_pli(fixed_weir_fn, fixed_weirs) if gen_grids: print("Setting bathymetry for %s" % name) if 0: # Simplest option: # Put bathy on nodes, just direct sampling. z_node = dem(g.nodes['x']) if 1: # Bias deep name += "_deep" # Maybe a good match with bedlevtype=5. # BLT=5: edges get shallower node, cells get deepest edge.
# count total features so that files can be concatenated without issue. total_count = 0 # no longer split by class, all filtering already complete in the input # shapefile g = unstructured_grid.UnstructuredGrid(extra_node_fields=[('elev_m', 'f8')], extra_edge_fields=[('mean_elev_m', 'f8') ]) for ix, sel_i in enumerate(np.nonzero(sel)[0]): geom = inv['geom'][sel_i] coords = np.array(geom) # not 100% sure about whether it's necessary to test for closed_ring new_coords = linestring_utils.upsample_linearring(coords, res, closed_ring=0) nodes = [ g.add_or_find_node(x=xy, tolerance=0.0, elev_m=np.nan) for xy in new_coords ] for a, b in zip(nodes[:-1], nodes[1:]): j = g.add_edge(nodes=[a, b], mean_elev_m=inv['Z_Mean'][sel_i]) # pull out point elevations at the nodes: g.nodes['elev_m'] = dem(g.nodes['x']) # drastic, but go ahead and delete any nodes which failed to get an elevation