Commit e2db986b authored by Eric Duminil's avatar Eric Duminil
Browse files

formatting

parent 302428e1
Showing with 11 additions and 12 deletions
+11 -12
...@@ -69,7 +69,7 @@ def find_simstadt_folder(): ...@@ -69,7 +69,7 @@ def find_simstadt_folder():
"""Find SimStadt installation on desktop""" """Find SimStadt installation on desktop"""
try: try:
simstadt_folder = next(x for x in Path.home().glob('Desktop/SimStadt*_0.*/') if x.is_dir()) simstadt_folder = next(x for x in Path.home().glob('Desktop/SimStadt*_0.*/') if x.is_dir())
logger.info(f"RegionChooser has been found in {simstadt_folder}") logger.info("RegionChooser has been found in %s", simstadt_folder)
return simstadt_folder return simstadt_folder
except StopIteration: except StopIteration:
return None return None
...@@ -98,8 +98,8 @@ def wkt_polygon_to_grid_coords(location_name: str, wkt_str: str) -> tuple[int, i ...@@ -98,8 +98,8 @@ def wkt_polygon_to_grid_coords(location_name: str, wkt_str: str) -> tuple[int, i
min_lon, max_lon = min(lons), max(lons) min_lon, max_lon = min(lons), max(lons)
min_lat, max_lat = min(lats), max(lats) min_lat, max_lat = min(lats), max(lats)
logger.info("%s (%.3f°N %.3f°E -> %.3f°N %.3f°E)" % logger.info("%s (%.3f°N %.3f°E -> %.3f°N %.3f°E)",
(location_name, max_lat, min_lon, min_lat, max_lon)) location_name, max_lat, min_lon, min_lat, max_lon)
x1, y1 = coordinates_to_grid(min_lon, min_lat) x1, y1 = coordinates_to_grid(min_lon, min_lat)
x2, y2 = coordinates_to_grid(max_lon, max_lat) x2, y2 = coordinates_to_grid(max_lon, max_lat)
...@@ -122,19 +122,19 @@ def download_whole_region(output_dir: Path, wkt_region: str, x1: int, x2: int, y ...@@ -122,19 +122,19 @@ def download_whole_region(output_dir: Path, wkt_region: str, x1: int, x2: int, y
citygml_url = f"{CITYGML_SERVER}/{citygml_zip}" citygml_url = f"{CITYGML_SERVER}/{citygml_zip}"
local_zip = output_dir / citygml_zip local_zip = output_dir / citygml_zip
if local_zip.exists(): if local_zip.exists():
logger.info(f" {local_zip.name} already in {output_dir.name}/") logger.info(" %s already in %s/", local_zip.name, output_dir.name)
else: else:
logger.info(f" Download {citygml_zip} to {output_dir.name}/ ") logger.info(" Download %s to %s/", citygml_zip, output_dir.name)
try: try:
urllib.request.urlretrieve(citygml_url, local_zip) urllib.request.urlretrieve(citygml_url, local_zip)
logger.info("✅ Download successful") logger.info("✅ Download successful")
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
logger.error(f"❌ {e}") logger.error("❌ %s", e)
continue continue
finally: finally:
time.sleep(WAIT_BETWEEN_DOWNLOADS) time.sleep(WAIT_BETWEEN_DOWNLOADS)
logger.info(f" Extract {citygml_zip} to {output_dir.name}/ ") logger.info(" Extract %s to %s/", citygml_zip, output_dir.name)
with zipfile.ZipFile(local_zip, "r") as zip_ref: with zipfile.ZipFile(local_zip, "r") as zip_ref:
zip_ref.extractall(output_dir) zip_ref.extractall(output_dir)
logger.info("✅ Extraction successful") logger.info("✅ Extraction successful")
...@@ -144,7 +144,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_ ...@@ -144,7 +144,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
"""Uses RegionChooser to extract a given region from all the CityGML files found in subfolder.""" """Uses RegionChooser to extract a given region from all the CityGML files found in subfolder."""
output_file = output_dir / (location_name + '.gml') output_file = output_dir / (location_name + '.gml')
if output_file.exists(): if output_file.exists():
logger.info(f" {output_file} already exists. Not extracting.") logger.info(" %s already exists. Not extracting.", output_file)
return return
region_chooser_libs = simstadt_folder / 'lib/*' region_chooser_libs = simstadt_folder / 'lib/*'
...@@ -159,7 +159,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_ ...@@ -159,7 +159,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
local_wkt = convert_wkt_to_local(wkt_str) local_wkt = convert_wkt_to_local(wkt_str)
logger.info(f" Extracting {output_file}.") logger.info(" Extracting %s.", output_file)
with open(wkt_path, 'w') as f: with open(wkt_path, 'w') as f:
f.write(local_wkt) f.write(local_wkt)
...@@ -182,7 +182,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_ ...@@ -182,7 +182,7 @@ def extract_region(output_dir: Path, location_name: str, wkt_str: str, simstadt_
check=False check=False
) )
if result.stderr: if result.stderr:
logger.error(result.stderr) logger.error("%s", result.stderr)
if result.returncode != 0: if result.returncode != 0:
raise ValueError(f"RegionChooser failed with code {result.returncode}") raise ValueError(f"RegionChooser failed with code {result.returncode}")
logger.info(" DONE!") logger.info(" DONE!")
...@@ -273,10 +273,9 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s ...@@ -273,10 +273,9 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s
else: else:
logger.info("Download-only mode: Skipping region extraction.") logger.info("Download-only mode: Skipping region extraction.")
logger.info(f"Processing of {location_name} complete!") logger.info("Processing of %s complete!", location_name)
if __name__ == '__main__': if __name__ == '__main__':
args = parse_arguments() args = parse_arguments()
main(args.name, args.region, args.download_only, args.simstadt_folder) main(args.name, args.region, args.download_only, args.simstadt_folder)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment