예제 #1
0
def test_D_infinity_flat_closed_upper():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = mg.add_zeros("node", "topographic__elevation")
    z[mg.core_nodes] -= 1
    mg.set_closed_boundaries_at_grid_edges(
        bottom_is_closed=True,
        left_is_closed=True,
        right_is_closed=True,
        top_is_closed=True,
    )

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    node_ids = np.arange(mg.number_of_nodes)
    true_recievers = -1 * np.ones(fd.receivers.shape)
    true_recievers[:, 0] = node_ids

    true_proportions = np.zeros(fd.proportions.shape)
    true_proportions[:, 0] = 1

    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(
        np.round(fd.proportions, decimals=6), np.round(true_proportions, decimals=6)
    )
예제 #2
0
def test_route_to_many():
    mg = RasterModelGrid((5, 5))
    mg.add_zeros("node", "topographic__elevation", dtype=float)
    fd = FlowDirectorDINF(mg, "topographic__elevation")
    fd.run_one_step()
    assert mg.at_node["flow__receiver_node"].shape == (mg.number_of_nodes, 2)
    with pytest.raises(NotImplementedError):
        LakeMapperBarnes(mg, method="D8", redirect_flow_steepest_descent=True)
예제 #3
0
def test_route_to_many():
    mg = RasterModelGrid((5, 5))
    mg.add_zeros("node", "topographic__elevation", dtype=float)
    fd = FlowDirectorDINF(mg, "topographic__elevation")
    fd.run_one_step()
    assert mg.at_node["flow__receiver_node"].shape == (mg.number_of_nodes, 2)
    with pytest.raises(NotImplementedError):
        LakeMapperBarnes(mg, method="D8", redirect_flow_steepest_descent=True)
예제 #4
0
def test_D_infinity_open_boundary_conditions():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = mg.x_of_node + 2. * mg.y_of_node
    mg.add_field("node", "topographic__elevation", z)

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    true_recievers = np.array([
        [0, -1],
        [1, -1],
        [2, -1],
        [3, -1],
        [4, -1],
        [1, 0],
        [2, 1],
        [7, -1],
        [8, -1],
        [5, 4],
        [6, 5],
        [11, -1],
        [12, -1],
        [9, 8],
        [10, 9],
        [15, -1],
        [16, -1],
        [17, -1],
        [18, -1],
        [19, -1],
    ])

    true_proportions = np.array([
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [0.40966553, 0.59033447],
        [0.40966553, 0.59033447],
        [1., 0.],
        [1., 0.],
        [0.40966553, 0.59033447],
        [0.40966553, 0.59033447],
        [1., 0.],
        [1., 0.],
        [0.40966553, 0.59033447],
        [0.40966553, 0.59033447],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
    ])
    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(np.round(fd.proportions, decimals=6),
                       np.round(true_proportions, decimals=6))
예제 #5
0
def test_D_infinity_flat():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    mg.add_zeros("node", "topographic__elevation")

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    node_ids = np.arange(mg.number_of_nodes)
    true_recievers = -1 * np.ones(fd.receivers.shape)
    true_recievers[:, 0] = node_ids

    true_proportions = np.zeros(fd.proportions.shape)
    true_proportions[:, 0] = 1

    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(np.round(fd.proportions, decimals=6),
                       np.round(true_proportions, decimals=6))
예제 #6
0
def test_D_infinity_flat():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    mg.add_zeros("node", "topographic__elevation")

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    node_ids = np.arange(mg.number_of_nodes)
    true_recievers = -1 * np.ones(fd.receivers.shape)
    true_recievers[:, 0] = node_ids

    true_proportions = np.zeros(fd.proportions.shape)
    true_proportions[:, 0] = 1

    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(
        np.round(fd.proportions, decimals=6), np.round(true_proportions, decimals=6)
    )
