Skip to content

Commit f227899

Browse files
authored
Merge pull request #992 from mapswipe/fix/mapillary-image-error-handling
Fix Mapillary image metadata error handling
2 parents 3974bf5 + 0e8b15b commit f227899

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

mapswipe_workers/mapswipe_workers/utils/process_mapillary.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from shapely.geometry import shape
1010
from vt2geojson import tools as vt2geojson_tools
1111

12-
from mapswipe_workers.definitions import MAPILLARY_API_KEY, MAPILLARY_API_LINK, logger
12+
from mapswipe_workers.definitions import (
13+
MAPILLARY_API_KEY,
14+
MAPILLARY_API_LINK,
15+
CustomError,
16+
logger,
17+
)
1318
from mapswipe_workers.utils.spatial_sampling import spatial_sampling
1419

1520

@@ -177,28 +182,24 @@ def filter_results(
177182
df = results_df.copy()
178183
if creator_id is not None:
179184
if df["creator_id"].isna().all():
180-
logger.exception(
181-
"No Mapillary Feature in the AoI has a 'creator_id' value."
182-
)
185+
logger.info("No Mapillary Feature in the AoI has a 'creator_id' value.")
183186
return None
184187
df = df[df["creator_id"] == creator_id]
185188
if is_pano is not None:
186189
if df["is_pano"].isna().all():
187-
logger.exception("No Mapillary Feature in the AoI has a 'is_pano' value.")
190+
logger.info("No Mapillary Feature in the AoI has a 'is_pano' value.")
188191
return None
189192
df = df[df["is_pano"] == is_pano]
190193
if organization_id is not None:
191194
if df["organization_id"].isna().all():
192-
logger.exception(
195+
logger.info(
193196
"No Mapillary Feature in the AoI has an 'organization_id' value."
194197
)
195198
return None
196199
df = df[df["organization_id"] == organization_id]
197200
if start_time is not None:
198201
if df["captured_at"].isna().all():
199-
logger.exception(
200-
"No Mapillary Feature in the AoI has a 'captured_at' value."
201-
)
202+
logger.info("No Mapillary Feature in the AoI has a 'captured_at' value.")
202203
return None
203204
df = filter_by_timerange(df, start_time, end_time)
204205
return df
@@ -225,7 +226,7 @@ def get_image_metadata(
225226
aoi_polygon = geojson_to_polygon(aoi_geojson)
226227
downloaded_metadata = coordinate_download(aoi_polygon, level, kwargs)
227228
if downloaded_metadata.empty or downloaded_metadata.isna().all().all():
228-
raise ValueError(
229+
raise CustomError(
229230
"No Mapillary Features in the AoI or no Features match the filter criteria."
230231
)
231232
downloaded_metadata = downloaded_metadata.drop_duplicates(subset=["geometry"])
@@ -237,7 +238,7 @@ def get_image_metadata(
237238

238239
total_images = len(downloaded_metadata)
239240
if total_images > 100000:
240-
raise ValueError(
241+
raise CustomError(
241242
f"Too many Images with selected filter options for the AoI: {total_images}"
242243
)
243244

mapswipe_workers/tests/unittests/test_process_mapillary.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from shapely import wkt
88
from shapely.geometry import GeometryCollection, MultiPolygon, Point, Polygon
99

10+
from mapswipe_workers.definitions import CustomError
1011
from mapswipe_workers.utils.process_mapillary import (
1112
coordinate_download,
1213
create_tiles,
@@ -316,7 +317,7 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
316317
df = df.drop(df.index)
317318
mock_coordinate_download.return_value = df
318319

319-
with self.assertRaises(ValueError):
320+
with self.assertRaises(CustomError):
320321
get_image_metadata(self.fixture_data)
321322

322323
@patch("mapswipe_workers.utils.process_mapillary.filter_results")
@@ -326,7 +327,7 @@ def test_get_image_metadata_size_restriction(
326327
):
327328
mock_df = pd.DataFrame({"id": range(1, 100002), "geometry": range(1, 100002)})
328329
mock_coordinate_download.return_value = mock_df
329-
with self.assertRaises(ValueError):
330+
with self.assertRaises(CustomError):
330331
get_image_metadata(self.fixture_data)
331332

332333
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")

0 commit comments

Comments
 (0)