def test_data_distance_cosine(): # answer calculated from PASSaGE 2 and exported to 5 decimals answer = load_answer("answers/data_cosine_dists_answer.txt") data, _ = create_test_scattered() output = pyssage.distances.data_distance_matrix(data, pyssage.distances.data_distance_cosine) for i in range(len(answer)): for j in range(len(answer)): assert round(output[i, j], 5) == answer[i, j]
def test_euc_dist_matrix(): # answer calculated from PASSaGE 2 and exported to 5 decimals answer = load_answer("answers/euc_distmat_answer.txt") coords = create_test_coords() output = pyssage.distances.euclidean_distance_matrix(coords[:, 0], coords[:, 1]) for i in range(len(answer)): for j in range(len(answer)): assert round(output[i, j], 5) == answer[i, j]
def test_minimum_spanning_tree(): # answer calculated from PASSaGE 2 and exported as a binary connection matrix answer = load_answer("answers/minspan_answer.txt") coords = create_test_coords() distances = pyssage.distances.spherical_distance_matrix(coords[:, 0], coords[:, 1]) connections = pyssage.connections.minimum_spanning_tree(distances) pyssage.graph.draw_connections(connections, coords[:, 0], coords[:, 1], title="Minimum-Spanning Tree Test", figoutput=pyssage.graph.FigOutput(figshow=True)) for i in range(len(answer)): for j in range(len(answer)): assert connections[i, j] == answer[i, j]
def test_gabriel_network(): # answer calculated from PASSaGE 2 and exported as a binary connection matrix answer = load_answer("answers/gabriel_answer.txt") coords = create_test_coords() distances = pyssage.distances.spherical_distance_matrix(coords[:, 0], coords[:, 1]) connections = pyssage.connections.gabriel_network(distances) pyssage.graph.draw_connections(connections, coords[:, 0], coords[:, 1], title="Gabriel Graph/Network Test", figoutput=pyssage.graph.FigOutput(figshow=True)) for i in range(len(answer)): for j in range(len(answer)): assert connections[i, j] == answer[i, j]
def test_connect_distance_range(): # answer calculated from PASSaGE 2 and exported as a binary connection matrix answer = load_answer("answers/distance_based_connect_7-12_answer.txt") coords = create_test_coords() distances = pyssage.distances.euclidean_distance_matrix(coords[:, 0], coords[:, 1]) connections = pyssage.connections.connect_distance_range(distances, mindist=7, maxdist=12) pyssage.graph.draw_connections(connections, coords[:, 0], coords[:, 1], title="Distance-based Connections (7-12) Test", figoutput=pyssage.graph.FigOutput(figshow=True)) for i in range(len(answer)): for j in range(len(answer)): assert connections[i, j] == answer[i, j]
def test_delaunay_tessellation(): # answer calculated from PASSaGE 2 and exported as a binary connection matrix answer = load_answer("answers/delaunay_answer.txt") coords = create_test_coords() tessellation, connections = pyssage.connections.delaunay_tessellation(coords[:, 0], coords[:, 1]) pyssage.graph.draw_tessellation(tessellation, coords[:, 0], coords[:, 1], title="Tessellation Test", figoutput=pyssage.graph.FigOutput(figshow=True)) pyssage.graph.draw_connections(connections, coords[:, 0], coords[:, 1], title="Delaunay Connections Test", figoutput=pyssage.graph.FigOutput(figshow=True)) for i in range(len(answer)): for j in range(len(answer)): assert connections[i, j] == answer[i, j]
def test_shortest_path_distances(): """ testing with euclidean distances as the spherical estimation procedure is now a bit different """ # answer calculated from PASSaGE 2 and exported to 5 decimals answer = load_answer("answers/shortest_path_minspan_answer.txt") # test a fully connected network coords = create_test_coords() distances = pyssage.distances.euclidean_distance_matrix(coords[:, 0], coords[:, 1]) connections = pyssage.connections.minimum_spanning_tree(distances) geodists, trace = pyssage.distances.shortest_path_distances(distances, connections) for i in range(len(answer)): for j in range(len(answer)): assert round(geodists[i, j], 5) == answer[i, j] pyssage.graph.draw_shortest_path(connections, coords[:, 0], coords[:, 1], trace, 0, 300, figoutput=pyssage.graph.FigOutput(figshow=True)) # test a partially connected network connections = pyssage.connections.nearest_neighbor_connections(distances, 1) pyssage.distances.shortest_path_distances(distances, connections)