diff --git a/gdecore/database_queries.py b/gdecore/database_queries.py index 500dc6ffacdb0bca7492226c80317bee32c797e4..874f81db70399d18b23da195fc5c7a115e8b804c 100644 --- a/gdecore/database_queries.py +++ b/gdecore/database_queries.py @@ -631,66 +631,3 @@ class DatabaseQueries: ) return building_classes_proportions - - @staticmethod - def get_quadkeys_of_exposure_entity( - exposure_entity, aggregated_source_id, db_gde_tiles_config, db_table - ): - """This function retrieves the quadkeys of the tiles associated with an - 'exposure_entity' and an 'aggregated_source_id' from the table with name 'db_table' in - the database whose credentials are indicated in 'db_gde_tiles_config'. - - Args: - exposure_entity (str): - 3-character code of the exposure entity for which the quadkeys will be - retrieved. - aggregated_source_id (int): - ID of the source of the aggregated exposure model. - db_gde_tiles_config (dict): - Dictionary containing the credentials needed to connect to the SQL database in - which information on the data-unit tiles is stored. The keys of the dictionary - need to be: - host (str): - SQL database host address. - dbname (str): - Name of the SQL database. - port (int): - Port where the SQL database can be found. - username (str): - User name to connect to the SQL database. - password (str): - Password associated with self.username. - db_table (str): - Name of the table of the SQL database where the data-unit tiles are stored. It - is assumed that this table contains, at least, the following fields: - quadkey (str): - String indicating the quadkey of a tile. - aggregated_source_id (int): - ID of the source of the aggregated exposure model. - exposure_entity (str): - 3-character code of the exposure entity. - - Returns: - quadkeys (array of str): - Unique quadkeys associated with 'exposure_entity' and 'aggregated_source_id'. - """ - - sql_query = "SELECT DISTINCT quadkey FROM %s" - sql_query += " WHERE exposure_entity='%s' AND aggregated_source_id=%s;" - - db_gde_tiles = Database(**db_gde_tiles_config) - db_gde_tiles.create_connection_and_cursor() - - db_gde_tiles.cursor.execute( - sql_query % (db_table, exposure_entity, aggregated_source_id) - ) - exec_result = db_gde_tiles.cursor.fetchall() - - db_gde_tiles.close_connection() - - if len(exec_result) > 1: # Entry exists --> retrieve - quadkeys = numpy.array([exec_result[i][0] for i in range(len(exec_result))]) - else: # No entries found - quadkeys = numpy.array([], dtype=str) - - return quadkeys diff --git a/gdecore/gdecore.py b/gdecore/gdecore.py index 4b5813936eae3363e389f444563c209fefa120df..579207ffdce2204da0aeecbe61c5d714106e7442 100644 --- a/gdecore/gdecore.py +++ b/gdecore/gdecore.py @@ -159,19 +159,6 @@ def main(): % (aux_log_string, str(len(obm_buildings_building_classes.keys()))) ) - # Get quadkeys associated with this exposure entity (all occupancies) - quadkeys = DatabaseQueries.get_quadkeys_of_exposure_entity( - exposure_entity_code, - aggregated_source_id, - config.database_gde_tiles, - "data_unit_tiles", - ) - - logger.info( - "%s quadkeys retrieved for exposure entity '%s'" - % (str(len(quadkeys)), exposure_entity_code) - ) - # Leave the program logger.info("gde-core has finished") sys.exit() diff --git a/tests/data/test_database_set_up.sql b/tests/data/test_database_set_up.sql index be3a9dadb93166177897cf2dff68d0afcd641f65..ac93a2f8c77ca70295dcc91e0d9db0a4a46ce42e 100644 --- a/tests/data/test_database_set_up.sql +++ b/tests/data/test_database_set_up.sql @@ -2,7 +2,6 @@ DROP TABLE IF EXISTS aggregated_sources; DROP TABLE IF EXISTS data_units; DROP TABLE IF EXISTS obm_buildings; DROP TABLE IF EXISTS data_units_buildings; -DROP TABLE IF EXISTS data_unit_tiles; DROP TYPE IF EXISTS occupancycase; DROP TYPE IF EXISTS settlement; DROP EXTENSION IF EXISTS postgis; @@ -165,35 +164,3 @@ VALUES ('A1/HBET:1-3', 'urban', 'all', 2, 'ABC', 'residential', 'ABC_10269', 0.2 ('C4/HBET:2-3', 'urban', 'Trade', 2, 'ABC', 'commercial', 'ABC_10269', 0.10, 0.0, 0.0, 2, 3), ('C5/HBET:1-2', 'urban', 'Offices', 2, 'ABC', 'commercial', 'ABC_10269', 0.20, 0.0, 0.0, 1, 2), ('C6/HBET:3-5', 'urban', 'Offices', 2, 'ABC', 'commercial', 'ABC_10269', 0.30, 0.0, 0.0, 3, 5); - -CREATE TABLE data_unit_tiles -( - quadkey char(18), - aggregated_source_id SMALLINT, - occupancy_case occupancycase, - exposure_entity char(3), - data_unit_id varchar, - size_data_unit_tile_area FLOAT, - size_data_unit_tile_built_up_area FLOAT, - fraction_data_unit_area FLOAT, - fraction_data_unit_built_up_area FLOAT, - aggregated_buildings FLOAT, - - PRIMARY KEY (quadkey, aggregated_source_id, occupancy_case, data_unit_id) -); -INSERT INTO data_unit_tiles(quadkey, - aggregated_source_id, - occupancy_case, - exposure_entity, - data_unit_id, - size_data_unit_tile_area, - size_data_unit_tile_built_up_area, - fraction_data_unit_area, - fraction_data_unit_built_up_area, - aggregated_buildings) -VALUES ('122010321033023130', 2, 'residential', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 15.7), -('122010321033023130', 2, 'commercial', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 23.4), -('122010321033023120', 2, 'residential', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 39.1), -('122010321033023120', 2, 'commercial', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 17.6), -('122010321033023132', 2, 'residential', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 34.4), -('122010321033023132', 2, 'commercial', 'ABC', 'ABC_10269', 0.0, 0.0, 0.0, 0.0, 11.5); diff --git a/tests/test_database_queries.py b/tests/test_database_queries.py index fa1a283161de2505aeca1425fb8252dd359bec1c..4daa33a5e5a1a5913b8c22da959969e42eeae31a 100644 --- a/tests/test_database_queries.py +++ b/tests/test_database_queries.py @@ -339,30 +339,3 @@ def test_get_building_classes_of_data_unit(test_db): for col_name in expected_columns: assert col_name in returned_building_classes.columns assert round(returned_building_classes["proportions"].sum(), 5) == 0.0 - - -def test_get_quadkeys_of_exposure_entity(test_db): - # Database connection (the Configuration class will define the credentials based on whether - # the code is running in the CI or locally) - config = Configuration( - os.path.join(os.path.dirname(__file__), "data", "config_for_testing_good.yml") - ) - - # Test case: quadkeys will be found - returned_quadkeys = DatabaseQueries.get_quadkeys_of_exposure_entity( - "ABC", 2, config.database_gde_tiles, "data_unit_tiles" - ) - - expected_quadkeys = ["122010321033023130", "122010321033023120", "122010321033023132"] - - assert len(returned_quadkeys) == len(expected_quadkeys) - - for quadkey in expected_quadkeys: - assert quadkey in returned_quadkeys - - # Test case: no quadkeys will be found - returned_quadkeys = DatabaseQueries.get_quadkeys_of_exposure_entity( - "XYZ", 2, config.database_gde_tiles, "data_unit_tiles" - ) - - assert len(returned_quadkeys) == 0