Loading autocnet/fileio/tests/test_utils.py 0 → 100644 +18 −0 Original line number Diff line number Diff line import unittest import pandas as pd import numpy as np from .. import utils class TestUtils(unittest.TestCase): def setUp(self): pass def test_slopes(self): x1 = pd.DataFrame({'x': np.arange(1, 11), 'y': np.arange(1, 11)}) x2 = pd.DataFrame({'x': np.arange(6, 16), 'y': np.arange(11, 21)}) slope = utils.calculate_slope(x1, x2) self.assertEqual(slope.slope[0], 2) autocnet/fileio/utils.py +21 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import tempfile import os import fnmatch import numpy as np import pandas as pd def create_dir(basedir=''): """ Loading Loading @@ -34,3 +35,23 @@ def file_search(searchdir,searchstring): filelist.append(os.path.join(root, filename)) filelist=np.array(filelist) return filelist def calculate_slope(x1, x2): """ Calculates the 2-dimensional slope between the points in two dataframes each containing two columns ['x', 'y'] The slope is calculated from x1 to x2. Parameters ---------- x1 : dataframe Each row is a point with columns ['x', 'y'] x2 : dataframe Each row is a point with columns ['x', 'y'] Returns ------- : dataframe A dataframe with the slope between the points in x1 and x2 for each row. """ slopes = (x2.y.values - x1.y.values)/(x2.x.values-x1.x.values) return pd.DataFrame(slopes, columns=['slope']) autocnet/graph/network.py +8 −8 Original line number Diff line number Diff line Loading @@ -355,13 +355,13 @@ class CandidateGraph(nx.Graph): """ _, self.clusters = func(self, *args, **kwargs) def apply_func_to_edges(self, func, *args, graph_mask_keys=[], **kwargs): def apply_func_to_edges(self, function, *args, graph_mask_keys=[], **kwargs): """ Iterates over edges using an optional mask and and applies the given function. If func is not an attribute of Edge, raises AttributeError Parameters ---------- func : string function : obj function to be called on every edge graph_mask_keys : list of keys in graph_masks Loading @@ -373,17 +373,17 @@ class CandidateGraph(nx.Graph): else: edges_to_iter = self.edges() if not isinstance(func, str): func = func.__name__ if not isinstance(function, str): function = function.__name__ for s, d in edges_to_iter: curr_edge = self.get_edge_data(s, d) try: function = getattr(curr_edge, func) func = getattr(curr_edge, function) except: raise AttributeError(func, ' is not an attribute of Edge') raise AttributeError(function, ' is not an attribute of Edge') else: function(*args, **kwargs) func(*args, **kwargs) def minimum_spanning_tree(self): """ Loading autocnet/transformation/tests/test_transformations.py +0 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import numpy.testing import pandas as pd from autocnet.transformation import transformations class TestHomography(unittest.TestCase): def test_Homography(self): Loading autocnet/transformation/transformations.py +10 −4 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ class FundamentalMatrix(TransformationMatrix): compute this homography """ def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, bin_id=0, **kwargs): def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, df=None, bin_id=0, **kwargs): """ Refine the fundamental matrix by accepting some data classification method that accepts an ndarray and returns an object with a bins Loading @@ -192,6 +192,10 @@ class FundamentalMatrix(TransformationMatrix): method : object A function that accepts and ndarray and returns an object with a bins attribute df : dataframe Dataframe (from which a ndarray will be extracted) to pass to the method. bin_id : int The index into the bins object. Data classified > this id is masked Loading @@ -209,10 +213,12 @@ class FundamentalMatrix(TransformationMatrix): data in the new fundamental matrix. """ # Perform the data classification fj = method(self.error.values.ravel(), **kwargs) if df is None: df = self.error fj = method(df.values.ravel(), **kwargs) bins = fj.bins # Mask the data that falls outside the provided bins mask = self.error['Reprojection Error'] <= bins[bin_id] mask = df.iloc[:, 0] <= bins[bin_id] new_x1 = self.x1.iloc[mask[mask == True].index] new_x2 = self.x2.iloc[mask[mask == True].index] fmatrix, new_mask = compute_fundamental_matrix(new_x1.values, new_x2.values) Loading @@ -220,7 +226,7 @@ class FundamentalMatrix(TransformationMatrix): # Update the current state self[:] = fmatrix self.mask[self.mask == True] = mask self.mask = mask # Update the action stack try: Loading Loading
autocnet/fileio/tests/test_utils.py 0 → 100644 +18 −0 Original line number Diff line number Diff line import unittest import pandas as pd import numpy as np from .. import utils class TestUtils(unittest.TestCase): def setUp(self): pass def test_slopes(self): x1 = pd.DataFrame({'x': np.arange(1, 11), 'y': np.arange(1, 11)}) x2 = pd.DataFrame({'x': np.arange(6, 16), 'y': np.arange(11, 21)}) slope = utils.calculate_slope(x1, x2) self.assertEqual(slope.slope[0], 2)
autocnet/fileio/utils.py +21 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ import tempfile import os import fnmatch import numpy as np import pandas as pd def create_dir(basedir=''): """ Loading Loading @@ -34,3 +35,23 @@ def file_search(searchdir,searchstring): filelist.append(os.path.join(root, filename)) filelist=np.array(filelist) return filelist def calculate_slope(x1, x2): """ Calculates the 2-dimensional slope between the points in two dataframes each containing two columns ['x', 'y'] The slope is calculated from x1 to x2. Parameters ---------- x1 : dataframe Each row is a point with columns ['x', 'y'] x2 : dataframe Each row is a point with columns ['x', 'y'] Returns ------- : dataframe A dataframe with the slope between the points in x1 and x2 for each row. """ slopes = (x2.y.values - x1.y.values)/(x2.x.values-x1.x.values) return pd.DataFrame(slopes, columns=['slope'])
autocnet/graph/network.py +8 −8 Original line number Diff line number Diff line Loading @@ -355,13 +355,13 @@ class CandidateGraph(nx.Graph): """ _, self.clusters = func(self, *args, **kwargs) def apply_func_to_edges(self, func, *args, graph_mask_keys=[], **kwargs): def apply_func_to_edges(self, function, *args, graph_mask_keys=[], **kwargs): """ Iterates over edges using an optional mask and and applies the given function. If func is not an attribute of Edge, raises AttributeError Parameters ---------- func : string function : obj function to be called on every edge graph_mask_keys : list of keys in graph_masks Loading @@ -373,17 +373,17 @@ class CandidateGraph(nx.Graph): else: edges_to_iter = self.edges() if not isinstance(func, str): func = func.__name__ if not isinstance(function, str): function = function.__name__ for s, d in edges_to_iter: curr_edge = self.get_edge_data(s, d) try: function = getattr(curr_edge, func) func = getattr(curr_edge, function) except: raise AttributeError(func, ' is not an attribute of Edge') raise AttributeError(function, ' is not an attribute of Edge') else: function(*args, **kwargs) func(*args, **kwargs) def minimum_spanning_tree(self): """ Loading
autocnet/transformation/tests/test_transformations.py +0 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import numpy.testing import pandas as pd from autocnet.transformation import transformations class TestHomography(unittest.TestCase): def test_Homography(self): Loading
autocnet/transformation/transformations.py +10 −4 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ class FundamentalMatrix(TransformationMatrix): compute this homography """ def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, bin_id=0, **kwargs): def refine(self, method=ps.esda.mapclassify.Fisher_Jenks, df=None, bin_id=0, **kwargs): """ Refine the fundamental matrix by accepting some data classification method that accepts an ndarray and returns an object with a bins Loading @@ -192,6 +192,10 @@ class FundamentalMatrix(TransformationMatrix): method : object A function that accepts and ndarray and returns an object with a bins attribute df : dataframe Dataframe (from which a ndarray will be extracted) to pass to the method. bin_id : int The index into the bins object. Data classified > this id is masked Loading @@ -209,10 +213,12 @@ class FundamentalMatrix(TransformationMatrix): data in the new fundamental matrix. """ # Perform the data classification fj = method(self.error.values.ravel(), **kwargs) if df is None: df = self.error fj = method(df.values.ravel(), **kwargs) bins = fj.bins # Mask the data that falls outside the provided bins mask = self.error['Reprojection Error'] <= bins[bin_id] mask = df.iloc[:, 0] <= bins[bin_id] new_x1 = self.x1.iloc[mask[mask == True].index] new_x2 = self.x2.iloc[mask[mask == True].index] fmatrix, new_mask = compute_fundamental_matrix(new_x1.values, new_x2.values) Loading @@ -220,7 +226,7 @@ class FundamentalMatrix(TransformationMatrix): # Update the current state self[:] = fmatrix self.mask[self.mask == True] = mask self.mask = mask # Update the action stack try: Loading