예제 #7
0
def test_D_infinity_flat_closed_upper():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = mg.add_zeros("node", "topographic__elevation")
    z[mg.core_nodes] -= 1
    mg.set_closed_boundaries_at_grid_edges(
        bottom_is_closed=True,
        left_is_closed=True,
        right_is_closed=True,
        top_is_closed=True,
    )

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    node_ids = np.arange(mg.number_of_nodes)
    true_recievers = -1 * np.ones(fd.receivers.shape)
    true_recievers[:, 0] = node_ids

    true_proportions = np.zeros(fd.proportions.shape)
    true_proportions[:, 0] = 1

    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(np.round(fd.proportions, decimals=6),
                       np.round(true_proportions, decimals=6))
예제 #8
0
def test_D_infinity_open_boundary_conditions():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = mg.x_of_node + 2.0 * mg.y_of_node
    mg.add_field("node", "topographic__elevation", z)

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    true_recievers = np.array(
        [
            [0, -1],
            [1, -1],
            [2, -1],
            [3, -1],
            [4, -1],
            [1, 0],
            [2, 1],
            [7, -1],
            [8, -1],
            [5, 4],
            [6, 5],
            [11, -1],
            [12, -1],
            [9, 8],
            [10, 9],
            [15, -1],
            [16, -1],
            [17, -1],
            [18, -1],
            [19, -1],
        ]
    )

    true_proportions = np.array(
        [
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [0.40966553, 0.59033447],
            [0.40966553, 0.59033447],
            [1.0, 0.0],
            [1.0, 0.0],
            [0.40966553, 0.59033447],
            [0.40966553, 0.59033447],
            [1.0, 0.0],
            [1.0, 0.0],
            [0.40966553, 0.59033447],
            [0.40966553, 0.59033447],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
        ]
    )
    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(
        np.round(fd.proportions, decimals=6), np.round(true_proportions, decimals=6)
    )
예제 #9
0
def test_D_infinity_low_closed_boundary_conditions():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = np.array(
        [[0, 0, 0, 0], [0, 21, 10, 0], [0, 31, 20, 0], [0, 32, 30, 0], [0, 0, 0, 0]],
        dtype="float64",
    )
    mg.add_field("node", "topographic__elevation", z)
    mg.set_closed_boundaries_at_grid_edges(
        bottom_is_closed=True,
        left_is_closed=True,
        right_is_closed=True,
        top_is_closed=True,
    )

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    true_recievers = np.array(
        [
            [0, -1],
            [1, -1],
            [2, -1],
            [3, -1],
            [4, -1],
            [6, -1],
            [6, -1],
            [7, -1],
            [8, -1],
            [10, 6],
            [6, -1],
            [11, -1],
            [12, -1],
            [10, -1],
            [10, -1],
            [15, -1],
            [16, -1],
            [17, -1],
            [18, -1],
            [19, -1],
        ]
    )

    true_proportions = np.array(
        [
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [0.06058469, 0.93941531],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
            [1.0, 0.0],
        ]
    )
    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(
        np.round(fd.proportions, decimals=6), np.round(true_proportions, decimals=6)
    )
예제 #10
0
def test_D_infinity_low_closed_boundary_conditions():
    mg = RasterModelGrid((5, 4), xy_spacing=(1, 1))
    z = np.array(
        [[0, 0, 0, 0], [0, 21, 10, 0], [0, 31, 20, 0], [0, 32, 30, 0],
         [0, 0, 0, 0]],
        dtype="float64",
    )
    mg.add_field("node", "topographic__elevation", z)
    mg.set_closed_boundaries_at_grid_edges(
        bottom_is_closed=True,
        left_is_closed=True,
        right_is_closed=True,
        top_is_closed=True,
    )

    fd = FlowDirectorDINF(mg)
    fd.run_one_step()

    true_recievers = np.array([
        [0, -1],
        [1, -1],
        [2, -1],
        [3, -1],
        [4, -1],
        [6, -1],
        [6, -1],
        [7, -1],
        [8, -1],
        [10, 6],
        [6, -1],
        [11, -1],
        [12, -1],
        [10, -1],
        [10, -1],
        [15, -1],
        [16, -1],
        [17, -1],
        [18, -1],
        [19, -1],
    ])

    true_proportions = np.array([
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [0.06058469, 0.93941531],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
        [1., 0.],
    ])
    assert_array_equal(fd.receivers, true_recievers)
    assert_array_equal(np.round(fd.proportions, decimals=6),
                       np.round(true_proportions, decimals=6))