def test_get_indices_leading_to_endpoints(): endpoints = np.array([7, 7, 7, 5, 5, 5, 7, 7, 7, 22, 5, 5, 13, 13, 13, 22, 22, 23, 13, 13, 13, 22, 22, 23, 13, 13, 13, 28, 28, 29]) # unique_endpoints = np.array([5, 7, 13, 22, 23, 28, 29]) result_indices_to_endpoints = {5: np.array([3, 4, 5, 10, 11]), 7: np.array([0, 1, 2, 6, 7, 8]), 13: np.array([12, 13, 14, 18, 19, 20, 24, 25, 26]), 22: np.array([9, 15, 16, 21, 22]), 23: np.array([17, 23]), 28: np.array([27, 28]), 29: np.array([29])} indices_to_endpoints = trap_analysis.get_indices_leading_to_endpoints(endpoints) for minimum in indices_to_endpoints: indices_to_endpoints[minimum] = np.sort(indices_to_endpoints[minimum]) are_equal = compare_methods.compare_two_dictionaries_where_values_are_arrays(indices_to_endpoints, result_indices_to_endpoints) assert are_equal
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'))