Exemple #1
0
def test_flow__distance_irregular_grid_d4():
    """Test to demonstrate that flow__distance utility works as expected with irregular grids"""

    # instantiate a model grid

    dx = 1.0
    hmg = HexModelGrid((5, 3), spacing=dx)

    # instantiate and add the elevation field

    hmg.add_field(
        "topographic__elevation", hmg.node_x + np.round(hmg.node_y), at="node"
    )

    # instantiate the expected flow__distance array

    flow__distance_expected = np.array(
        [
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            dx,
            0.0,
            0.0,
            dx,
            dx,
            2.0 * dx,
            0.0,
            0.0,
            2.0 * dx,
            2.0 * dx,
            0.0,
            0.0,
            0.0,
            0.0,
        ]
    )

    # setting boundary conditions

    hmg.status_at_node[hmg.boundary_nodes] = hmg.BC_NODE_IS_CLOSED

    # calculating flow directions with FlowAccumulator component: D4 algorithm

    fr = FlowAccumulator(hmg, flow_director="D4")
    fr.run_one_step()

    # calculating flow distance map

    flow__distance = calculate_flow__distance(hmg, add_to_grid=True, clobber=True)

    # test that the flow__distance utility works as expected

    assert_almost_equal(flow__distance_expected, flow__distance, decimal=10)
def test_flow__distance_irregular_grid_d4():
    """Test to demonstrate that flow__distance utility works as expected with irregular grids"""

    # instantiate a model grid

    dx = 1.0
    hmg = HexModelGrid(5, 3, dx)

    # instantiate and add the elevation field

    hmg.add_field(
        "topographic__elevation", hmg.node_x + np.round(hmg.node_y), at="node"
    )

    # instantiate the expected flow__distance array

    flow__distance_expected = np.array(
        [
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            dx,
            0.0,
            0.0,
            dx,
            dx,
            2.0 * dx,
            0.0,
            0.0,
            2.0 * dx,
            2.0 * dx,
            0.0,
            0.0,
            0.0,
            0.0,
        ]
    )

    # setting boundary conditions

    hmg.set_closed_nodes(hmg.boundary_nodes)

    # calculating flow directions with FlowAccumulator component: D4 algorithm

    fr = FlowAccumulator(hmg, flow_director="D4")
    fr.run_one_step()

    # calculating flow distance map

    flow__distance = calculate_flow__distance(hmg, add_to_grid=True, noclobber=False)

    # test that the flow__distance utility works as expected

    assert_almost_equal(flow__distance_expected, flow__distance, decimal=10)
def test_grid_type_testing():
    """Test that only the right grids can be implemented."""
    dx = (2.0 / (3.0 ** 0.5)) ** 0.5
    hmg = HexModelGrid(3, 3, dx)
    hmg.add_field(
        "topographic__elevation", hmg.node_x + np.round(hmg.node_y), at="node"
    )

    # D8 is ONLY RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorD8(hmg)

    # DINF IS ONLY RASTER RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorDINF(hmg)
def test_grid_type_testing():
    """Test that only the right grids can be implemented."""
    dx = (2. / (3.**0.5))**0.5
    hmg = HexModelGrid(9, 5, dx)
    hmg.add_field("topographic__elevation",
                  hmg.node_x + np.round(hmg.node_y),
                  at="node")

    # D8 is ONLY RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorD8(hmg)

    # DINF IS ONLY RASTER RASTER
    with pytest.raises(NotImplementedError):
        FlowDirectorDINF(hmg)
Exemple #5
0
def test_hex_mfd():
    mg = HexModelGrid(5, 3)
    z = mg.add_field("topographic__elevation",
                     mg.node_x + mg.node_y,
                     at="node")
    fa = FlowAccumulator(mg, flow_director="MFD")
    fa.run_one_step()
def test_with_lake_mapper_barnes():
    hmg_hole = HexModelGrid((9, 5))
    z = hmg_hole.add_field(
        "topographic__elevation",
        hmg_hole.x_of_node + np.round(hmg_hole.y_of_node),
        at="node",
    )
    hole_nodes = [21, 22, 23, 30, 31, 39, 40]
    z[hole_nodes] = z[hole_nodes] * 0.1
    hmg_hole.add_zeros("filled__elevation", at="node")
    fa = FlowAccumulator(
        hmg_hole,
        flow_director="Steepest",
        depression_finder="LakeMapperBarnes",
        fill_flat=False,
        redirect_flow_steepest_descent=True,
        reaccumulate_flow=True,
        fill_surface="filled__elevation",
    )
    fa.run_one_step()

    rcvrs = hmg_hole.at_node["flow__receiver_node"]
    assert_array_equal(rcvrs[[13, 21, 46]], [6, 13, 39])

    from landlab.components import LakeMapperBarnes

    fa = FlowAccumulator(hmg_hole, depression_finder=LakeMapperBarnes)
    lmb = LakeMapperBarnes(hmg_hole)
    fa = FlowAccumulator(hmg_hole, depression_finder=lmb)
Exemple #7
0
def test_flow__distance_irregular_grid_d4():
    """Test to demonstrate that flow__distance utility works as expected with irregular grids"""

    # instantiate a model grid

    dx = 1.0
    hmg = HexModelGrid(5, 3, dx)

    # instantiate and add the elevation field

    hmg.add_field('topographic__elevation',
                  hmg.node_x + np.round(hmg.node_y),
                  at='node')

    # instantiate the expected flow__distance array

    flow__distance_expected = np.array([
        0., 0., 0., 0., 0., dx, 0., 0., dx, dx, 2. * dx, 0., 0., 2. * dx,
        2. * dx, 0., 0., 0., 0.
    ])

    #setting boundary conditions

    hmg.set_closed_nodes(hmg.boundary_nodes)

    # calculating flow directions with FlowAccumulator component: D4 algorithm

    fr = FlowAccumulator(hmg, flow_director='D4')
    fr.run_one_step()

    # calculating flow distance map

    flow__distance = calculate_flow__distance(hmg,
                                              add_to_grid=True,
                                              noclobber=False)

    # test that the flow__distance utility works as expected

    assert_almost_equal(flow__distance_expected, flow__distance, decimal=10)
Exemple #8
0
def test_grid_type_testing():
    """Test that only the right grids can be implemented."""
    dx = (2. / (3.**0.5))**0.5
    hmg = HexModelGrid(9, 5, dx)
    z = hmg.add_field('topographic__elevation',
                      hmg.node_x + np.round(hmg.node_y),
                      at='node')

    # D8 is ONLY RASTER
    assert_raises(NotImplementedError, FlowDirectorD8, hmg)

    # DINF IS ONLY RASTER RASTER
    assert_raises(NotImplementedError, FlowDirectorDINF, hmg)
def test_hex_mfd():
    mg = HexModelGrid(5, 3)
    mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")
    fa = LossyFlowAccumulator(mg, flow_director="MFD")
    fa.run_one_step()
def test_hex_mfd():
    # %%
    mg = HexModelGrid((5, 3))
    mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")
    with pytest.raises(FieldError):
        PriorityFloodFlowRouter(mg, flow_metric="MFD", suppress_out=True)