Skip to content

Commit

Permalink
Merge pull request #2 from cosbidev/v2.0.3
Browse files Browse the repository at this point in the history
V2.0.3
  • Loading branch information
mtortora-ai committed Jul 9, 2022
2 parents 816a816 + 63d26c7 commit 351f610
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 14 deletions.
14 changes: 14 additions & 0 deletions docs/source/API/analytics.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
Analytics
========

visualization
-------------
.. automodule:: pytrack.analytics.visualization
:members:
:undoc-members:
:show-inheritance:
:inherited-members:

video
-------------
.. automodule:: pytrack.analytics.video
:members:
:undoc-members:

plugins
-------------
.. automodule:: pytrack.analytics.plugins
:members:
:undoc-members:
2 changes: 1 addition & 1 deletion docs/source/API/graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ utils
.. automodule:: pytrack.graph.utils
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/API/matching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ candidate
:members:
:undoc-members:

cleaning
-------------
.. automodule:: pytrack.matching.cleaning
:members:
:undoc-members:

matcher
-------------
.. automodule:: pytrack.matching.matcher
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
author = 'Matteo Tortora'

# The full version, including alpha/beta/rc tags
release = '1.0.3'
release = '2.0.3'

# -- General configuration ---------------------------------------------------

Expand Down
16 changes: 16 additions & 0 deletions pytrack/analytics/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Segmenter:
""" Skeleton parent class to perform the segmentation operation.
"""
def __init__(self):
pass

def processing(self, img):
""" It takes an input image and returns the processed image.
"""
pass

def run(self, img):
""" It takes an input image and returns the mask of the segmented image.
"""
pass
Empty file removed pytrack/analytics/segmentator.py
Empty file.
8 changes: 7 additions & 1 deletion pytrack/analytics/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import cv2
import requests

from pytrack.analytics import plugins

PREV_PAN_ID = None


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


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

if isinstance(model, plugins.Segmenter):
with open(os.path.join(folder_path, 'pic_seg.png'), 'wb') as file:
file.write(model.run(pic))

with open(os.path.join(folder_path, 'metadata.json'), 'w+') as out_file:
json.dump(meta, out_file)
2 changes: 1 addition & 1 deletion pytrack/graph/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def haversine_dist(lat1, lon1, lat2, lon2, earth_radius=EARTH_RADIUS_M):
Earth's radius
Returns
----------
dists: float
dist: float
Distance in units of earth_radius
"""
# convert decimal degrees to radians
Expand Down
77 changes: 77 additions & 0 deletions pytrack/matching/cleaning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from pytrack.graph import distance


def veldist_filter(traj, th_dist=5, th_vel=3):
""" It filters the GPS trajectory combining speed and distance between adjacent points.
If the adjacent point distance does not exceed the threshold and the speed is less than th_vel (m/s), the current
trajectory point is ignored.
Parameters
----------
traj: pandas.DataFrame
Dataframe containing 3 columns [timestamp, latitude, longitude].
th_dist: float, optional, default: 5 meters.
Threshold for the distance of adjacent points.
th_vel: float, optional, default: 3 m/s.
Threshold for the velocity.
Returns
-------
df: pandas.DataFrame
Filtered version of the input dataframe.
"""

df = traj.copy()

i = 0
while True:
if i == df.shape[0]-1:
break
deltat = (df["datetime"][i+1]-df["datetime"][i]).total_seconds()
dist = distance.haversine_dist(*tuple(df.iloc[i, [1, 2]]), *tuple(df.iloc[i+1, [1, 2]]))

if dist < th_dist and dist/deltat < th_vel:
df.drop([i+1], inplace=True)
df.reset_index(drop=True, inplace=True)
else:
i += 1

return df


def park_filter(traj, th_dist=50, th_time=30):
""" It removes parking behaviour by eliminating those points that remain in a certain area
for a given amount of time.
Parameters
----------
traj: pandas.DataFrame
Dataframe containing 3 columns [timestamp, latitude, longitude].
th_dist: float, optional, default: 50 meters.
Threshold for the distance of adjacent points.
th_time: float, optional, default: 30 min.
Threshold for the delta time.
Returns
-------
df: pandas.DataFrame
Filtered version of the input dataframe.
"""

df = traj.copy()

i = 0
while True:
if i == df.shape[0]-1:
break
deltat = (df["datetime"][i+1]-df["datetime"][i]).total_seconds()
deltad = distance.haversine_dist(*tuple(df.iloc[i, [1, 2]]), *tuple(df.iloc[i+1, [1, 2]]))

if deltad < th_dist and deltat > th_time:
df.drop([i+1], inplace=True)
df.reset_index(drop=True, inplace=True)
else:
i += 1

return df

15 changes: 6 additions & 9 deletions pytrack/matching/matcher.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from . import mpmatching

class Matcher:
def __init__(self, G, trellis):
self.G
self.trellis

def match(self):
path_prob, predecessor = mpmatching.viterbi_search(self.G_interp, self.trellis, "start", "target")
""" Skeleton parent class to perform the matching operation.
"""
def __init__(self, G):
self.G = G

return results
def match(self, points):
pass
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def reqs(*f):

setuptools.setup(
name='PyTrack-lib',
version='2.0.2',
version='2.0.3',
packages=setuptools.find_packages(),
# namespace_packages=['pytrack'],
url='https://github.com/cosbidev/PyTrack',
Expand Down

0 comments on commit 351f610

Please sign in to comment.