def test_raster_spacing_as_scalar(): """Test the spacing keyword as a scalar for raster.""" graph = DualUniformRectilinearGraph((3, 4), spacing=2.0) assert_array_equal( graph.length_of_link, [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, ], ) assert_array_equal(graph.length_of_face, [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0])
def test_link_at_face(): """Test link-face connectivity.""" graph = DualUniformRectilinearGraph((3, 4)) assert_array_equal(graph.link_at_face, [4, 5, 7, 8, 9, 11, 12]) assert_array_equal( graph.face_at_link, [-1, -1, -1, -1, 0, 1, -1, 2, 3, 4, -1, 5, 6, -1, -1, -1, -1])
def test_raster_spacing(): """Test the spacing keyword for raster.""" graph = DualUniformRectilinearGraph((3, 4), spacing=(2.0, 3.0)) assert_array_equal( graph.length_of_link, [ 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, ], ) assert_array_equal(graph.length_of_face, [3.0, 3.0, 2.0, 2.0, 2.0, 3.0, 3.0])
def test_corner_at_face(): """Test corner-face connectivity.""" graph = DualUniformRectilinearGraph((3, 4)) assert_array_equal( graph.corners_at_face, [[0, 1], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5]]) assert_array_equal(graph.corner_at_face_tail, [0, 1, 0, 1, 2, 3, 4]) assert_array_equal(graph.corner_at_face_head, [1, 2, 3, 4, 5, 4, 5])
def test_cell_at_node(): """Test cell-node connectivity.""" y = [0, 1, 3, 0, 1, 3, 0, 1, 3] x = [3, 3, 3, 4, 4, 4, 6, 6, 6] graph = DualStructuredQuadGraph((y, x), shape=(3, 3)) assert_array_equal(graph.cell_at_node, [-1, -1, -1, -1, 0, -1, -1, -1, -1]) graph = DualUniformRectilinearGraph((3, 4)) assert_array_equal(graph.cell_at_node, [-1, -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1])
def test_create_raster(): """Test creating a quad graph.""" graph = DualUniformRectilinearGraph((3, 4), spacing=(2.0, 3.0)) assert graph.number_of_nodes == 12 assert graph.number_of_links == 17 assert graph.number_of_patches == 6 assert graph.number_of_corners == 6 assert graph.number_of_faces == 7 assert graph.number_of_cells == 2
def test_raster_origin_as_scalar(): """Test the origin keyword as a scalar for raster.""" graph = DualUniformRectilinearGraph((3, 4), origin=-1.) assert_array_equal(graph.xy_of_node[:, 0], [-1., 0., 1., 2., -1., 0., 1., 2., -1., 0., 1., 2.]) assert_array_equal(graph.xy_of_node[:, 1], [-1., -1., -1., -1., 0., 0., 0., 0., 1., 1., 1., 1.]) assert_array_equal(graph.xy_of_corner[:, 0], [-.5, .5, 1.5, -.5, .5, 1.5]) assert_array_equal(graph.xy_of_corner[:, 1], [-.5, -.5, -.5, .5, .5, .5])
def test_create_raster(): """Test creating a quad graph.""" graph = DualUniformRectilinearGraph((3, 4), spacing=(2., 3.)) assert_equal(graph.number_of_nodes, 12) assert_equal(graph.number_of_links, 17) assert_equal(graph.number_of_patches, 6) assert_equal(graph.number_of_corners, 6) assert_equal(graph.number_of_faces, 7) assert_equal(graph.number_of_cells, 2)
def test_raster_origin(): """Test the origin keyword for raster.""" graph = DualUniformRectilinearGraph((3, 4), origin=(-1., 10.)) assert_array_equal( graph.xy_of_node[:, 0], [10., 11., 12., 13., 10., 11., 12., 13., 10., 11., 12., 13.]) assert_array_equal(graph.xy_of_node[:, 1], [-1., -1., -1., -1., 0., 0., 0., 0., 1., 1., 1., 1.]) assert_array_equal(graph.xy_of_corner[:, 0], [10.5, 11.5, 12.5, 10.5, 11.5, 12.5]) assert_array_equal(graph.xy_of_corner[:, 1], [-.5, -.5, -.5, .5, .5, .5])
# ... and add it to the dict grid_dict['patches'] = my_list return grid_dict 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('')