xmsstamper

Introduction

xmsstamper is a library used to generate "feature stamps". Feature stamps refer to the insertion of man-made structures into a natural topography or bathymetry set. In common terms, this means adding an embankment (such as a levy) or dredging a channel. A stamped feature usually a linear object or centerline. More information on feature stamping can be found here https://xmswiki.com/wiki/SMS:Feature_Stamping.

The basic workflow is to first define the land surface or bathymetry as a TIN (triangular surface). Then define a feature stamp consisting of a center line, cross sections along the center line, and end caps. The feature stamp is used to generate a new TIN that is cut off by the land surface or bathemetry.

This example will show how to use the classes in the library with very simple examples.

In [1]:
import numpy as np
import holoviews as hv

from shapely.geometry import Polygon
from holoviews.streams import Params

import hvplot.pandas
import hvplot.xarray

import xmsmesh
import xmsstamper
import xmsinterp
import xmsgrid

import ugrid_tools

hv.extension('bokeh')
In [2]:
# define a tin, used later
surface_pts = [(-5,-15,9.5), (-5,45,9.5), (70, 45,9.5), (70,-15,9.5)]
tin = xmsinterp.triangulate.Tin(pts=surface_pts)
tin.triangulate()

x = [x[0] for x in tin.pts]
y = [y[1] for y in tin.pts]
z = [z[2] for z in tin.pts]
nodes = np.column_stack([x, y, z])
nodes = hv.Points(nodes, vdims=['z'])

Define Center Line Points and type of Stamp

In [3]:
stamp_type = "fill"
centerline = [
    (0.0, 0.0, 10.0),
    (10.0, 0.0, 10.0),
]

Define a Cross Section

In [4]:
# symetric cross section, left and right are equal
left = right = [(0, 10.0), (2.0, 10.0), (3.0, 9.5)]
index_left_shoulder = index_right_shoulder = 1
left_max = right_max = 5.0
cs = xmsstamper.stamper.StampCrossSection(
    left=left,
    right=right,
    index_left_shoulder=index_left_shoulder,
    index_right_shoulder=index_right_shoulder,
    left_max=left_max,
    right_max=right_max,
)
cs_list = [cs] * len(centerline)

Create a StamperIO class to perform the Stamp operation

In [5]:
stamp_io = xmsstamper.stamper.StamperIo(
    stamping_type=stamp_type,
    centerline=centerline,
    cs=cs_list,
)

Generate a Stamp

In [6]:
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()

Draw the output TIN

In [7]:
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]

x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')

trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
   hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
Out[7]:

Extend Centerline and add another cross section

In [8]:
centerline.append((50, 0, 10))

left = right = [(0, 10.0), (4.0, 10.0), (3.0, 9.0)]
index_left_shoulder = index_right_shoulder = 1
left_max = right_max = 10.0
cs = xmsstamper.stamper.StampCrossSection(
    left=left,
    right=right,
    index_left_shoulder=index_left_shoulder,
    index_right_shoulder=index_right_shoulder,
    left_max=left_max,
    right_max=right_max,
)
cs_list.append(cs)

stamp_io = xmsstamper.stamper.StamperIo(
    stamping_type=stamp_type,
    centerline=centerline,
    cs=cs_list,
)

Create new Stamp and Draw out put

In [9]:
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
In [10]:
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]

x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')

trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
   hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
Out[10]:

Add End Caps to beginning of center line

In [11]:
wing_wall = xmsstamper.stamper.WingWall(wing_wall_angle = -30)

first_end_cap = xmsstamper.stamper.StamperEndCap(wing_wall=wing_wall)

stamp_io = xmsstamper.stamper.StamperIo(
    stamping_type=stamp_type,
    centerline=centerline,
    cs=cs_list,
    first_end_cap=first_end_cap,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
In [12]:
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]

x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')

trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
   hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
Out[12]:

Add End Caps to end of center line

In [13]:
guidebank = xmsstamper.stamper.Guidebank(n_pts=10, radius1=30, radius2=20, side=0, width=4)

last_end_cap = xmsstamper.stamper.StamperEndCap(guidebank=guidebank)
stamp_io = xmsstamper.stamper.StamperIo(
    stamping_type=stamp_type,
    centerline=centerline,
    cs=cs_list,
    first_end_cap=first_end_cap,
    last_end_cap=last_end_cap
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
In [14]:
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]

x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')

trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
   hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
Out[14]:

Specify a land surface to cut off the stamp

In [15]:
stamp_io = xmsstamper.stamper.StamperIo(
    stamping_type=stamp_type,
    centerline=centerline,
    cs=cs_list,
    first_end_cap=first_end_cap,
    last_end_cap=last_end_cap,
    bathymetry=tin,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
In [16]:
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]

x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')

trimesh = hv.TriMesh((tris, stamp_nodes))
nodes *stamp_nodes * trimesh.opts(
   hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
Out[16]:
In [ ]: