Exemple #1
0
def test_get_downslope_neighbors_large():

    num_of_cols = 6
    num_of_rows = 5

    heights = np.array([5, 7, 8, 7, 6, 0, 7, 2, 10, 10, 7, 6, 7, 2, 4, 5, 5, 4, 7, 7, 3.9, 4, 0, 0, 6, 5, 4, 4, 0, 0])
    result_downslope_neighbors = np.array([7, 7, 7, 4, 5, -1, 7, -1, 7, 15, 5, 5, 13, -1, 13, 22, 22,
                                           23, 13, 13, 13, 22, -1, -1, 25, 26, 20, 28, -1, -1])

    downslope_neighbors = util.get_downslope_indices(num_of_cols, num_of_rows, heights)

    assert np.array_equal(downslope_neighbors, result_downslope_neighbors)
Exemple #2
0
def test_get_downslope_neighbors():

    num_of_cols = 3
    num_of_rows = 3
    indices = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8])
    heights = np.array([10, 9, 7, 9, 5, 3, 7, 3, 1])

    result_downslope_neighbors = np.array([4, 5, 5, 7, 8, 8, 7, 8, -1])

    downslope_neighbors = util.get_downslope_indices(num_of_cols, num_of_rows, heights)

    assert np.array_equal(downslope_neighbors, result_downslope_neighbors)
Exemple #3
0
def get_watersheds(heights, num_of_cols, num_of_rows):
    """
    Returns all watersheds in an area given the heights of the landscape
    :param heights: z-coordinate for all indices
    :param num_of_cols: Number of grid points in x-direction
    :param num_of_rows: Number of grid points in y-direction
    :return nodes_in_watersheds: List of arrays where each array is a watershed and its nodes
    """

    downslope_neighbors = util.get_downslope_indices(num_of_cols, num_of_rows, heights)
    endpoints = get_node_endpoints(num_of_cols, num_of_rows, downslope_neighbors)
    minimum_indices = np.where(downslope_neighbors == -1)[0]

    minimums_in_watersheds = sorted(get_minimums_in_watersheds(minimum_indices, num_of_cols, num_of_rows))
    nodes_in_watersheds = get_nodes_in_watersheds(endpoints, minimums_in_watersheds)

    return nodes_in_watersheds
Exemple #4
0
def get_nr_of_upstream_nodes(heights, nx, ny):

    downslope_indices = util.get_downslope_indices(nx, ny, heights)
    indices = np.arange(0, len(heights), 1)
    minima = np.where(downslope_indices == -1)[0]
    u, count = np.unique(downslope_indices, return_counts=True)
    u = u[1:]
    count = count[1:]

    counter = np.zeros(len(heights), dtype=int)

    counter[u] = count
    non_min = np.setdiff1d(indices, minima)
    index = non_min[np.where(counter[non_min] != 0)[0]]
    counter[downslope_indices[index]] += sum(counter[index])

    return counter
import util
import trap_analysis
import time

saved_files = '/home/shomea/a/anderovo/Dropbox/watershedLargeFiles/'
file_name = saved_files + 'anders_hoh.tiff'


"""
 Save the watershed using pickle and numpy save.
"""

landscape = load_geotiff.get_landscape_tyrifjorden(file_name)

# Get downslope neighbors
downslope_neighbors = util.get_downslope_indices(landscape.num_of_nodes_x, landscape.num_of_nodes_y,
                                                 landscape.coordinates[:, 2])

# Get endpoints
endpoints = trap_analysis.get_node_endpoints(landscape.num_of_nodes_x, landscape.num_of_nodes_y, downslope_neighbors)

# Get minimums in each watershed
minimum_indices = np.where(downslope_neighbors == -1)[0]
minimums_in_each_watershed = sorted(trap_analysis.get_minimums_in_watersheds(minimum_indices, landscape.num_of_nodes_x,
                                    landscape.num_of_nodes_y))

# Get indices leading to endpoints
indices_leading_to_endpoints = trap_analysis.get_indices_leading_to_endpoints(endpoints)

# Get the nodes in the watersheds. Save to file.
nodes_in_watersheds = trap_analysis.get_nodes_in_watersheds(endpoints, minimums_in_each_watershed)
cPickle.dump(nodes_in_watersheds, open('nodesInWatershedsStandard.pkl', 'wb'))
Exemple #6
0
#                                                 landscape.coordinates[:, 2])
# Get endpoints
#endpoints = trap_analysis.get_node_endpoints(landscape.num_of_nodes_x, landscape.num_of_nodes_y, downslope_neighbors)
#nr_of_upstream_nodes = rivers.get_rivers(endpoints)


#nx = 3
#ny = 3
#heights = np.array([0, 1, 2, 1, 2, 3, 2, 3, 1])
#indices = np.arange(0, len(heights), 1)

nx = 6
ny = 5
heights = np.array([5, 7, 8, 7, 6, 0, 7, 2, 10, 10, 7, 6, 7, 2, 4, 5, 5, 4, 7, 7, 3.9, 4, 0, 0, 6, 5, 4, 4, 0, 0])
indices = np.arange(0, len(heights), 1)
downslope_indices = util.get_downslope_indices(nx, ny, heights)
#print downslope_indices
#
#minimas = np.where(downslope_indices == -1)[0]
#print minimas
#u, count = np.unique(downslope_indices, return_counts=True)
#u = u[1:]
#count = count[1:]
#print u, count
#
#counter = np.zeros(len(heights), dtype=int)
#
#counter[u] = count
#non_min = np.setdiff1d(indices, minimas)
#print non_min
#index = non_min[np.where(counter[non_min] != 0)[0]]