Example #1
0
def get_lowest_landscape_boundary_for_watersheds(watersheds, heights, nx, ny):
    """
    Return an array with the lowest landscape boundary height for the watersheds. If the watershed doesn't have a
    landscape boundary, that number will be -1.
    :param watersheds: List of all watersheds.
    :param heights: The heights of all nodes.
    :param nx: Number of nodes in the x-direction.
    :param ny: Number of nodes in the y-direction.
    :return lowest_landscape_boundary_for_ws: The lowest value the landscape boundary attains in the watershed. If there
    is no such value, it is set to -1.
    """

    boundary_nodes = util.get_boundary_indices(nx, ny)
    mapping_nodes_to_watersheds = map_nodes_to_watersheds(watersheds, nx * ny)
    map_boundary_nodes_watershed = mapping_nodes_to_watersheds[boundary_nodes]
    indices_of_ws_with_boundary, nr_of_boundary_nodes_in_watersheds = np.unique(map_boundary_nodes_watershed,
                                                                                return_counts=True)
    combined = np.vstack((map_boundary_nodes_watershed, boundary_nodes))
    combined_sorted_indices = np.argsort(combined[0])
    combined = combined[:, combined_sorted_indices]

    boundary_nodes_in_each_ws = np.split(combined[1, :], np.cumsum(nr_of_boundary_nodes_in_watersheds))[0:-1]
    min_of_boundary_on_watersheds = np.array([np.amin(heights[arr]) for arr in boundary_nodes_in_each_ws])
    lowest_landscape_boundary_for_ws = np.ones(len(watersheds), dtype=float) * -1

    lowest_landscape_boundary_for_ws[indices_of_ws_with_boundary] = min_of_boundary_on_watersheds

    return lowest_landscape_boundary_for_ws
Example #2
0
def test_get_boundary_indices_rectangular():

    num_of_cols = 4
    num_of_rows = 3
    result_boundary_indices = np.array([0, 1, 2, 3, 4, 7, 8, 9, 10, 11])

    boundary_indices = util.get_boundary_indices(num_of_cols, num_of_rows)

    assert np.array_equal(boundary_indices, result_boundary_indices)
Example #3
0
def test_get_boundary_indices_square():

    num_of_cols = 3
    num_of_rows = 3
    result_boundary_indices = np.array([0, 1, 2, 3, 5, 6, 7, 8])

    boundary_indices = util.get_boundary_indices(num_of_cols, num_of_rows)

    assert np.array_equal(boundary_indices, result_boundary_indices)