Beispiel #1
0
def ahn_tiles(bag3d_db, elevation_tiles, feature_tiles):
    return tileconfig.DbTilesAHN(
        conn=bag3d_db,
        elevation_tiles=elevation_tiles,
        feature_tiles=feature_tiles,
        output=None,
    )
Beispiel #2
0
 def test_versions(self, bag3d_db, elevation_tiles, feature_tiles):
     expectation = [2, 3]
     ahn_tiles = tileconfig.DbTilesAHN(
         conn=bag3d_db,
         elevation_tiles=elevation_tiles,
         feature_tiles=feature_tiles,
     )
     result = ahn_tiles.versions()
     assert set(result) == set(expectation)
Beispiel #3
0
 def test_init_ahntiles(
     self,
     output_obj,
     bag3d_db,
     elevation_idx_sch,
     features_idx_sch,
     features_sch,
 ):
     tiles = tileconfig.DbTilesAHN(
         conn=bag3d_db,
         elevation_tiles=elevation_idx_sch,
         feature_tiles=features_idx_sch,
     )
Beispiel #4
0
    def configure(self, tiles, processor_key: str, worker_key: str):
        """Configure the control logic."""
        worker_init = worker.factory.create(worker_key)
        self.cfg["worker"] = worker_init.execute

        # Configure feature tiles with elevation from AHN3
        conn = db.Db(**self.cfg["config"]["database"])
        elevation_tiles = tileconfig.DbTiles(
            conn=conn,
            tile_index_schema=db.Schema(self.cfg["config"]["elevation_tiles"]),
        )
        elevation_tiles.configure(tiles=tiles)
        ahntiles = tileconfig.DbTilesAHN(conn=None,
                                         elevation_tiles=None,
                                         feature_tiles=None)
        ahntiles.to_process = elevation_tiles.to_process
        elevation_file_paths = ahntiles.create_elevation_file_index(
            directory_mapping=self.cfg["config"]["directory_mapping"])
        ahn_version = 3
        ahntiles.elevation_file_index = {}
        for i, ahn_id in enumerate(elevation_tiles.to_process):
            paths = []
            if ahn_id in elevation_file_paths:
                paths.extend(
                    (p, ahn_version) for p in elevation_file_paths[ahn_id])
            else:
                log.debug(
                    f"File matching the AHN ID {ahn_id} not found, skipping tile"
                )
                del ahntiles.to_process[i]
            ahntiles.elevation_file_index[ahn_id] = paths
        # Set up outputs
        output_obj = output.Output()
        if "database" in self.cfg["config"]["output"]:
            output_obj.db = output.DbOutput(conn=db.Db(
                **self.cfg["config"]["output"]["database"]))
        elif "dir" in self.cfg["config"]["output"]:
            output_obj.dir = output.DirOutput(
                path=self.cfg["config"]["output"]["dir"])
        for k, v in self.cfg["config"]["output"].items():
            if k != "database" and k != "dir":
                output_obj.kwargs[k] = v
        ahntiles.output = output_obj
        name = "part1"
        proc = processor.factory.create(processor_key,
                                        name=name,
                                        tiles=ahntiles)
        self.processors[proc] = name
        log.info(f"Configured {self.__class__.__name__}")
Beispiel #5
0
 def test_version_boundary(self, bag3d_db, elevation_tiles, feature_tiles):
     expectation = [
         "25gn1_3",
         "25gn1_4",
         "25gn1_6",
         "25gn1_7",
         "25gn1_10",
         "25gn1_14",
     ]
     ahn_tiles = tileconfig.DbTilesAHN(
         conn=bag3d_db,
         elevation_tiles=elevation_tiles,
         feature_tiles=feature_tiles,
     )
     result = ahn_tiles.version_boundary()
     assert set(result) == set(expectation)
Beispiel #6
0
    def configure(self, tiles, processor_key: str, worker_key: str):
        """Configure the control logic."""
        worker_init = worker.factory.create(worker_key)
        self.cfg["worker"] = worker_init.execute

        ahntiles = tileconfig.DbTilesAHN(
            conn=db.Db(**self.cfg["config"]["database"]),
            elevation_tiles=db.Schema(self.cfg["config"]["elevation_tiles"]),
            feature_tiles=None,
        )
        ahntiles.configure(
            tiles=tiles,
            directory_mapping=self.cfg["config"]["directory_mapping"],
            tin=True,
        )
        part = "AHN3"
        ahntiles.output = output.Output(
            dir=output.DirOutput(self.cfg["config"]["output"]["dir"]))
        proc = processor.factory.create(processor_key,
                                        name=part,
                                        tiles=ahntiles)
        self.processors[proc] = part
        log.info(f"Configured {self.__class__.__name__}")
Beispiel #7
0
 def test_version_not_boundary(
     self, bag3d_db, elevation_tiles, feature_tiles
 ):
     table = feature_tiles.tile_index.index.table.string
     if table == "bag_index_identical":
         expectation = {
             3: ["25gn1_1", "25gn1_2", "25gn1_5", "25gn1_9", "25gn1_13"],
             2: ["25gn1_8", "25gn1_11", "25gn1_12", "25gn1_15", "25gn1_16"],
         }
         ahn_tiles = tileconfig.DbTilesAHN(
             conn=bag3d_db,
             elevation_tiles=elevation_tiles,
             feature_tiles=feature_tiles,
         )
         result = ahn_tiles.version_not_boundary()
         assert result == expectation
     elif table == "bag_index":
         pytest.skip("No appropriate data for testing this branch")
     else:
         pytest.fail(
             msg=f"Unexpected features_tiles.index.table " f"{table}",
             pytrace=False,
         )
