Loading autocnet/graph/network.py +2 −6 Original line number Diff line number Diff line Loading @@ -1913,10 +1913,7 @@ class NetworkCandidateGraph(CandidateGraph): # Create the nodes in the graph. Really, this is creating the # images in the DB print('loading {} of {}'.format(cnt+1, total)) image_name = os.path.basename(f) node = NetworkNode(image_path=f, image_name=image_name) node.parent = self node.populate_db() self.add_image(f) self.from_database() # Execute the computation to compute overlapping geometries Loading @@ -1932,11 +1929,10 @@ class NetworkCandidateGraph(CandidateGraph): absolute path to image """ image_name = os.path.basename(img_path) node = NetworkNode(image_path=f, image_name=image_name) node = NetworkNode(image_path=img_path, image_name=image_name) node.parent = self node.populate_db() def copy_images(self, newdir): """ Copy images from a given directory into a new directory and Loading autocnet/graph/node.py +9 −4 Original line number Diff line number Diff line Loading @@ -519,15 +519,20 @@ class NetworkNode(Node): # Image already exists return # If the geodata is not valid, do no create an assocaited keypoints file # One instance when invalid is during testing. if hasattr(self.geodata, 'file_name'): kpspath = io_keypoints.create_output_path(self.geodata.file_name) # Create the keypoints entry kps = Keypoints(path=kpspath, nkeypoints=0) else: kps = None try: fp, cam_type = self.footprint except Exception as e: warnings.warn('Unable to generate image footprint.\n{}'.format(e)) fp = None fp = cam_type = None # Create the image i = Images(name=self['image_name'], path=self['image_path'], Loading autocnet/graph/tests/test_network_graph.py +51 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,54 @@ def test_to_isis(db_controlnetwork, ncg, node_a, node_b, tmpdir): ncg.to_isis(outpath) assert os.path.exists(outpath) def test_from_filelist(session, default_configuration, tmp_path): # Written as a list and not parametrized so that the fixture does not automatically clean # up the DB. Needed to test the functionality of the clear_db kwarg. for filelist, clear_db in [(['bar1.cub', 'bar2.cub', 'bar3.cub'], False), ([], True), (['bar1.cub', 'bar2.cub', 'bar3.cub'], True)]: filelist = [tmp_path/f for f in filelist] # Since we have no overlaps (everything is faked), len(ncg) == 0 ncg = NetworkCandidateGraph.from_filelist(filelist, default_configuration, clear_db=clear_db) with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == len(filelist) def test_global_clear_db(session, ncg): i = model.Images(name='foo', path='/fooland/foo.img') with ncg.session_scope() as session: session.add(i) res = session.query(model.Images).all() assert len(res) == 1 ncg.clear_db() with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == 0 def test_selective_clear_db(session, ncg): i = model.Images(name='foo', path='fooland/foo.img') p = model.Points(pointtype=2) with ncg.session_scope() as session: session.add(i) session.add(p) res = session.query(model.Images).all() assert len(res) == 1 res = session.query(model.Points).all() assert len(res) == 1 ncg.clear_db(tables=['Points']) with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == 1 res = session.query(model.Points).all() assert len(res) == 0 No newline at end of file autocnet/io/db/__init__.py +1 −0 Original line number Diff line number Diff line from autocnet.io.db import adapters # imported here to get these registered autocnet/io/db/adapters.py 0 → 100644 +13 −0 Original line number Diff line number Diff line from pathlib import PosixPath from psycopg2.extensions import register_adapter, AsIs, adapt # Adaptors as defined by https://www.psycopg.org/docs/advanced.html#adapting-new-python-types-to-sql-syntax def adapt_posixpath(posixpath): stringified = adapt(str(posixpath)) return stringified # TODO: Add adaptors from numpy types. We shouldn't have to typecast # explicitly across the code base. register_adapter(PosixPath, adapt_posixpath) No newline at end of file Loading
autocnet/graph/network.py +2 −6 Original line number Diff line number Diff line Loading @@ -1913,10 +1913,7 @@ class NetworkCandidateGraph(CandidateGraph): # Create the nodes in the graph. Really, this is creating the # images in the DB print('loading {} of {}'.format(cnt+1, total)) image_name = os.path.basename(f) node = NetworkNode(image_path=f, image_name=image_name) node.parent = self node.populate_db() self.add_image(f) self.from_database() # Execute the computation to compute overlapping geometries Loading @@ -1932,11 +1929,10 @@ class NetworkCandidateGraph(CandidateGraph): absolute path to image """ image_name = os.path.basename(img_path) node = NetworkNode(image_path=f, image_name=image_name) node = NetworkNode(image_path=img_path, image_name=image_name) node.parent = self node.populate_db() def copy_images(self, newdir): """ Copy images from a given directory into a new directory and Loading
autocnet/graph/node.py +9 −4 Original line number Diff line number Diff line Loading @@ -519,15 +519,20 @@ class NetworkNode(Node): # Image already exists return # If the geodata is not valid, do no create an assocaited keypoints file # One instance when invalid is during testing. if hasattr(self.geodata, 'file_name'): kpspath = io_keypoints.create_output_path(self.geodata.file_name) # Create the keypoints entry kps = Keypoints(path=kpspath, nkeypoints=0) else: kps = None try: fp, cam_type = self.footprint except Exception as e: warnings.warn('Unable to generate image footprint.\n{}'.format(e)) fp = None fp = cam_type = None # Create the image i = Images(name=self['image_name'], path=self['image_path'], Loading
autocnet/graph/tests/test_network_graph.py +51 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,54 @@ def test_to_isis(db_controlnetwork, ncg, node_a, node_b, tmpdir): ncg.to_isis(outpath) assert os.path.exists(outpath) def test_from_filelist(session, default_configuration, tmp_path): # Written as a list and not parametrized so that the fixture does not automatically clean # up the DB. Needed to test the functionality of the clear_db kwarg. for filelist, clear_db in [(['bar1.cub', 'bar2.cub', 'bar3.cub'], False), ([], True), (['bar1.cub', 'bar2.cub', 'bar3.cub'], True)]: filelist = [tmp_path/f for f in filelist] # Since we have no overlaps (everything is faked), len(ncg) == 0 ncg = NetworkCandidateGraph.from_filelist(filelist, default_configuration, clear_db=clear_db) with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == len(filelist) def test_global_clear_db(session, ncg): i = model.Images(name='foo', path='/fooland/foo.img') with ncg.session_scope() as session: session.add(i) res = session.query(model.Images).all() assert len(res) == 1 ncg.clear_db() with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == 0 def test_selective_clear_db(session, ncg): i = model.Images(name='foo', path='fooland/foo.img') p = model.Points(pointtype=2) with ncg.session_scope() as session: session.add(i) session.add(p) res = session.query(model.Images).all() assert len(res) == 1 res = session.query(model.Points).all() assert len(res) == 1 ncg.clear_db(tables=['Points']) with ncg.session_scope() as session: res = session.query(model.Images).all() assert len(res) == 1 res = session.query(model.Points).all() assert len(res) == 0 No newline at end of file
autocnet/io/db/__init__.py +1 −0 Original line number Diff line number Diff line from autocnet.io.db import adapters # imported here to get these registered
autocnet/io/db/adapters.py 0 → 100644 +13 −0 Original line number Diff line number Diff line from pathlib import PosixPath from psycopg2.extensions import register_adapter, AsIs, adapt # Adaptors as defined by https://www.psycopg.org/docs/advanced.html#adapting-new-python-types-to-sql-syntax def adapt_posixpath(posixpath): stringified = adapt(str(posixpath)) return stringified # TODO: Add adaptors from numpy types. We shouldn't have to typecast # explicitly across the code base. register_adapter(PosixPath, adapt_posixpath) No newline at end of file