Ejemplo n.º 1
0
def test_from_file(tmpdir, clock_yaml):
    with tmpdir.as_cwd():
        with open("params.yaml", "w") as fp:
            fp.write(clock_yaml)
        clock = Clock.from_file("./params.yaml")
    assert clock.start == 1.0
    assert clock.stop == 11.0
    assert clock.step == 2.0
Ejemplo n.º 2
0
def test_stochastic_duration_rainfall_means():
    """Test option with stochastic duration.

    Test is simply to get the correct total cumulative rain depth.
    """
    U = 0.0001
    K = 0.0001
    m = 1.0
    n = 1.0

    grid = RasterModelGrid((3, 6), xy_spacing=100.0)
    grid.set_closed_boundaries_at_grid_edges(True, False, True, False)
    grid.add_zeros("node", "topographic__elevation")

    ncnblh = NotCoreNodeBaselevelHandler(grid,
                                         modify_core_nodes=True,
                                         lowering_rate=-U)

    clock = Clock(step=200, stop=400)
    # construct dictionary. note that D is turned off here
    params = {
        "grid": grid,
        "clock": clock,
        "regolith_transport_parameter": 0.0,
        "water_erodibility": K,
        "m_sp": m,
        "n_sp": n,
        "opt_stochastic_duration": True,
        "record_rain": True,
        "mean_storm_duration": 1.0,
        "mean_interstorm_duration": 1.0,
        "infiltration_capacity": 1.0,
        "random_seed": 3141,
        "mean_storm_depth": 1.0,
        "output_interval": 401,
        "depression_finder": "DepressionFinderAndRouter",
        "boundary_handlers": {
            "NotCoreNodeBaselevelHandler": ncnblh
        },
    }

    # construct and run model
    model = BasicSt(**params)
    model.run()

    cum_rain_depth = np.sum(
        np.array(model.rain_record["event_duration"]) *
        np.array(model.rain_record["rainfall_rate"]))
    assert_equal(np.round(cum_rain_depth), 200.0)

    os.remove("storm_sequence.txt")
    fs = glob.glob(model._out_file_name + "*.nc")
    for f in fs:
        os.remove(f)
Ejemplo n.º 3
0
def clock_09():
    clock_09 = Clock(step=2.0, stop=200.0)
    return clock_09
Ejemplo n.º 4
0
def clock_08():
    clock_08 = Clock(step=1.0, stop=20.0)
    return clock_08
Ejemplo n.º 5
0
def clock_07():
    clock_07 = Clock.from_dict({"step": 10.0, "stop": 10000.0})
    return clock_07
Ejemplo n.º 6
0
def clock_06():
    clock_06 = Clock.from_dict({"step": 1.0, "stop": 3.0})
    return clock_06
Ejemplo n.º 7
0
def clock_05():
    clock_05 = Clock.from_dict({"step": 10.0, "stop": 200.0})
    return clock_05
Ejemplo n.º 8
0
def clock_simple():
    clock_simple = Clock(step=1000.0, stop=5.1e6)
    return clock_simple
Ejemplo n.º 9
0
def test_start_larger():
    with pytest.raises(ValueError):
        Clock(stop=-1, step=1)
Ejemplo n.º 10
0
def test_bad_values(bad):
    params = {"start": 0, "stop": 10, "step": 2}
    params[bad] = "spam"
    with pytest.raises(ValueError):
        Clock.from_dict(params)