Exemple #1
0
def test_passing_neither_lowering_method():
    """Test passing no lowering information."""
    mg = RasterModelGrid((5, 5))
    mg.add_zeros("node", "topographic__elevation")

    with pytest.raises(ValueError):
        NotCoreNodeBaselevelHandler(mg)
Exemple #2
0
def test_pass_two_boundary_handlers(clock_simple, simple_square_grid, U):
    ncnblh = NotCoreNodeBaselevelHandler(simple_square_grid,
                                         modify_core_nodes=True,
                                         lowering_rate=-U)
    snblh = SingleNodeBaselevelHandler(simple_square_grid,
                                       modify_outlet_node=False,
                                       lowering_rate=-U)
    params = {
        "grid": simple_square_grid,
        "clock": clock_simple,
        "boundary_handlers": {
            "mybh1": ncnblh,
            "mybh2": snblh
        },
    }
    model = Basic(**params)
    model.run_one_step(1.0)

    truth = np.zeros(model.z.size)
    truth[0] -= U
    truth[model.grid.core_nodes] += U
    assert_array_equal(model.z, truth)

    status_at_node = np.zeros(model.z.size)
    status_at_node[model.grid.boundary_nodes] = CLOSED_BOUNDARY
    status_at_node[0] = FIXED_VALUE_BOUNDARY
    assert_array_equal(model.grid.status_at_node, status_at_node)
Exemple #3
0
def test_outlet_lowering_object_bad_file():
    """Test using an outlet lowering object with a bad file."""

    mg = HexModelGrid((5, 5))
    mg.add_zeros("node", "topographic__elevation")

    with pytest.raises(ValueError):
        NotCoreNodeBaselevelHandler(mg, lowering_file_path="foo.txt")
Exemple #4
0
def test_passing_both_lowering_methods():
    """Test passing both lowering methods."""
    mg = RasterModelGrid((5, 5))
    mg.add_zeros("node", "topographic__elevation")
    file = os.path.join(_TEST_DATA_DIR, "outlet_history.txt")

    with pytest.raises(ValueError):
        NotCoreNodeBaselevelHandler(
            mg, lowering_rate=-0.1, lowering_file_path=file
        )
Exemple #5
0
def test_hex():
    """Test using a hex grid."""

    mg = HexModelGrid((5, 5))
    z = mg.add_zeros("node", "topographic__elevation")

    bh = NotCoreNodeBaselevelHandler(
        mg, modify_core_nodes=False, lowering_rate=-0.1
    )
    bh.run_one_step(10.0)

    closed = mg.status_at_node != 0
    not_closed = mg.status_at_node == 0

    # closed should have been downdropped 10*0.1
    assert_array_equal(z[closed], -1.0 * np.ones(np.sum(closed)))

    # not closed should have stayed the same
    assert_array_equal(z[not_closed], np.zeros(np.sum(not_closed)))
Exemple #6
0
def test_outlet_lowering_object_no_scaling():
    """Test using an outlet lowering object with no scaling."""

    mg = HexModelGrid((5, 5))
    z = mg.add_ones("node", "topographic__elevation")
    file = os.path.join(_TEST_DATA_DIR, "outlet_history.txt")
    bh = NotCoreNodeBaselevelHandler(
        mg, modify_core_nodes=False, lowering_file_path=file
    )
    for _ in range(241):
        bh.run_one_step(10)

    closed = mg.status_at_node != 0
    not_closed = mg.status_at_node == 0

    # not closed should have stayed the same
    assert_array_equal(z[not_closed], np.ones(np.sum(not_closed)))

    # closed should lowered by 47.5  to -46.5
    assert_array_equal(z[closed], -46.5 * np.ones(np.sum(closed)))
Exemple #7
0
def test_outlet_lowering_rate_no_scaling_bedrock():
    """Test using an outlet lowering rate with no scaling and bedrock."""

    mg = RasterModelGrid((5, 5))
    z = mg.add_ones("node", "topographic__elevation")
    b = mg.add_zeros("node", "bedrock__elevation")

    bh = NotCoreNodeBaselevelHandler(
        mg, modify_core_nodes=True, lowering_rate=-0.1
    )
    for _ in range(240):
        bh.run_one_step(10)

    closed = mg.status_at_node != 0
    not_closed = mg.status_at_node == 0

    # closed should have stayed the same
    assert_array_equal(z[closed], np.ones(np.sum(closed)))
    assert_array_equal(b[closed], np.zeros(np.sum(closed)))

    # not closed should have been uplifted 2410*0.1
    assert_array_equal(b[not_closed], 240.0 * np.ones(np.sum(not_closed)))
    assert_array_equal(z[not_closed], 241.0 * np.ones(np.sum(not_closed)))

    # % doing the oposite should also work
    mg = RasterModelGrid((5, 5))
    z = mg.add_ones("node", "topographic__elevation")
    b = mg.add_zeros("node", "bedrock__elevation")

    bh = NotCoreNodeBaselevelHandler(
        mg, modify_core_nodes=False, lowering_rate=-0.1
    )
    for _ in range(240):
        bh.run_one_step(10)

    closed = mg.status_at_node != 0
    not_closed = mg.status_at_node == 0

    # not closed should have staued the same
    assert_array_equal(z[not_closed], np.ones(np.sum(not_closed)))
    assert_array_equal(b[not_closed], np.zeros(np.sum(not_closed)))

    # closed should have lowered by 240
    assert_array_equal(b[closed], -240.0 * np.ones(np.sum(closed)))
    assert_array_equal(z[closed], -239.0 * np.ones(np.sum(closed)))