Example #1
0
def bathy():
    # from stompy.spatial import field
    #return field.GdalGrid('../../bathy/OldRvr_at_SanJoaquinRvr2012_0104-utm-m_NAVD.tif')
    utils.path("../../bathy")
    from bathy import dem
    tile = dem().extract_tile(study_zoom)
    return tile
def bathy():
    # from stompy.spatial import field
    #return field.GdalGrid('../../bathy/OldRvr_at_SanJoaquinRvr2012_0104-utm-m_NAVD.tif')
    utils.path(os.path.join(os.path.dirname(__file__), "../../bathy"))
    from bathy import dem
    study_zoom = [646000, 649000, 4185000, 4186500]
    tile = dem().extract_tile(study_zoom)
    return tile
def add_bathy(g, suffix=''):
    dem = bathy.dem(suffix=suffix)

    z = dem(g.cells_center())
    z[np.isnan(z)] = 5.0
    g.add_cell_field('z_bed', z, on_exists='overwrite')

    return g
def process(grid_in, grid_out):
    g = unstructured_grid.UnstructuredGrid.from_ugrid(grid_in)

    dem = bathy.dem()

    # By default, just put depths onto the nodes straight from DEM
    g.add_node_field('depth', dem(g.nodes['x']))

    g.write_ugrid(grid_out, overwrite=True)
Example #5
0
def set_bathy(g_in, g_out):
    from stompy.grid import depth_connectivity
    import bathy

    assert g_in != g_out
    shallow_thresh = -1
    g = unstructured_grid.UnstructuredGrid.from_ugrid(g_in)
    dem = bathy.dem()
    z_cell_mean = depth_connectivity.cell_mean_depth(g, dem)

    e2c = g.edge_to_cells().copy()
    nc1 = e2c[:, 0]
    nc2 = e2c[:, 1]
    nc1[nc1 < 0] = nc2[nc1 < 0]
    nc2[nc2 < 0] = nc1[nc2 < 0]
    # starting point for edges is shallower of the neighboring cells
    z_edge = np.maximum(z_cell_mean[nc1], z_cell_mean[nc2])
    # only worry about connectivity when the edge is starting above
    # the threshold
    shallow = (z_edge > shallow_thresh)
    # centers='centroid' seemed to be losing a lot of connectivity.
    z_edge_conn = depth_connectivity.edge_connection_depth(g,
                                                           dem,
                                                           edge_mask=shallow,
                                                           centers='lowest')
    valid = np.isfinite(z_edge_conn)
    z_edge[valid] = z_edge_conn[valid]
    # edge-based is better at getting the unresolved channels connected
    # leads to alligator teeth in some places.
    # only use edge connectivity approach down to edge_thresh
    z_cell_edgeminthresh = [
        min(max(shallow_thresh, z_edge[g.cell_to_edges(c)].min()),
            z_cell_mean[c]) for c in range(g.Ncells())
    ]
    g.add_cell_field('z_bed',
                     np.asarray(z_cell_edgeminthresh),
                     on_exists='overwrite')
    rough = 'z0B'
    if rough in g.edges.dtype.names:
        missing = g.edges[rough] == 0
        g.edges[rough][missing] = 0.002

    ec = g.edge_to_cells().copy()
    nc1 = ec[:, 0]
    nc2 = ec[:, 1]
    nc1[nc1 < 0] = nc2[nc1 < 0]
    nc2[nc2 < 0] = nc1[nc2 < 0]
    edge_z = np.maximum(g.cells['z_bed'][nc1], g.cells['z_bed'][nc2])
    g.add_edge_field('edge_z_bed', edge_z, on_exists='overwrite')

    g.write_ugrid(g_out, overwrite=True)
    return g
Example #6
0
    # as suntans.  Could patch unstructured_grid to check for n1/n2, though
    # they don't have a standard name so it would be a kludge.
    # normal_sgn=-1
    Q *= -1

    return dict(U=U, V=V, Q=Q, g=g)


hydro = extract_global(model)

##

# Sample datasets
if 1:
    import bathy
    dem = bathy.dem()

    # fake, sparser tracks.
    adcp_shp = wkb2shp.shp2geom('sparse_fake_bathy_trackline.shp')
    xys = []
    for feat in adcp_shp['geom']:
        feat_xy = np.array(feat)
        feat_xy = linestring_utils.resample_linearring(feat_xy,
                                                       1.0,
                                                       closed_ring=0)
        feat_xy = filters.lowpass_fir(feat_xy, winsize=6, axis=0)
        xys.append(feat_xy)
    adcp_xy = np.concatenate(xys)
    source_ds = xr.Dataset()
    source_ds['x'] = ('sample', 'xy'), adcp_xy
    source_ds['z'] = ('sample', ), dem(adcp_xy)
# Looking at a specific transect with matlab info:
# '../field/adcp/040518_BT/040518_2BTref/20180404084019r.rivr'
# '../field/adcp/040518_BT/040518_2BTref/20180404084019r.mat'
# First time in the dataset is '2018-04-04T08:40:10.000000000'
#  with 167 samples
# First time in the GPS['Utc'] field is
# [174336.5], also 167 samples.
# Kind of weird, but maybe some clock drift?
#   That is 17:43:36.500 vs 08:40:10.00
#   So the ADCP is 9h03 behind.  That's weird, since PDT is 7h off,
#   and PST is 8h off.
#
##

zoom = (646982, 647582, 4185480, 4186091)
dem = bathy.dem().extract_tile(zoom, res=2.0)

##

delta = xyz_samples[:, 2] - dem(xyz_samples[:, :2])

##
plt.figure(1).clf()
fig, (ax, ax2) = plt.subplots(1, 2, num=1, sharex=True, sharey=True)
fig.set_size_inches([10, 7], forward=True)

scat = ax.scatter(xyz_samples[:, 0],
                  xyz_samples[:, 1],
                  15,
                  xyz_samples[:, 2],
                  cmap='jet')