예제 #1
0
def test_merge():
    ugA=unstructured_grid.SuntansGrid('/Users/rusty/src/umbra/Umbra/sample_data/sfbay')
    ugB=unstructured_grid.SuntansGrid('/Users/rusty/src/umbra/Umbra/sample_data/sfbay')

    x_cut=568000
    n_sel=ugA.nodes['x'][:,0]<x_cut


    for n in np.nonzero(n_sel)[0]:
        ugA.delete_node_cascade(n)
    for n in np.nonzero(~n_sel)[0]:
        ugB.delete_node_cascade(n)

    if 0:
        plt.figure(1).clf()
        fig,ax=plt.subplots(num=1)

        ugA.plot_edges(ax=ax,color='r')
        ugB.plot_edges(ax=ax,color='b')

    ugA.add_grid(ugB)

    if 0: 
        plt.figure(2).clf()
        fig,ax=plt.subplots(num=2)

        ugA.plot_edges(ax=ax,color='r')
예제 #2
0
def test_nearest_cell():
    ug=unstructured_grid.SuntansGrid(os.path.join(sample_data,'sfbay') )
    
    target=[550000,4.14e6]
    hit1=ug.select_cells_nearest(target,inside=True)
    hit2=ug.cell_containing(target)

    assert hit1==hit2
예제 #3
0
def test_delete_undelete():
    ug=unstructured_grid.SuntansGrid(os.path.join(sample_data,'sfbay'))
    xy=(507872, 4159018)
    c=ug.select_cells_nearest(xy)
    nodes=ug.cell_to_nodes(c)
    chk=ug.checkpoint()
    ug.delete_cell(c)
    ug.revert(chk)
    ug.delete_node_cascade(nodes[0])
예제 #4
0
def test_boundary_polygon():
    ug=unstructured_grid.SuntansGrid(os.path.join(sample_data,'sfbay') )
    poly1=ug.boundary_polygon()
    poly2=ug.boundary_polygon_by_edges()
    poly3=ug.boundary_polygon_by_union()

    print("poly1 area:",poly1.area)
    print("poly2 area:",poly2.area)
    print("poly3 area:",poly3.area)

    # in one test, these were the same out to 12 digits.
    assert abs( (poly1.area - poly2.area) / poly1.area ) < 1e-10
    assert abs( (poly1.area - poly3.area) / poly1.area ) < 1e-10
예제 #5
0
def test_modify_max_sides():
    ug=unstructured_grid.SuntansGrid(os.path.join(sample_data,'sfbay') )

    ug.modify_max_sides(max_sides=6)
    
    n1=ug.add_node(x=[0,0])
    n2=ug.add_node(x=[1,0])
    n3=ug.add_node(x=[1,1])
    n4=ug.add_node(x=[0,1])

    ug.add_cell_and_edges(nodes=[n1,n2,n3,n4])

    ug.modify_max_sides(max_sides=4)

    with assert_raises(unstructured_grid.GridException) as cm:
        ug.modify_max_sides(max_sides=3)
예제 #6
0
#!/usr/bin/env python
"""
Read a suntans grid in the current directory and write a DFM grid, output_net.nc
"""

from stompy.grid import unstructured_grid
from stompy.model.delft import dfm_grid

ug = unstructured_grid.SuntansGrid(".")

dfm_grid.write_dfm(ug, "output_net.nc")
예제 #7
0
import os
from stompy.grid import unstructured_grid

g_tri=unstructured_grid.SuntansGrid('junction-grid-100')

##

g_hex=g_tri.create_dual(center='circumcenter',create_cells=True)


##

plt.figure(1).clf()
fig,ax=plt.subplots(1,1,num=1)

g_tri.plot_edges(ax=ax,color='b',lw=0.3)
g_hex.plot_edges(ax=ax,color='g',lw=0.3)
g_hex.plot_cells(ax=ax,alpha=0.2)

ax.axis('equal')

# checking on orthogonality at a problem spot:
zoom=(647275.5263519865, 647295.9225515076, 4185924.1187208737, 4185934.4744617515)
ax.axis(zoom)

cc_hex=g_hex.cells_center()
mask=g_hex.cell_clip_mask(zoom)
ax.plot(  cc_hex[mask,0], cc_hex[mask,1], 'bo')

##
예제 #8
0
        try:
            j = g.add_edge(nodes=[na, nb])
        except g.GridException:
            pass

cycles = g.find_cycles(max_cycle_len=g.Nnodes())
polys = [geometry.Polygon(g.nodes['x'][cycle]) for cycle in cycles]

from shapely import ops

full_poly = ops.cascaded_union(polys)

##
# scale=field.ConstantField(100)
scale = apollo  # out of order, from below

p = paver.Paving(geom=full_poly, density=scale)

p.verbose = 1
p.pave_all()

output_dir = 'grid_v01'
os.path.exists(output_dir) or os.makedirs(output_dir)

p.write_suntans(output_dir)

##

g = unstructured_grid.SuntansGrid(output_dir)
g.write_ugrid(os.path.join(output_dir, 'grid-v01.nc'))