Beispiel #8
0
    def configure(self, tiles, processor_key: str, worker_key: str):
        """Configure the control logic."""
        worker_init = worker.factory.create(worker_key)
        self.cfg["worker"] = worker_init.execute

        # Configure the tiles
        _tilecfg = {
            "conn":
            db.Db(**self.cfg["config"]["database"]),
            "elevation_index_schema":
            db.Schema(self.cfg["config"]["elevation_tiles"]),
            "tile_index_schema":
            db.Schema(self.cfg["config"]["features_tiles"]),
            "features_schema":
            db.Schema(self.cfg["config"]["features"]),
        }
        conn = db.Db(**self.cfg["config"]["database"])
        elevation_tiles = tileconfig.DbTiles(
            conn=conn,
            tile_index_schema=db.Schema(self.cfg["config"]["elevation_tiles"]),
        )
        feature_tiles = tileconfig.DbTiles(
            conn=conn,
            tile_index_schema=db.Schema(self.cfg["config"]["features_tiles"]),
            features_schema=db.Schema(self.cfg["config"]["features"]),
        )
        # Configure feature tiles with elevation from AHN2
        ahn_2 = tileconfig.DbTilesAHN(
            conn=conn,
            elevation_tiles=elevation_tiles,
            feature_tiles=feature_tiles,
        )
        ahn_2.configure(
            tiles=tiles,
            version=2,
            directory_mapping=self.cfg["config"]["directory_mapping"],
            tin=False,
        )
        # Configure feature tiles with elevation from AHN3
        ahn_3 = tileconfig.DbTilesAHN(
            conn=conn,
            elevation_tiles=elevation_tiles,
            feature_tiles=feature_tiles,
        )
        ahn_3.configure(
            tiles=tiles,
            version=3,
            directory_mapping=self.cfg["config"]["directory_mapping"],
            tin=False,
        )
        # Configure feature tiles that are on the border of AHN2 and AHN3
        ahn_border = tileconfig.DbTilesAHN(
            conn=conn,
            elevation_tiles=elevation_tiles,
            feature_tiles=feature_tiles,
        )
        ahn_border.configure(
            tiles=tiles,
            on_border=True,
            directory_mapping=self.cfg["config"]["directory_mapping"],
            tin=False,
        )

        out_dir = output.DirOutput(self.cfg["config"]["output"]["dir"])
        # Set up logic
        parts = {"AHN2": ahn_2, "AHN3": ahn_3, "AHN_border": ahn_border}
        for part, ahntiles in parts.items():
            ahntiles.output = output.Output(
                dir=output.DirOutput(out_dir.join_path(part)))
            proc = processor.factory.create(processor_key,
                                            name=part,
                                            tiles=ahntiles)
            self.processors[proc] = part
        log.info(f"Configured {self.__class__.__name__}")
Beispiel #9
0
    def configure(self,
                  tiles,
                  processor_key: str,
                  worker_key: str = None,
                  worker_class=None,
                  restart: int = 0):
        """Configure the control logic."""
        if worker_key:
            worker_init = worker.factory.create(worker_key)
        else:
            worker_init = worker_class
        self.cfg["worker"] = worker_init.execute

        # Configure the tiles
        conn = db.Db(**self.cfg["config"]["database"])
        elevation_tiles = tileconfig.DbTiles(
            conn=conn,
            tile_index_schema=db.Schema(self.cfg["config"]["elevation_tiles"]),
        )
        feature_tiles = tileconfig.DbTiles(
            conn=conn,
            tile_index_schema=db.Schema(self.cfg["config"]["features_tiles"]),
            features_schema=db.Schema(self.cfg["config"]["features"]),
        )
        # Configure feature tiles with elevation from AHN3
        ahntiles = tileconfig.DbTilesAHN(
            conn=conn,
            elevation_tiles=elevation_tiles,
            feature_tiles=feature_tiles,
        )
        ahntiles.configure(
            tiles=tiles,
            version=None,
            directory_mapping=self.cfg["config"]["directory_mapping"],
            tin=False,
        )
        # Set up outputs
        output_obj = output.Output()
        if "database" in self.cfg["config"]["output"]:
            output_obj.db = output.DbOutput(conn=db.Db(
                **self.cfg["config"]["output"]["database"]))
        if "dir" in self.cfg["config"]["output"]:
            # FIXME: Output.dir should be a dict maybe by default?
            output_obj.dir = {}
            if isinstance(self.cfg["config"]["output"]["dir"], str):
                output_obj.dir["path"] = output.DirOutput(
                    path=self.cfg["config"]["output"]["dir"])
            elif isinstance(self.cfg["config"]["output"]["dir"], dict):
                for k, dirpath in self.cfg["config"]["output"]["dir"].items():
                    output_obj.dir[k] = output.DirOutput(dirpath)
            else:
                raise ValueError(
                    f'Expected str or dict in {self.cfg["config"]["output"]["dir"]}'
                )
        for k, v in self.cfg["config"]["output"].items():
            if k != "database" and k != "dir":
                output_obj.kwargs[k] = v
        ahntiles.output = output_obj
        name = "part1"
        proc = processor.factory.create(processor_key,
                                        name=name,
                                        tiles=ahntiles)
        self.processors[proc] = name
        log.info(f"Configured {self.__class__.__name__}")
Beispiel #10
0
 def test_create_file_index(self, directory_mapping, file_index_ahn):
     ft = tileconfig.DbTilesAHN(
         conn=None, elevation_tiles=None, feature_tiles=None, output=None
     )
     result = ft.create_elevation_file_index(directory_mapping)
     assert result == file_index_ahn