Commit dd8bfbc1 authored by Adam Paquette's avatar Adam Paquette
Browse files

Updated network with is_complete method to determine if graphs are complete.

parent b9abf758
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -781,20 +781,16 @@ class CandidateGraph(nx.Graph):
        clean_keys : list
                     Strings used to apply masks to omit correspondences
        """
        neighbors_dict = nx.degree(self)
        if False in list(all(value == len(self.neighbors(self.nodes()[0])) for value in neighbors_dict.values())):
            warnings.warn('The given graph is not complete and may yield garbage.')

        source_node = self.nodes(data=True)[0][1]
        intersect_gdf = self.compute_intersection(self, source_node, clean_keys)
        if not self.is_complete():
            warnings.warn('The given graph is not complete and may yield garbage.')

        for s, d, edge in self.edges_iter(data=True):
            # Recompute the intersection if the source node of the n + 1 edge is different from the n edge
            if s != source_node['node_id']:
            source_node = edge.source
            intersect_gdf = self.compute_intersection(self, source_node, clean_keys)

            kps = edge.get_keypoints('source', clean_keys=clean_keys)[['x', 'y']]
            matches, _ = edge.clean(clean_keys)
            kps = edge.get_keypoints(edge.source, index=matches['source_idx'])[['x', 'y']]
            reproj_geom = source_node.reproject_geom(intersect_gdf.query("overlaps_all == True").geometry.values[0].__geo_interface__['coordinates'][0])
            initial_mask = geom_mask(kps, reproj_geom)

@@ -859,3 +855,16 @@ class CandidateGraph(nx.Graph):
            intersect_gdf.loc[len(intersect_gdf)] = [source['node_id'], source['node_id'], new_poly, True]

        return intersect_gdf

    def is_complete(self):
        """
        Checks if the graph is a complete graph
        """
        neighbors_dict = nx.degree(self)
        for value in neighbors_dict.values():
            if value == len(self.neighbors(self.nodes()[0])):
                continue
            else:
                return False

        return True
+11 −11
Original line number Diff line number Diff line
@@ -199,17 +199,8 @@ def test_intersection():
        cang.node[n] = new_node

    # Create the edges between the nodes in the graph
    cang.add_edge(0, 1)
    cang.add_edge(0, 2)
    cang.add_edge(0, 3)
    cang.add_edge(2, 3)
    cang.add_edge(3, 4)
    cang.add_edge(4, 5)
    cang.add_edge(5, 6)
    cang.add_edge(6, 7)
    cang.add_edge(7, 4)
    cang.add_edge(4, 6)
    cang.add_edge(5, 7)
    cang.add_edges_from([(0, 1), (0, 2), (0, 3), (2, 3), (3, 4), (4, 5),
                                            (5, 6), (6, 7), (7, 4), (4, 6), (5, 7)])

    # Define source and destination for each edge
    for s, d in cang.edges():
@@ -247,3 +238,12 @@ def test_update_data(graph):
   ntime = graph.graph['modifieddate']
   assert ctime != ntime


def test_is_complete(graph):
    # Create a small incomplete graph with three nodes and two edges
    incomplete_graph = network.CandidateGraph()
    incomplete_graph.add_nodes_from([1, 2, 3])
    incomplete_graph.add_edges_from([(1, 2), (2, 3)])

    assert False == incomplete_graph.is_complete()
    assert True == graph.is_complete()