Loading autocnet/graph/edge.py +13 −8 Original line number Diff line number Diff line Loading @@ -188,15 +188,15 @@ class Edge(dict, MutableMapping): keypts = node.get_keypoint_coordinates(index=index, homogeneous=homogeneous) # If we only want keypoints in the overlap if overlap: if self.source == node: mbr = self['source_mbr'] else: mbr = self['destin_mbr'] # Can't use overlap if we haven't computed MBRs if self['overlap_latlon_coords'] is None: print(mbr) if mbr is None: return keypts # Create overlap's bounding polygon in pixel space bounds_poly = node.reproject_geom(self['overlap_latlon_coords']) # Mask for node keypts based on bounding poly overlap_mask = cg.geom_mask(node.keypoints, bounds_poly) # Return masked keypts return keypts[overlap_mask] return keypts.query('x >= {} and x <= {} and y >= {} and y <= {}'.format(*mbr)) return keypts @get_keypoints.register(str) Loading Loading @@ -515,6 +515,10 @@ class Edge(dict, MutableMapping): Estimate a source and destination minimum bounding rectangle, in pixel space. """ if isinstance(self.source.geodata, (int, float)): smbr = None dmbr = None else: try: self['overlap_latlon_coords'], smbr, dmbr = self.source.geodata.compute_overlap(self.destination.geodata, **kwargs) smbr = list(smbr) Loading @@ -533,7 +537,8 @@ class Edge(dict, MutableMapping): warnings.warn("Overlap between {} and {} could not be " "computed. Using the full image extents".format(self.source['image_name'], self.destination['image_name'])) smbr = [smbr[0][0], smbr[1][0], smbr[0][1], smbr[1][1]] dmbr = [dmbr[0][0], dmbr[1][0], dmbr[0][1], dmbr[1][1]] self['source_mbr'] = smbr self['destin_mbr'] = dmbr Loading autocnet/graph/node.py +3 −0 Original line number Diff line number Diff line Loading @@ -114,8 +114,11 @@ class Node(dict, MutableMapping): @property def geodata(self): if not getattr(self, '_geodata', None) and self['image_path'] is not None: try: self._geodata = GeoDataset(self['image_path']) return self._geodata except: return self['node_id'] if hasattr(self, '_geodata'): return self._geodata else: Loading autocnet/graph/tests/test_edge.py +11 −5 Original line number Diff line number Diff line Loading @@ -185,15 +185,17 @@ class TestEdge(unittest.TestCase): destination_node.keypoints = dst_keypoint_df # Only keep keypt vals w/I these bounding rects e["source_mbr"] = (0, 2, 8, 5) e["destin_mbr"] = (31, 33, 28, 26) e["source_mbr"] = (0, 2, 5, 8) e["destin_mbr"] = (31, 33, 26, 28) # Grab the keypoints on our MBR overlaps s_overlap = e.get_keypoints(e.source, overlap=True) d_overlap = e.get_keypoints(e.destination, overlap=True) # Assert masked src keypts coords are equal s_expected = pd.DataFrame({'x': (1, 2, 3), 'y': (6, 7, 8)}) s_expected = pd.DataFrame({'x': (0, 1, 2), 'y': (5, 6, 7)}) print(s_expected['y']) print(s_overlap['y']) self.assertTrue(np.array_equal(s_expected['x'], s_overlap['x'].values)) self.assertTrue(np.array_equal(s_expected['y'], s_overlap['y'].values)) Loading Loading @@ -260,6 +262,10 @@ class TestEdge(unittest.TestCase): self.assertEqual(expected, e.__repr__()) def test_ratio_check(self): """ A pretty basic test that simply tests pass through from the edge to the proper distance func. """ # Matches is init to None e = edge.Edge() Loading @@ -273,9 +279,9 @@ class TestEdge(unittest.TestCase): matches_df = pd.DataFrame(data=keypoint_matches, columns=['source_image', 'source_idx', 'destination_image', 'destination_idx', 'distance']) e.matches = matches_df expected = list(od.distance_ratio(matches_df)) expected = od.distance_ratio(None, matches_df) e.ratio_check() self.assertEqual(expected, list(e.masks["ratio"])) assert expected.equals(e.masks["ratio"]) def test_overlap_check(self): s = node.Node() Loading autocnet/graph/tests/test_network.py +1 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,7 @@ def test_minimum_spanning_tree(): "7": ["2"]} graph = network.CandidateGraph.from_adjacency(test_dict) print(graph) mst_graph = graph.minimum_spanning_tree() assert sorted(mst_graph.nodes()) == sorted(graph.nodes()) Loading Loading
autocnet/graph/edge.py +13 −8 Original line number Diff line number Diff line Loading @@ -188,15 +188,15 @@ class Edge(dict, MutableMapping): keypts = node.get_keypoint_coordinates(index=index, homogeneous=homogeneous) # If we only want keypoints in the overlap if overlap: if self.source == node: mbr = self['source_mbr'] else: mbr = self['destin_mbr'] # Can't use overlap if we haven't computed MBRs if self['overlap_latlon_coords'] is None: print(mbr) if mbr is None: return keypts # Create overlap's bounding polygon in pixel space bounds_poly = node.reproject_geom(self['overlap_latlon_coords']) # Mask for node keypts based on bounding poly overlap_mask = cg.geom_mask(node.keypoints, bounds_poly) # Return masked keypts return keypts[overlap_mask] return keypts.query('x >= {} and x <= {} and y >= {} and y <= {}'.format(*mbr)) return keypts @get_keypoints.register(str) Loading Loading @@ -515,6 +515,10 @@ class Edge(dict, MutableMapping): Estimate a source and destination minimum bounding rectangle, in pixel space. """ if isinstance(self.source.geodata, (int, float)): smbr = None dmbr = None else: try: self['overlap_latlon_coords'], smbr, dmbr = self.source.geodata.compute_overlap(self.destination.geodata, **kwargs) smbr = list(smbr) Loading @@ -533,7 +537,8 @@ class Edge(dict, MutableMapping): warnings.warn("Overlap between {} and {} could not be " "computed. Using the full image extents".format(self.source['image_name'], self.destination['image_name'])) smbr = [smbr[0][0], smbr[1][0], smbr[0][1], smbr[1][1]] dmbr = [dmbr[0][0], dmbr[1][0], dmbr[0][1], dmbr[1][1]] self['source_mbr'] = smbr self['destin_mbr'] = dmbr Loading
autocnet/graph/node.py +3 −0 Original line number Diff line number Diff line Loading @@ -114,8 +114,11 @@ class Node(dict, MutableMapping): @property def geodata(self): if not getattr(self, '_geodata', None) and self['image_path'] is not None: try: self._geodata = GeoDataset(self['image_path']) return self._geodata except: return self['node_id'] if hasattr(self, '_geodata'): return self._geodata else: Loading
autocnet/graph/tests/test_edge.py +11 −5 Original line number Diff line number Diff line Loading @@ -185,15 +185,17 @@ class TestEdge(unittest.TestCase): destination_node.keypoints = dst_keypoint_df # Only keep keypt vals w/I these bounding rects e["source_mbr"] = (0, 2, 8, 5) e["destin_mbr"] = (31, 33, 28, 26) e["source_mbr"] = (0, 2, 5, 8) e["destin_mbr"] = (31, 33, 26, 28) # Grab the keypoints on our MBR overlaps s_overlap = e.get_keypoints(e.source, overlap=True) d_overlap = e.get_keypoints(e.destination, overlap=True) # Assert masked src keypts coords are equal s_expected = pd.DataFrame({'x': (1, 2, 3), 'y': (6, 7, 8)}) s_expected = pd.DataFrame({'x': (0, 1, 2), 'y': (5, 6, 7)}) print(s_expected['y']) print(s_overlap['y']) self.assertTrue(np.array_equal(s_expected['x'], s_overlap['x'].values)) self.assertTrue(np.array_equal(s_expected['y'], s_overlap['y'].values)) Loading Loading @@ -260,6 +262,10 @@ class TestEdge(unittest.TestCase): self.assertEqual(expected, e.__repr__()) def test_ratio_check(self): """ A pretty basic test that simply tests pass through from the edge to the proper distance func. """ # Matches is init to None e = edge.Edge() Loading @@ -273,9 +279,9 @@ class TestEdge(unittest.TestCase): matches_df = pd.DataFrame(data=keypoint_matches, columns=['source_image', 'source_idx', 'destination_image', 'destination_idx', 'distance']) e.matches = matches_df expected = list(od.distance_ratio(matches_df)) expected = od.distance_ratio(None, matches_df) e.ratio_check() self.assertEqual(expected, list(e.masks["ratio"])) assert expected.equals(e.masks["ratio"]) def test_overlap_check(self): s = node.Node() Loading
autocnet/graph/tests/test_network.py +1 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,7 @@ def test_minimum_spanning_tree(): "7": ["2"]} graph = network.CandidateGraph.from_adjacency(test_dict) print(graph) mst_graph = graph.minimum_spanning_tree() assert sorted(mst_graph.nodes()) == sorted(graph.nodes()) Loading