Skip to content

Commit

Permalink
skip missing maps
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 committed Jan 23, 2025
1 parent 1c98024 commit 16778c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 12 additions & 5 deletions mapreader/download/sheet_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def _download_map(
existing_id: str | bool,
download_in_parallel: bool = True,
overwrite: bool = False,
force: bool = False,
error_on_missing_map=True,
) -> str | bool:
"""
Downloads a single map sheet and saves as png file.
Expand All @@ -545,8 +545,8 @@ def _download_map(
Whether to download tiles in parallel, by default ``True``.
overwrite : bool, optional
Whether to overwrite existing maps, by default ``False``.
force : bool, optional
Whether to force the download or ask for confirmation, by default ``False``.
error_on_missing_map : bool, optional
Whether to raise an error if a map sheet is missing, by default True.
Returns
-------
Expand All @@ -563,13 +563,16 @@ def _download_map(
map_name = existing_id[:-4] # remove file extension (assuming .png)

img_path, success = self.merger.merge(
feature["grid_bb"], file_name=map_name, overwrite=overwrite
feature["grid_bb"],
file_name=map_name,
overwrite=overwrite,
error_on_missing_map=error_on_missing_map,
)

if success:
print(f'[INFO] Downloaded "{img_path}"')
else:
print(f'[WARNING] Download of "{img_path}" was unsuccessful.')
print("[WARNING] Download unsuccessful.")

Check warning on line 575 in mapreader/download/sheet_downloader.py

View check run for this annotation

Codecov / codecov/patch

mapreader/download/sheet_downloader.py#L575

Added line #L575 was not covered by tests

# Try to remove the temporary folder
try:
Expand Down Expand Up @@ -686,6 +689,7 @@ def _download_map_sheets(
overwrite: bool | None = False,
download_in_parallel: bool = True,
force: bool = False,
error_on_missing_map: bool = True,
**kwargs: dict | None,
):
"""Download map sheets from features.
Expand All @@ -704,6 +708,8 @@ def _download_map_sheets(
Whether to download tiles in parallel, by default ``True``.
force : bool, optional
Whether to force the download or ask for confirmation, by default ``False``.
error_on_missing_map : bool, optional
Whether to raise an error if a map sheet is missing, by default True.
**kwargs : dict, optional
Keyword arguments to pass to the
:meth:`~.download.sheet_downloader.SheetDownloader._save_metadata`
Expand Down Expand Up @@ -759,6 +765,7 @@ def _download_map_sheets(
existing_id,
download_in_parallel=download_in_parallel,
overwrite=overwrite,
error_on_missing_map=error_on_missing_map,
)
if img_path is not False:
metadata_path = f"{path_save}/{metadata_fname}"
Expand Down
8 changes: 7 additions & 1 deletion mapreader/download/tile_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def merge(
grid_bb: GridBoundingBox,
file_name: str | None = None,
overwrite: bool = False,
error_on_missing_map: bool = True,
) -> str | bool:
"""Merges cells contained within GridBoundingBox.
Expand All @@ -167,7 +168,12 @@ def merge(
"""
os.makedirs(self.output_folder, exist_ok=True)

tile_size = self._load_tile_size(grid_bb)
try:
tile_size = self._load_tile_size(grid_bb)
except FileNotFoundError as err:
if error_on_missing_map:
raise err
return False, False

Check warning on line 176 in mapreader/download/tile_merging.py

View check run for this annotation

Codecov / codecov/patch

mapreader/download/tile_merging.py#L173-L176

Added lines #L173 - L176 were not covered by tests

merged_image = Image.new(
"RGBA", (len(grid_bb.x_range) * tile_size, len(grid_bb.y_range) * tile_size)
Expand Down

0 comments on commit 16778c6

Please sign in to comment.