示例#1
0
def test_make_grid_uh(fdr_vic_small, dy_vic, dx_vic, pour_point):
    ndays = 4
    t_uh = 40
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    catchment, _ = search_catchment(to_y, to_x, pour_point, basin_ids,
                                    basin_id)
    uh_river = np.zeros((t_uh, ) + fdr_vic_small.shape)
    uh_river[0] = 1.0
    uh_box = np.array([1.0, 0, 0, 0])
    unit_hydrograph = make_grid_uh(
        t_uh,
        ndays,
        uh_river,
        uh_box,
        to_y,
        to_x,
        catchment["y_inds"],
        catchment["x_inds"],
        catchment["count_ds"],
    )
    assert unit_hydrograph.shape[0] == t_uh
    assert unit_hydrograph.max() <= 1.0
    assert unit_hydrograph.min() >= 0.0
    np.testing.assert_almost_equal(
        unit_hydrograph.sum(axis=0)[catchment["y_inds"], catchment["x_inds"]],
        1)
示例#2
0
def test_make_grid_uh_river(fdr_vic_small, dy_vic, dx_vic, pour_point):
    ndays = 4
    t_uh = 40
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    uh = np.zeros((ndays, ) + fdr_vic_small.shape)
    uh[0, :, :] = 1.0
    catchment, _ = search_catchment(to_y, to_x, pour_point, basin_ids,
                                    basin_id)
    uh_river = make_grid_uh_river(
        t_uh,
        ndays,
        uh,
        to_y,
        to_x,
        pour_point,
        catchment["y_inds"],
        catchment["x_inds"],
        catchment["count_ds"],
    )
    assert uh_river.shape[0] == t_uh
    assert uh_river.max() <= 1.0
    assert uh_river.min() >= 0.0
    np.testing.assert_almost_equal(
        uh_river.sum(axis=0)[catchment["y_inds"], catchment["x_inds"]], 1)
示例#3
0
def test_search_catchment(fdr_vic_small, dy_vic, dx_vic, pour_point):
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    catchment, catch_fracs = search_catchment(to_y, to_x, pour_point,
                                              basin_ids, basin_id)
    assert catch_fracs.min() <= 0.0
    assert catch_fracs.max() == 1.0
    assert type(catchment) == dict
    assert all([k in catchment for k in ["count_ds", "x_inds", "y_inds"]])
    assert len(catchment["count_ds"]) > 0
    assert len(catchment["count_ds"]) == len(catchment["x_inds"])
    assert len(catchment["count_ds"]) == len(catchment["y_inds"])
示例#4
0
def test_search_catchment(fdr_vic_small, dy_vic, dx_vic, pour_point):
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    catchment, catch_fracs = search_catchment(to_y, to_x, pour_point,
                                              basin_ids, basin_id)
    assert catch_fracs.min() <= 0.
    assert catch_fracs.max() == 1.
    assert type(catchment) == dict
    assert all([k in catchment for k in ['count_ds', 'x_inds', 'y_inds']])
    assert len(catchment['count_ds']) > 0
    assert len(catchment['count_ds']) == len(catchment['x_inds'])
    assert len(catchment['count_ds']) == len(catchment['y_inds'])
示例#5
0
def test_make_grid_uh_river(fdr_vic_small, dy_vic, dx_vic, pour_point):
    ndays = 4
    t_uh = 40
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    uh = np.zeros((ndays, ) + fdr_vic_small.shape)
    uh[0, :, :] = 1.
    catchment, _ = search_catchment(to_y, to_x, pour_point,
                                    basin_ids, basin_id)
    uh_river = make_grid_uh_river(t_uh, ndays, uh, to_y, to_x, pour_point,
                                  catchment['y_inds'], catchment['x_inds'],
                                  catchment['count_ds'])
    assert uh_river.shape[0] == t_uh
    assert uh_river.max() <= 1.
    assert uh_river.min() >= 0.
    np.testing.assert_almost_equal(uh_river.sum(axis=0)[catchment['y_inds'],
                                                        catchment['x_inds']],
                                   1)
示例#6
0
def test_make_grid_uh(fdr_vic_small, dy_vic, dx_vic, pour_point):
    ndays = 4
    t_uh = 40
    basin_ids = np.ones_like(fdr_vic_small, dtype=np.int)
    basin_id = 1
    to_y, to_x = read_direction(fdr_vic_small, dy_vic, dx_vic)
    catchment, _ = search_catchment(to_y, to_x, pour_point,
                                    basin_ids, basin_id)
    uh_river = np.zeros((t_uh, ) + fdr_vic_small.shape)
    uh_river[0] = 1.
    uh_box = np.array([1., 0, 0, 0])
    unit_hydrograph = make_grid_uh(t_uh, ndays, uh_river, uh_box, to_y, to_x,
                                   catchment['y_inds'], catchment['x_inds'],
                                   catchment['count_ds'])
    assert unit_hydrograph.shape[0] == t_uh
    assert unit_hydrograph.max() <= 1.
    assert unit_hydrograph.min() >= 0.
    np.testing.assert_almost_equal(
        unit_hydrograph.sum(axis=0)[catchment['y_inds'], catchment['x_inds']],
        1)
示例#7
0
def test_read_direction(fdr_vic, dy_vic, dx_vic):
    to_y, to_x = read_direction(fdr_vic, dy_vic, dx_vic)
    np.testing.assert_equal(to_y.shape, to_x.shape)
    assert to_y.max() <= fdr_vic.shape[0] + 1
    assert to_x.max() <= fdr_vic.shape[1] + 1
示例#8
0
def test_read_direction(fdr_vic, dy_vic, dx_vic):
    to_y, to_x = read_direction(fdr_vic, dy_vic, dx_vic)
    np.testing.assert_equal(to_y.shape, to_x.shape)
    assert to_y.max() <= fdr_vic.shape[0] + 1
    assert to_x.max() <= fdr_vic.shape[1] + 1