Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions mapswipe_workers/mapswipe_workers/utils/process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from shapely.geometry import shape
from vt2geojson import tools as vt2geojson_tools

from mapswipe_workers.definitions import MAPILLARY_API_KEY, MAPILLARY_API_LINK, logger
from mapswipe_workers.definitions import (
MAPILLARY_API_KEY,
MAPILLARY_API_LINK,
CustomError,
logger,
)
from mapswipe_workers.utils.spatial_sampling import spatial_sampling


Expand Down Expand Up @@ -177,28 +182,24 @@ def filter_results(
df = results_df.copy()
if creator_id is not None:
if df["creator_id"].isna().all():
logger.exception(
"No Mapillary Feature in the AoI has a 'creator_id' value."
)
logger.info("No Mapillary Feature in the AoI has a 'creator_id' value.")
return None
df = df[df["creator_id"] == creator_id]
if is_pano is not None:
if df["is_pano"].isna().all():
logger.exception("No Mapillary Feature in the AoI has a 'is_pano' value.")
logger.info("No Mapillary Feature in the AoI has a 'is_pano' value.")
return None
df = df[df["is_pano"] == is_pano]
if organization_id is not None:
if df["organization_id"].isna().all():
logger.exception(
logger.info(
"No Mapillary Feature in the AoI has an 'organization_id' value."
)
return None
df = df[df["organization_id"] == organization_id]
if start_time is not None:
if df["captured_at"].isna().all():
logger.exception(
"No Mapillary Feature in the AoI has a 'captured_at' value."
)
logger.info("No Mapillary Feature in the AoI has a 'captured_at' value.")
return None
df = filter_by_timerange(df, start_time, end_time)
return df
Expand All @@ -225,7 +226,7 @@ def get_image_metadata(
aoi_polygon = geojson_to_polygon(aoi_geojson)
downloaded_metadata = coordinate_download(aoi_polygon, level, kwargs)
if downloaded_metadata.empty or downloaded_metadata.isna().all().all():
raise ValueError(
raise CustomError(
"No Mapillary Features in the AoI or no Features match the filter criteria."
)
downloaded_metadata = downloaded_metadata.drop_duplicates(subset=["geometry"])
Expand All @@ -237,7 +238,7 @@ def get_image_metadata(

total_images = len(downloaded_metadata)
if total_images > 100000:
raise ValueError(
raise CustomError(
f"Too many Images with selected filter options for the AoI: {total_images}"
)

Expand Down
5 changes: 3 additions & 2 deletions mapswipe_workers/tests/unittests/test_process_mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from shapely import wkt
from shapely.geometry import GeometryCollection, MultiPolygon, Point, Polygon

from mapswipe_workers.definitions import CustomError
from mapswipe_workers.utils.process_mapillary import (
coordinate_download,
create_tiles,
Expand Down Expand Up @@ -316,7 +317,7 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
df = df.drop(df.index)
mock_coordinate_download.return_value = df

with self.assertRaises(ValueError):
with self.assertRaises(CustomError):
get_image_metadata(self.fixture_data)

@patch("mapswipe_workers.utils.process_mapillary.filter_results")
Expand All @@ -326,7 +327,7 @@ def test_get_image_metadata_size_restriction(
):
mock_df = pd.DataFrame({"id": range(1, 100002), "geometry": range(1, 100002)})
mock_coordinate_download.return_value = mock_df
with self.assertRaises(ValueError):
with self.assertRaises(CustomError):
get_image_metadata(self.fixture_data)

@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
Expand Down