def test_get_minimums_in_watersheds(): num_of_cols = 6 num_of_rows = 5 minimum_indices = np.array([5, 7, 13, 22, 23, 28, 29]) neighbors = np.array([[4, 10, 11, -1, -1, -1, -1, -1], [0, 1, 2, 6, 8, 12, 13, 14], [6, 7, 8, 12, 14, 18, 19, 20], [15, 16, 17, 21, 23, 27, 28, 29], [16, 17, 22, 28, 29, -1, -1, -1], [21, 22, 23, 27, 29, -1, -1, -1], [22, 23, 28, -1, -1, -1, -1, -1]]) connections = [{5}, {7, 13}, {22, 23, 28, 29}] result_connections = trap_analysis.get_minimums_in_watersheds(minimum_indices, num_of_cols, num_of_rows) assert sorted(connections) == sorted(result_connections)
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'))