From 64553efdad31066d0c7d53fbaa54fdec7027f449 Mon Sep 17 00:00:00 2001 From: Levi Szamek Date: Mon, 24 Feb 2025 17:07:15 +0100 Subject: [PATCH 1/3] fix: remove duplicates after spatial sampling --- mapswipe_workers/mapswipe_workers/utils/process_mapillary.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py index f8db99cc..54afc2be 100644 --- a/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py +++ b/mapswipe_workers/mapswipe_workers/utils/process_mapillary.py @@ -229,13 +229,14 @@ def get_image_metadata( raise CustomError( "No Mapillary Features in the AoI or no Features match the filter criteria." ) - downloaded_metadata = downloaded_metadata.drop_duplicates(subset=["geometry"]) if sampling_threshold is not None: downloaded_metadata = spatial_sampling(downloaded_metadata, sampling_threshold) if randomize_order is True: downloaded_metadata = downloaded_metadata.sample(frac=1).reset_index(drop=True) + downloaded_metadata = downloaded_metadata.drop_duplicates(subset=["geometry"]) + total_images = len(downloaded_metadata) if total_images > 100000: raise CustomError( From 809f0f8f26b229d8ac9b9ca1784d11effff5e6c0 Mon Sep 17 00:00:00 2001 From: Levi Szamek Date: Mon, 3 Mar 2025 15:26:38 +0100 Subject: [PATCH 2/3] fix: handle FutureWarning when concating dfs --- mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py b/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py index 97302b94..739ae39a 100644 --- a/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py +++ b/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py @@ -143,6 +143,9 @@ def spatial_sampling(df, interval_length): if interval_length: sequence_df = filter_points(sequence_df, interval_length) + # below line prevents FutureWarning + # (https://stackoverflow.com/questions/73800841/add-series-as-a-new-row-into-dataframe-triggers-futurewarning) + sequence_df["is_pano"] = sequence_df["is_pano"].astype(bool) sampled_sequence_df = pd.concat([sampled_sequence_df, sequence_df], axis=0) # reverse order such that sequence are in direction of travel From a7319e490cc97193ebcd64cebcb549b5f0974ad9 Mon Sep 17 00:00:00 2001 From: Levi Szamek Date: Mon, 3 Mar 2025 16:16:31 +0100 Subject: [PATCH 3/3] fix: check if column exists before using astype --- .../mapswipe_workers/utils/spatial_sampling.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py b/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py index 739ae39a..67f35c7e 100644 --- a/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py +++ b/mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py @@ -143,9 +143,10 @@ def spatial_sampling(df, interval_length): if interval_length: sequence_df = filter_points(sequence_df, interval_length) - # below line prevents FutureWarning - # (https://stackoverflow.com/questions/73800841/add-series-as-a-new-row-into-dataframe-triggers-futurewarning) - sequence_df["is_pano"] = sequence_df["is_pano"].astype(bool) + if "is_pano" in sequence_df.columns: + # below line prevents FutureWarning + # (https://stackoverflow.com/questions/73800841/add-series-as-a-new-row-into-dataframe-triggers-futurewarning) + sequence_df["is_pano"] = sequence_df["is_pano"].astype(bool) sampled_sequence_df = pd.concat([sampled_sequence_df, sequence_df], axis=0) # reverse order such that sequence are in direction of travel