Skip to content

Commit 351f610

Browse files
Merge pull request #2 from cosbidev/v2.0.3
V2.0.3
2 parents 816a816 + 63d26c7 commit 351f610

11 files changed

Lines changed: 130 additions & 14 deletions

File tree

docs/source/API/analytics.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
Analytics
22
========
33

4+
visualization
5+
-------------
46
.. automodule:: pytrack.analytics.visualization
57
:members:
68
:undoc-members:
79
:show-inheritance:
810
:inherited-members:
11+
12+
video
13+
-------------
14+
.. automodule:: pytrack.analytics.video
15+
:members:
16+
:undoc-members:
17+
18+
plugins
19+
-------------
20+
.. automodule:: pytrack.analytics.plugins
21+
:members:
22+
:undoc-members:

docs/source/API/graph.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ utils
2727
.. automodule:: pytrack.graph.utils
2828
:members:
2929
:undoc-members:
30-
:show-inheritance:
30+
:show-inheritance:

docs/source/API/matching.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ candidate
77
:members:
88
:undoc-members:
99

10+
cleaning
11+
-------------
12+
.. automodule:: pytrack.matching.cleaning
13+
:members:
14+
:undoc-members:
15+
1016
matcher
1117
-------------
1218
.. automodule:: pytrack.matching.matcher

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
author = 'Matteo Tortora'
2525

2626
# The full version, including alpha/beta/rc tags
27-
release = '1.0.3'
27+
release = '2.0.3'
2828

2929
# -- General configuration ---------------------------------------------------
3030

pytrack/analytics/plugins.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Segmenter:
2+
""" Skeleton parent class to perform the segmentation operation.
3+
4+
"""
5+
def __init__(self):
6+
pass
7+
8+
def processing(self, img):
9+
""" It takes an input image and returns the processed image.
10+
"""
11+
pass
12+
13+
def run(self, img):
14+
""" It takes an input image and returns the mask of the segmented image.
15+
"""
16+
pass

pytrack/analytics/segmentator.py

Whitespace-only changes.

pytrack/analytics/video.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import cv2
66
import requests
77

8+
from pytrack.analytics import plugins
9+
810
PREV_PAN_ID = None
911

1012

@@ -102,7 +104,7 @@ def extract_streetview_pic(point, api_key, size="640x640", heading=90, pitch=-10
102104
return pic, meta
103105

104106

105-
def save_streetview(pic, meta, folder_path):
107+
def save_streetview(pic, meta, folder_path, model=None):
106108
""" Save streetview pic and metadata in the desired path.
107109
108110
Parameters
@@ -121,5 +123,9 @@ def save_streetview(pic, meta, folder_path):
121123
with open(os.path.join(folder_path, 'pic.png'), 'wb') as file:
122124
file.write(pic)
123125

126+
if isinstance(model, plugins.Segmenter):
127+
with open(os.path.join(folder_path, 'pic_seg.png'), 'wb') as file:
128+
file.write(model.run(pic))
129+
124130
with open(os.path.join(folder_path, 'metadata.json'), 'w+') as out_file:
125131
json.dump(meta, out_file)

pytrack/graph/distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def haversine_dist(lat1, lon1, lat2, lon2, earth_radius=EARTH_RADIUS_M):
5151
Earth's radius
5252
Returns
5353
----------
54-
dists: float
54+
dist: float
5555
Distance in units of earth_radius
5656
"""
5757
# convert decimal degrees to radians

pytrack/matching/cleaning.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from pytrack.graph import distance
2+
3+
4+
def veldist_filter(traj, th_dist=5, th_vel=3):
5+
""" It filters the GPS trajectory combining speed and distance between adjacent points.
6+
If the adjacent point distance does not exceed the threshold and the speed is less than th_vel (m/s), the current
7+
trajectory point is ignored.
8+
9+
Parameters
10+
----------
11+
traj: pandas.DataFrame
12+
Dataframe containing 3 columns [timestamp, latitude, longitude].
13+
th_dist: float, optional, default: 5 meters.
14+
Threshold for the distance of adjacent points.
15+
th_vel: float, optional, default: 3 m/s.
16+
Threshold for the velocity.
17+
18+
Returns
19+
-------
20+
df: pandas.DataFrame
21+
Filtered version of the input dataframe.
22+
"""
23+
24+
df = traj.copy()
25+
26+
i = 0
27+
while True:
28+
if i == df.shape[0]-1:
29+
break
30+
deltat = (df["datetime"][i+1]-df["datetime"][i]).total_seconds()
31+
dist = distance.haversine_dist(*tuple(df.iloc[i, [1, 2]]), *tuple(df.iloc[i+1, [1, 2]]))
32+
33+
if dist < th_dist and dist/deltat < th_vel:
34+
df.drop([i+1], inplace=True)
35+
df.reset_index(drop=True, inplace=True)
36+
else:
37+
i += 1
38+
39+
return df
40+
41+
42+
def park_filter(traj, th_dist=50, th_time=30):
43+
""" It removes parking behaviour by eliminating those points that remain in a certain area
44+
for a given amount of time.
45+
46+
Parameters
47+
----------
48+
traj: pandas.DataFrame
49+
Dataframe containing 3 columns [timestamp, latitude, longitude].
50+
th_dist: float, optional, default: 50 meters.
51+
Threshold for the distance of adjacent points.
52+
th_time: float, optional, default: 30 min.
53+
Threshold for the delta time.
54+
55+
Returns
56+
-------
57+
df: pandas.DataFrame
58+
Filtered version of the input dataframe.
59+
"""
60+
61+
df = traj.copy()
62+
63+
i = 0
64+
while True:
65+
if i == df.shape[0]-1:
66+
break
67+
deltat = (df["datetime"][i+1]-df["datetime"][i]).total_seconds()
68+
deltad = distance.haversine_dist(*tuple(df.iloc[i, [1, 2]]), *tuple(df.iloc[i+1, [1, 2]]))
69+
70+
if deltad < th_dist and deltat > th_time:
71+
df.drop([i+1], inplace=True)
72+
df.reset_index(drop=True, inplace=True)
73+
else:
74+
i += 1
75+
76+
return df
77+

pytrack/matching/matcher.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from . import mpmatching
2-
31
class Matcher:
4-
def __init__(self, G, trellis):
5-
self.G
6-
self.trellis
7-
8-
def match(self):
9-
path_prob, predecessor = mpmatching.viterbi_search(self.G_interp, self.trellis, "start", "target")
2+
""" Skeleton parent class to perform the matching operation.
3+
"""
4+
def __init__(self, G):
5+
self.G = G
106

11-
return results
7+
def match(self, points):
8+
pass

0 commit comments

Comments
 (0)