Skip to content

Commit c0016e2

Browse files
committed
style: fix flake8 errors and isort
1 parent 9503a7d commit c0016e2

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

mapswipe_workers/mapswipe_workers/project_types/street/project.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import json
2-
import os
3-
import urllib
41
import math
5-
6-
from osgeo import ogr
72
from dataclasses import dataclass
8-
from mapswipe_workers.definitions import DATA_PATH, logger
3+
from typing import Dict, List
4+
5+
from mapswipe_workers.definitions import logger
96
from mapswipe_workers.firebase.firebase import Firebase
107
from mapswipe_workers.firebase_to_postgres.transfer_results import (
118
results_to_file,
@@ -15,16 +12,16 @@
1512
from mapswipe_workers.generate_stats.project_stats import (
1613
get_statistics_for_integer_result_project,
1714
)
15+
from mapswipe_workers.project_types.project import BaseGroup, BaseProject, BaseTask
16+
from mapswipe_workers.utils.process_mapillary import get_image_metadata
1817
from mapswipe_workers.utils.validate_input import (
19-
check_if_layer_is_empty,
20-
load_geojson_to_ogr,
2118
build_multipolygon_from_layer_geometries,
2219
check_if_layer_has_too_many_geometries,
23-
save_geojson_to_file,
20+
check_if_layer_is_empty,
21+
load_geojson_to_ogr,
2422
multipolygon_to_wkt,
23+
save_geojson_to_file,
2524
)
26-
from mapswipe_workers.project_types.project import BaseProject, BaseTask, BaseGroup
27-
from mapswipe_workers.utils.process_mapillary import get_image_metadata
2825

2926

3027
@dataclass

mapswipe_workers/mapswipe_workers/utils/process_mapillary.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
import os
2+
from concurrent.futures import ThreadPoolExecutor, as_completed
3+
14
import mercantile
2-
import json
5+
import pandas as pd
36
import requests
4-
import os
5-
import time
67
from shapely import (
7-
box,
8-
Polygon,
9-
MultiPolygon,
10-
Point,
118
LineString,
129
MultiLineString,
10+
MultiPolygon,
11+
Point,
12+
Polygon,
13+
box,
1314
unary_union,
1415
)
1516
from shapely.geometry import shape
16-
import pandas as pd
1717
from vt2geojson import tools as vt2geojson_tools
18-
from concurrent.futures import ThreadPoolExecutor, as_completed
19-
from mapswipe_workers.definitions import MAPILLARY_API_LINK, MAPILLARY_API_KEY
20-
from mapswipe_workers.definitions import logger
18+
19+
from mapswipe_workers.definitions import MAPILLARY_API_KEY, MAPILLARY_API_LINK, logger
2120
from mapswipe_workers.utils.spatial_sampling import spatial_sampling
2221

2322

@@ -140,8 +139,8 @@ def coordinate_download(
140139
downloaded_metadata[col] = None
141140

142141
if (
143-
downloaded_metadata.isna().all().all() == False
144-
or downloaded_metadata.empty == True
142+
downloaded_metadata.isna().all().all() is False
143+
or downloaded_metadata.empty is True
145144
):
146145
downloaded_metadata = downloaded_metadata[
147146
downloaded_metadata["geometry"].apply(
@@ -243,8 +242,8 @@ def get_image_metadata(
243242
if sampling_threshold is not None:
244243
downloaded_metadata = spatial_sampling(downloaded_metadata, sampling_threshold)
245244
if (
246-
downloaded_metadata.isna().all().all() == False
247-
or downloaded_metadata.empty == False
245+
downloaded_metadata.isna().all().all() is False
246+
or downloaded_metadata.empty is False
248247
):
249248
if len(downloaded_metadata) > 100000:
250249
err = (

mapswipe_workers/mapswipe_workers/utils/spatial_sampling.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import numpy as np
22
import pandas as pd
3-
from shapely import wkt
4-
from shapely.geometry import Point
53

64

75
def distance_on_sphere(p1, p2):
86
"""
9-
p1 and p2 are two lists that have two elements. They are numpy arrays of the long and lat
10-
coordinates of the points in set1 and set2
7+
p1 and p2 are two lists that have two elements. They are numpy arrays of the long
8+
and lat coordinates of the points in set1 and set2
119
12-
Calculate the distance between two points on the Earth's surface using the haversine formula.
10+
Calculate the distance between two points on the Earth's surface using the
11+
haversine formula.
1312
1413
Args:
15-
p1 (list): Array containing the longitude and latitude coordinates of points FROM which the distance to be calculated in degree
16-
p2 (list): Array containing the longitude and latitude coordinates of points TO which the distance to be calculated in degree
14+
p1 (list): Array containing the longitude and latitude coordinates of points
15+
FROM which the distance to be calculated in degree
16+
p2 (list): Array containing the longitude and latitude coordinates of points
17+
TO which the distance to be calculated in degree
1718
1819
Returns:
19-
numpy.ndarray: Array containing the distances between the two points on the sphere in kilometers.
20+
numpy.ndarray: Array containing the distances between the two points on the
21+
sphere in kilometers.
2022
21-
This function computes the distance between two points on the Earth's surface using the haversine formula,
22-
which takes into account the spherical shape of the Earth. The input arrays `p1` and `p2` should contain
23-
longitude and latitude coordinates in degrees. The function returns an array containing the distances
23+
This function computes the distance between two points on the Earth's surface
24+
using the haversine formula, which takes into account the spherical shape of the
25+
Earth. The input arrays `p1` and `p2` should contain longitude and latitude
26+
coordinates in degrees. The function returns an array containing the distances
2427
between corresponding pairs of points.
2528
"""
2629
earth_radius = 6371 # km
@@ -41,7 +44,7 @@ def distance_on_sphere(p1, p2):
4144
return distances
4245

4346

44-
"""-----------------------------------Filtering Points------------------------------------------------"""
47+
"""----------------------------Filtering Points-------------------------------"""
4548

4649

4750
def filter_points(df, threshold_distance):
@@ -56,10 +59,11 @@ def filter_points(df, threshold_distance):
5659
pandas.DataFrame: Filtered DataFrame containing selected points.
5760
float: Total road length calculated from the selected points.
5861
59-
This function filters points from a DataFrame based on the given threshold distance. It calculates
60-
distances between consecutive points and accumulates them until the accumulated distance surpasses
61-
the threshold distance. It then selects those points and constructs a new DataFrame. Additionally,
62-
it manually checks the last point to include it if it satisfies the length condition. The function
62+
This function filters points from a DataFrame based on the given threshold
63+
distance. It calculates distances between consecutive points and accumulates them
64+
until the accumulated distance surpasses the threshold distance. It then selects
65+
those points and constructs a new DataFrame. Additionally, it manually checks the
66+
last point to include it if it satisfies the length condition. The function
6367
returns the filtered DataFrame along with the calculated road length.
6468
"""
6569
road_length = 0
@@ -83,7 +87,8 @@ def filter_points(df, threshold_distance):
8387
accumulated_distance = 0 # Reset accumulated distance
8488

8589
to_be_returned_df = df[mask]
86-
# since the last point has to be omitted in the vectorized distance calculation, it is being checked manually
90+
# since the last point has to be omitted in the vectorized distance calculation,
91+
# it is being checked manually
8792
p2 = to_be_returned_df.iloc[0]
8893
distance = distance_on_sphere(
8994
[float(p2["long"]), float(p2["lat"])], [long[-1], lat[-1]]
@@ -114,10 +119,10 @@ def spatial_sampling(df, interval_length):
114119
geopandas.GeoDataFrame: Filtered GeoDataFrame containing selected points.
115120
float: Total road length calculated from the selected points.
116121
117-
This function calculates the spacing between points in a GeoDataFrame by filtering points
118-
based on the provided interval length. It first sorts the GeoDataFrame by timestamp and
119-
then filters points using the filter_points function. The function returns the filtered
120-
GeoDataFrame along with the total road length.
122+
This function calculates the spacing between points in a GeoDataFrame by filtering
123+
points based on the provided interval length. It first sorts the GeoDataFrame by
124+
timestamp and then filters points using the filter_points function. The function
125+
returns the filtered GeoDataFrame along with the total road length.
121126
"""
122127
if len(df) == 1:
123128
return df

0 commit comments

Comments
 (0)