示例#1
0
def test_spacing():
    """Test spacing of nodes."""
    graph = DualHexGraph((20, 31), node_layout='rect1')
    assert_array_almost_equal(graph.length_of_link, 1.)

    graph = DualHexGraph((31, 20), spacing=2, node_layout='rect1')
    assert_array_almost_equal(graph.length_of_link, 2.)
示例#2
0
def test_orientation():
    """Test vertical and horizontal orientation."""
    graph = DualHexGraph((3, 4), orientation='vertical')
    assert_array_almost_equal(graph.y_of_corner,
                              [.5, .5, 1, 1, 1, 1.5, 1.5, 1.5, 2, 2])

    graph = DualHexGraph((4, 3), orientation='horizontal')
    assert_array_almost_equal(graph.x_of_corner,
                              [1.5, 1, 2, 1, 2, .5, 1.5, .5, 1.5, 1])
示例#3
0
def test_orientation():
    """Test vertical and horizontal orientation."""
    graph = DualHexGraph((3, 4), orientation="vertical", sort=True)
    assert_array_almost_equal(
        graph.y_of_corner, [0.5, 0.5, 0.5, 1, 1, 1, 1.5, 1.5, 1.5, 2, 2, 2]
    )

    graph = DualHexGraph((4, 3), orientation="horizontal", sort=True)
    assert_array_almost_equal(
        graph.x_of_corner, [0.5, 1.5, 1, 2, 1, 2, 0.5, 1.5, 0.5, 1.5, 1, 2]
    )
示例#4
0
def test_origin():
    """Test setting the origin."""
    graph = DualHexGraph((4, 3))

    assert graph.y_of_node.min() == approx(0.0)
    assert graph.x_of_node.min() == approx(0.0)
    # assert graph.x_of_corner[0] == approx(1.5)

    graph = DualHexGraph((4, 3), xy_of_lower_left=(0.25, 0.5))

    assert graph.y_of_node.min() == approx(0.5)
    assert graph.x_of_node.min() == approx(0.25)
示例#5
0
def test_origin():
    """Test setting the origin."""
    graph = DualHexGraph((4, 3))

    assert graph.y_of_node[0] == approx(0.)
    assert graph.x_of_node[0] == approx(0.)
    assert graph.x_of_corner[0] == approx(1.5)

    graph = DualHexGraph((4, 3), origin=(.5, .25))

    assert graph.y_of_node[0] == approx(.5)
    assert graph.x_of_node[0] == approx(.25)
    assert graph.x_of_corner[0] == approx(1.75)
示例#6
0
def test_origin():
    """Test setting the origin."""
    graph = DualHexGraph((4, 3))

    assert_almost_equal(graph.y_of_node[0], 0.)
    assert_almost_equal(graph.x_of_node[0], 0.)
    assert_almost_equal(graph.x_of_corner[0], 1.5)

    graph = DualHexGraph((4, 3), origin=(.5, .25))

    assert_almost_equal(graph.y_of_node[0], .5)
    assert_almost_equal(graph.x_of_node[0], .25)
    assert_almost_equal(graph.x_of_corner[0], 1.75)
示例#7
0
def test_create_rect1():
    """Test creating a dual hex graph."""
    graph = DualHexGraph((4, 3), node_layout='rect1')

    assert graph.number_of_nodes == 14
    assert graph.number_of_links == 28
    assert graph.number_of_patches == 15

    assert graph.number_of_corners == 13
    assert graph.number_of_faces == 15
    assert graph.number_of_cells == 3
示例#8
0
def test_create_hex():
    """Test creating a dual hex graph with hex layout."""
    graph = DualHexGraph((4, 3), node_layout='hex')

    assert graph.number_of_nodes == 16
    assert graph.number_of_links == 34
    assert graph.number_of_patches == 19

    assert graph.number_of_corners == 19
    assert graph.number_of_faces == 23
    assert graph.number_of_cells == 5
示例#9
0
def test_create():
    """Test creating a dual hex graph with rectangular layout."""
    graph = DualHexGraph((4, 3), node_layout='rect')

    assert graph.number_of_nodes == 12
    assert graph.number_of_links == 23
    assert graph.number_of_patches == 12

    assert graph.number_of_corners == 10
    assert graph.number_of_faces == 11
    assert graph.number_of_cells == 2
示例#10
0
def test_create_rect1():
    """Test creating a dual hex graph."""
    graph = DualHexGraph((4, 3), node_layout='rect1')

    assert_equal(graph.number_of_nodes, 14)
    assert_equal(graph.number_of_links, 28)
    assert_equal(graph.number_of_patches, 15)

    assert_equal(graph.number_of_corners, 13)
    assert_equal(graph.number_of_faces, 15)
    assert_equal(graph.number_of_cells, 3)
示例#11
0
def test_create_hex():
    """Test creating a dual hex graph with hex layout."""
    graph = DualHexGraph((4, 3), node_layout='hex')

    assert_equal(graph.number_of_nodes, 16)
    assert_equal(graph.number_of_links, 34)
    assert_equal(graph.number_of_patches, 19)

    assert_equal(graph.number_of_corners, 19)
    assert_equal(graph.number_of_faces, 23)
    assert_equal(graph.number_of_cells, 5)
示例#12
0
def test_create():
    """Test creating a dual hex graph with rectangular layout."""
    graph = DualHexGraph((4, 3), node_layout='rect')

    assert_equal(graph.number_of_nodes, 12)
    assert_equal(graph.number_of_links, 23)
    assert_equal(graph.number_of_patches, 12)

    assert_equal(graph.number_of_corners, 10)
    assert_equal(graph.number_of_faces, 11)
    assert_equal(graph.number_of_cells, 2)
示例#13
0
def test_adjacent_corners_at_corner():
    graph = DualHexGraph((3, 3), node_layout='hex')
    assert_array_equal(graph.adjacent_corners_at_corner,
                       [[ 3,  2, -1],
                        [ 4 , 3, -1],
                        [ 5,  0, -1],
                        [ 6,  0,  1],
                        [ 7,  1, -1],
                        [ 8,  2, -1],
                        [ 9,  8,  3],
                        [ 9,  4, -1],
                        [ 5,  6, -1],
                        [ 6,  7, -1]])
示例#14
0
def write_grid_dict_to_json_file(grid_dict, filename):
    """Writes dictionary grid_dict to a JSON file of name <filename>."""
    fp = open(filename, 'w')
    json.dump(grid_dict, fp, sort_keys=True, indent=4, separators=(',', ': '))


# Make a raster graph and grid for testing
rgrid = RasterModelGrid((NUMROWS, NUMCOLS), SPACING)
rgraph = DualUniformRectilinearGraph((NUMROWS, NUMCOLS),
                                     spacing=(SPACING, SPACING))

print('3x4 RASTER GRID:')
print('')
display_grid_data(rgrid)

grid_dict = landlab_grid_to_dict(rgrid, rgraph)

write_grid_dict_to_json_file(grid_dict, 'landlab_raster_grid_example.json')

# Make a hex grid for testing
hgrid = HexModelGrid(NUMROWS, NUMCOLS, SPACING)
hgraph = DualHexGraph((NUMROWS, NUMCOLS), node_layout='hex', spacing=SPACING)

print('HEX GRID:')
print('')
display_grid_data(hgrid)

grid_dict = landlab_grid_to_dict(hgrid, hgraph)

write_grid_dict_to_json_file(grid_dict, 'landlab_hex_grid_example.json')