Skip to content
Snippets Groups Projects
Commit 0eee3873 authored by Danijel Schorlemmer's avatar Danijel Schorlemmer
Browse files

[Hotfix] - Correct wrong call to function in processing gaps of small countries

parent 2a88004a
No related branches found
Tags v2.2.1
1 merge request!34Resolve "[Hotfix] - Processing countries without the `large-country` flag fails"
Pipeline #68066 passed
......@@ -489,7 +489,7 @@ class ExposureInitializer:
self.exposure_db.cursor.execute(sql_statement)
self.exposure_db.connection.commit()
def process_gaps_in_exposure(self, country_iso_code, is_large_country=False):
def process_gaps_in_exposure(self, country_iso_code, low_memory_usage=False):
"""
In the case of missing exposure data for districts in the country, tiles containing
built area will not be covered with assets. Also, tiles at the border with the centroid
......@@ -506,9 +506,9 @@ class ExposureInitializer:
Args:
country_iso_code (str):
ISO 3166-1 alpha-3 code of the country.
is_large_country (bool, optional, default: False):
Switch for processing large countries in case of memory problems. If set to
`True`, a slower but less memory-consuming process is used.
low_memory_usage (bool, optional, default: False):
Switch in case of memory problems. If set to `True`, a slower but less
memory-consuming process is used.
"""
# Get the assets of the average building in the country
......@@ -523,19 +523,19 @@ class ExposureInitializer:
# Calculate the total built area in the country
logger.info(f"Calculating the total built area in country {country_iso_code}.")
quadkeys = []
if is_large_country:
if low_memory_usage:
# To avoid a query over the full country, first retrieve all quadkeys of the country
# and then compute the total built area stepwise in batches of quadkeys
quadkeys = self.exposure_db.get_country_tiles(country_iso_code)
total_built_area = self.exposure_db.get_built_area_from_quadkeys(quadkeys)
else:
# For small countries the query can be directly executed
total_built_area = self.exposure_db.cursor.get_country_built_area(country_iso_code)
total_built_area = self.exposure_db.get_country_built_area(country_iso_code)
logger.info(f"Total built area in country {country_iso_code}: {total_built_area}.")
# Select all tiles within the country (and with built area) without reference entities.
logger.info("Retrieving all tiles with built area but without reference entities.")
if is_large_country:
if low_memory_usage:
tiles = self.exposure_db.get_tiles_without_reference_entities(quadkeys=quadkeys)
else:
tiles = self.exposure_db.get_tiles_without_reference_entities(
......@@ -713,10 +713,10 @@ def command_line_interface():
)
parser_postgis.add_argument(
"-l",
"--large-country",
"--low-memory-usage",
required=False,
action="store_true",
help="Switch for processing large countries in case of memory problems",
help="Switch in case of memory problems",
)
# Read arguments from command line
......@@ -725,7 +725,7 @@ def command_line_interface():
exposure_model = args.exposure_model
country_iso_code = args.country_iso_code
postgis_config_file = args.config_file
is_large_country = args.large_country
low_memory_usage = args.low_memory_usage
# Create dictionary from INI-style config file
postgis_config = configparser.ConfigParser()
......@@ -759,7 +759,7 @@ def command_line_interface():
initializer.exposure_db.remove_asset_country(country_iso_code)
initializer.import_exposure(exposure_model, country_iso_code, num_processors)
initializer.process_gaps_in_exposure(
country_iso_code, is_large_country=is_large_country
country_iso_code, low_memory_usage=low_memory_usage
)
initializer.exposure_db.commit_and_close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment