Loading autocnet/control/tests/test_control.py +20 −0 Original line number Diff line number Diff line Loading @@ -75,3 +75,23 @@ class TestC(unittest.TestCase): def test_to_dataframe(self): self.C.to_dataframe() def test_point_repr(self): expected = 0 p = control.Point(expected) self.assertEqual(str(expected), p.__repr__()) def test_correspondence_repr(self): expected = 0 c = control.Correspondence(expected, 1, 1) self.assertEqual(str(expected), c.__repr__()) def test_correspondence_eq(self): expected = 0 c = control.Correspondence(expected, 1, 1) self.assertTrue(c == expected) def test_correspondence_hash(self): expected = 200 c = control.Correspondence(expected, 1, 1) self.assertEqual(hash(expected), hash(c)) autocnet/graph/edge.py +8 −19 Original line number Diff line number Diff line Loading @@ -74,22 +74,11 @@ class Edge(dict, MutableMapping): def masks(self): mask_lookup = {'fundamental': 'fundamental_matrix'} if not hasattr(self, '_masks'): if self.matches is not None: if isinstance(self.matches, pd.DataFrame): self._masks = pd.DataFrame(True, columns=['symmetry'], index=self.matches.index) else: self._masks = pd.DataFrame() # If the mask is coming form another object that tracks # state, dynamically draw the mask from the object. for c in self._masks.columns: if c in mask_lookup: try: truncated_mask = getattr(self, mask_lookup[c]).mask self._masks[c] = False self._masks[c].iloc[truncated_mask.index] = truncated_mask except Exception: #TODO: Get rid of state pass return self._masks @masks.setter Loading Loading @@ -118,14 +107,14 @@ class Edge(dict, MutableMapping): pass def symmetry_check(self): if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): mask = od.mirroring_test(self.matches) self.masks = ('symmetry', mask) else: raise AttributeError('No matches have been computed for this edge.') def ratio_check(self, clean_keys=[], **kwargs): if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): matches, mask = self.clean(clean_keys) distance_mask = od.distance_ratio(matches, **kwargs) self.masks = ('ratio', distance_mask) Loading @@ -152,7 +141,7 @@ class Edge(dict, MutableMapping): autocnet.transformation.transformations.FundamentalMatrix """ if not hasattr(self, 'matches'): if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Matches have not been computed for this edge') return matches, mask = self.clean(clean_keys) Loading Loading @@ -197,7 +186,7 @@ class Edge(dict, MutableMapping): Boolean array of the outliers """ if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): matches = self.matches else: raise AttributeError('Matches have not been computed for this edge') Loading Loading @@ -321,7 +310,7 @@ class Edge(dict, MutableMapping): of mask keys to be used to reduce the total size of the matches dataframe. """ if not hasattr(self, 'matches'): if not isinstance(self.matches, pd.DataFrame): raise AttributeError('This edge does not yet have any matches computed.') matches, mask = self.clean(clean_keys) Loading Loading @@ -418,7 +407,7 @@ class Edge(dict, MutableMapping): returns the overlap area covered by the keypoints """ if self.matches is None: if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Edge needs to have features extracted and matched') return matches, mask = self.clean(clean_keys) Loading Loading @@ -454,7 +443,7 @@ class Edge(dict, MutableMapping): Of strings used to apply masks to omit correspondences """ if self.matches is None: if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Matches have not been computed for this edge') voronoi = cg.vor(self, clean_keys, **kwargs) self.matches = pd.concat([self.matches, voronoi[1]['vor_weights']], axis=1) Loading autocnet/graph/tests/test_edge.py +107 −0 Original line number Diff line number Diff line Loading @@ -3,9 +3,11 @@ from unittest.mock import Mock from unittest.mock import MagicMock import ogr import numpy as np import pandas as pd from plio.io import io_gdal from autocnet.matcher import outlier_detector as od from autocnet.examples import get_path from autocnet.graph.network import CandidateGraph from autocnet.utils.utils import array_to_poly Loading Loading @@ -44,6 +46,33 @@ class TestEdge(unittest.TestCase): def test_masks(self): self.assertIsInstance(self.edge.masks, pd.DataFrame) matches = [[0, 0, 1, 0], [0, 1, 1, 1], [0, 2, 1, 2], [0, 3, 1, 3], [0, 4, 1, 4]] matches_df = pd.DataFrame(data=matches, columns=['source_image', 'source_idx', 'destination_image', 'destination_idx']) e = edge.Edge() e.matches = matches_df # Test empty masks df on an edge with computed matches expected = pd.DataFrame(True, columns=['symmetry'], index=matches_df.index) self.assertTrue(expected.equals(e.masks)) # Test the masks setter, changing a given row new_symmetry_rows = [True, False, True, False, True] e.masks = "symmetry", new_symmetry_rows self.assertEqual(new_symmetry_rows, list(e.masks.loc[:, "symmetry"])) # Test the masks setter, inserting a new row e.masks = "fundamental", new_symmetry_rows self.assertEqual(new_symmetry_rows, list(e.masks.loc[:, "fundamental"])) def test_compute_fundamental_matrix(self): Loading Loading @@ -321,3 +350,81 @@ class TestEdge(unittest.TestCase): # Check key error thrown when string arg != "source" or "destination" with self.assertRaises(KeyError): e.get_keypoints("string", clean_keys) def test_eq(self): edge1 = edge.Edge() edge2 = edge.Edge() edge3 = edge.Edge() # Test edges w/ different keys are not equal, ones with same keys are edge1.__dict__["key"] = 1 edge2.__dict__["key"] = 1 edge3.__dict__["not_key"] = 1 self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) # Test edges with same keys, but diff df values edge1.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)}) edge2.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)}) edge3.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 5)}) self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) # Test edges with same keys, but diff np array vals # edge.__eq__ calls ndarray.all(), which checks that # all values in an array eval to true edge1.__dict__["key"] = np.array([True, True, True], dtype=np.bool) edge2.__dict__["key"] = np.array([True, True, True], dtype=np.bool) edge3.__dict__["key"] = np.array([True, True, False], dtype=np.bool) self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) def test_repr(self): src = node.Node() dst = node.Node() masks = pd.DataFrame() e = edge.Edge() e.source = src e.destination = dst expected = """ Source Image Index: {} Destination Image Index: {} Available Masks: {} """.format(src, dst, masks) self.assertEqual(expected, e.__repr__()) def test_symmetry_check(self): # Matches is init to None e = edge.Edge() e.source = node.Node() e.destination = node.Node() # If there are no matches, should raise attrib err with (self.assertRaises(AttributeError)): e.symmetry_check() def test_ratio_check(self): # Matches is init to None e = edge.Edge() # If there are no matches, should raise attrib err with (self.assertRaises(AttributeError)): e.ratio_check() # If there are matches... keypoint_matches = [[0, 0, 1, 4, 5], [0, 1, 1, 3, 5], [0, 2, 1, 2, 5], [0, 3, 1, 1, 5], [0, 4, 1, 0, 5]] 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)) e.ratio_check() self.assertEqual(expected, list(e.masks["ratio"])) Loading
autocnet/control/tests/test_control.py +20 −0 Original line number Diff line number Diff line Loading @@ -75,3 +75,23 @@ class TestC(unittest.TestCase): def test_to_dataframe(self): self.C.to_dataframe() def test_point_repr(self): expected = 0 p = control.Point(expected) self.assertEqual(str(expected), p.__repr__()) def test_correspondence_repr(self): expected = 0 c = control.Correspondence(expected, 1, 1) self.assertEqual(str(expected), c.__repr__()) def test_correspondence_eq(self): expected = 0 c = control.Correspondence(expected, 1, 1) self.assertTrue(c == expected) def test_correspondence_hash(self): expected = 200 c = control.Correspondence(expected, 1, 1) self.assertEqual(hash(expected), hash(c))
autocnet/graph/edge.py +8 −19 Original line number Diff line number Diff line Loading @@ -74,22 +74,11 @@ class Edge(dict, MutableMapping): def masks(self): mask_lookup = {'fundamental': 'fundamental_matrix'} if not hasattr(self, '_masks'): if self.matches is not None: if isinstance(self.matches, pd.DataFrame): self._masks = pd.DataFrame(True, columns=['symmetry'], index=self.matches.index) else: self._masks = pd.DataFrame() # If the mask is coming form another object that tracks # state, dynamically draw the mask from the object. for c in self._masks.columns: if c in mask_lookup: try: truncated_mask = getattr(self, mask_lookup[c]).mask self._masks[c] = False self._masks[c].iloc[truncated_mask.index] = truncated_mask except Exception: #TODO: Get rid of state pass return self._masks @masks.setter Loading Loading @@ -118,14 +107,14 @@ class Edge(dict, MutableMapping): pass def symmetry_check(self): if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): mask = od.mirroring_test(self.matches) self.masks = ('symmetry', mask) else: raise AttributeError('No matches have been computed for this edge.') def ratio_check(self, clean_keys=[], **kwargs): if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): matches, mask = self.clean(clean_keys) distance_mask = od.distance_ratio(matches, **kwargs) self.masks = ('ratio', distance_mask) Loading @@ -152,7 +141,7 @@ class Edge(dict, MutableMapping): autocnet.transformation.transformations.FundamentalMatrix """ if not hasattr(self, 'matches'): if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Matches have not been computed for this edge') return matches, mask = self.clean(clean_keys) Loading Loading @@ -197,7 +186,7 @@ class Edge(dict, MutableMapping): Boolean array of the outliers """ if hasattr(self, 'matches'): if isinstance(self.matches, pd.DataFrame): matches = self.matches else: raise AttributeError('Matches have not been computed for this edge') Loading Loading @@ -321,7 +310,7 @@ class Edge(dict, MutableMapping): of mask keys to be used to reduce the total size of the matches dataframe. """ if not hasattr(self, 'matches'): if not isinstance(self.matches, pd.DataFrame): raise AttributeError('This edge does not yet have any matches computed.') matches, mask = self.clean(clean_keys) Loading Loading @@ -418,7 +407,7 @@ class Edge(dict, MutableMapping): returns the overlap area covered by the keypoints """ if self.matches is None: if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Edge needs to have features extracted and matched') return matches, mask = self.clean(clean_keys) Loading Loading @@ -454,7 +443,7 @@ class Edge(dict, MutableMapping): Of strings used to apply masks to omit correspondences """ if self.matches is None: if not isinstance(self.matches, pd.DataFrame): raise AttributeError('Matches have not been computed for this edge') voronoi = cg.vor(self, clean_keys, **kwargs) self.matches = pd.concat([self.matches, voronoi[1]['vor_weights']], axis=1) Loading
autocnet/graph/tests/test_edge.py +107 −0 Original line number Diff line number Diff line Loading @@ -3,9 +3,11 @@ from unittest.mock import Mock from unittest.mock import MagicMock import ogr import numpy as np import pandas as pd from plio.io import io_gdal from autocnet.matcher import outlier_detector as od from autocnet.examples import get_path from autocnet.graph.network import CandidateGraph from autocnet.utils.utils import array_to_poly Loading Loading @@ -44,6 +46,33 @@ class TestEdge(unittest.TestCase): def test_masks(self): self.assertIsInstance(self.edge.masks, pd.DataFrame) matches = [[0, 0, 1, 0], [0, 1, 1, 1], [0, 2, 1, 2], [0, 3, 1, 3], [0, 4, 1, 4]] matches_df = pd.DataFrame(data=matches, columns=['source_image', 'source_idx', 'destination_image', 'destination_idx']) e = edge.Edge() e.matches = matches_df # Test empty masks df on an edge with computed matches expected = pd.DataFrame(True, columns=['symmetry'], index=matches_df.index) self.assertTrue(expected.equals(e.masks)) # Test the masks setter, changing a given row new_symmetry_rows = [True, False, True, False, True] e.masks = "symmetry", new_symmetry_rows self.assertEqual(new_symmetry_rows, list(e.masks.loc[:, "symmetry"])) # Test the masks setter, inserting a new row e.masks = "fundamental", new_symmetry_rows self.assertEqual(new_symmetry_rows, list(e.masks.loc[:, "fundamental"])) def test_compute_fundamental_matrix(self): Loading Loading @@ -321,3 +350,81 @@ class TestEdge(unittest.TestCase): # Check key error thrown when string arg != "source" or "destination" with self.assertRaises(KeyError): e.get_keypoints("string", clean_keys) def test_eq(self): edge1 = edge.Edge() edge2 = edge.Edge() edge3 = edge.Edge() # Test edges w/ different keys are not equal, ones with same keys are edge1.__dict__["key"] = 1 edge2.__dict__["key"] = 1 edge3.__dict__["not_key"] = 1 self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) # Test edges with same keys, but diff df values edge1.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)}) edge2.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 4)}) edge3.__dict__["key"] = pd.DataFrame({'x': (0, 1, 2, 3, 5)}) self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) # Test edges with same keys, but diff np array vals # edge.__eq__ calls ndarray.all(), which checks that # all values in an array eval to true edge1.__dict__["key"] = np.array([True, True, True], dtype=np.bool) edge2.__dict__["key"] = np.array([True, True, True], dtype=np.bool) edge3.__dict__["key"] = np.array([True, True, False], dtype=np.bool) self.assertTrue(edge1 == edge2) self.assertFalse(edge1 == edge3) def test_repr(self): src = node.Node() dst = node.Node() masks = pd.DataFrame() e = edge.Edge() e.source = src e.destination = dst expected = """ Source Image Index: {} Destination Image Index: {} Available Masks: {} """.format(src, dst, masks) self.assertEqual(expected, e.__repr__()) def test_symmetry_check(self): # Matches is init to None e = edge.Edge() e.source = node.Node() e.destination = node.Node() # If there are no matches, should raise attrib err with (self.assertRaises(AttributeError)): e.symmetry_check() def test_ratio_check(self): # Matches is init to None e = edge.Edge() # If there are no matches, should raise attrib err with (self.assertRaises(AttributeError)): e.ratio_check() # If there are matches... keypoint_matches = [[0, 0, 1, 4, 5], [0, 1, 1, 3, 5], [0, 2, 1, 2, 5], [0, 3, 1, 1, 5], [0, 4, 1, 0, 5]] 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)) e.ratio_check() self.assertEqual(expected, list(e.masks["ratio"]))