cosbidev / pytrack Goto Github PK
View Code? Open in Web Editor NEWa Map-Matching-based Python Toolbox for Vehicle Trajectory Reconstruction
Home Page: https://pytrack-lib.readthedocs.io/en/latest/#
License: BSD 3-Clause Clear License
a Map-Matching-based Python Toolbox for Vehicle Trajectory Reconstruction
Home Page: https://pytrack-lib.readthedocs.io/en/latest/#
License: BSD 3-Clause Clear License
If points include matched points and unmatched points. How can I get matched points?
Thank you very much.
I've been using the PyTrack
package for map matching and encountered an issue when visualizing the results using the draw_path
function. Some of the plotted lines are not aligned with the roads, leading to a visually inaccurate representation.
The plotted path should align accurately with the roads on the map, reflecting the correct map-matched result.
Some lines are plotted off the roads, suggesting an issue with either the map matching or the visualization.
I hope this can be addressed soon, and I'd appreciate any guidance or workarounds in the meantime. Thank you for your hard work on this package!
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of PyTrack.
I have confirmed this bug exists on the main branch of PyTrack.
First of all, thank you for your project. It seems very helpful!
I'm having an issue running pytrack for a track that starts on a well connected road and ends up in a parking lot. It's making the pytrack crash with an error shown below.
The predecessor list ends up missing the "target" here. I'm not sure, but I think it is caused by the track ending up on a parking lot driveway that PyTrack treats as unreachable from the main road the track starts at. This is caused by the parking lot having a osm highway with a tag "service:driveway" which is only connected to the street with a highway of "service:parking_aisle". Parking aisle is filtered out with network_type="drive" while driveway is not.
Here's a picture to show the issue better, red arrow shows the direction of the track:
import numpy as np
from pytrack.graph import graph, distance
from pytrack.matching import candidate, mpmatching_utils, mpmatching
coords = [
(61.464851, 23.72293),
(61.464935, 23.721074),
(61.465018, 23.719238),
(61.464761, 23.718313),
(61.46429, 23.7183)]
north, east = np.max(np.array([*coords]), 0)
south, west = np.min(np.array([*coords]), 0)
G = graph.graph_from_bbox(*distance.enlarge_bbox(north, south, west, east, 500), simplify=True, network_type='drive')
G_interp, candidates = candidate.get_candidates(G, coords, interp_dist=10, closest=True, radius=30)
trellis = mpmatching_utils.create_trellis(candidates)
path_prob, predecessor = mpmatching.viterbi_search(G_interp, trellis, "start", "target")
... (Cut out many of similar lines)
Node 1004937441 not reachable from 1279650117
Node 1004937441 not reachable from 1229986873
Node 1004937441 not reachable from 1242556796
Node 1004937441 not reachable from 1212946680
Node 1004937441 not reachable from 1085933389
Traceback (most recent call last):
File "example.py", line 21, in <module>
path_prob, predecessor = mpmatching.viterbi_search(G_interp, trellis, "start", "target")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mpmatching.py", line 82, in viterbi_search
predecessor = mpmatching_utils.get_predecessor("target", predecessor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mpmatching_utils.py", line 191, in get_predecessor
pred = predecessor[target]
~~~~~~~~~~~^^^^^^^^
KeyError: 'target'
Python 3.11.5
PyTrack 2.0.6
No response
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of PyTrack.
I have confirmed this bug exists on the main branch of PyTrack.
I'm using Pycharm 2022.2. (Community Edition) under Ubuntu. The latest Pytrack-lib version 2.0.4.
By running:
G_interp, candidates = candidate.get_candidates(G, points, interp_dist=5, closest=True, radius=5)
I got the following error:
Traceback (most recent call last):
File "/home/PycharmProjects/pythonProject/20221011_AMT_MAP.py", line 196, in
G_interp, candidates = candidate.get_candidates(G, points, interp_dist=5, closest=True, radius=5)
File "/home/pww3/lib/python3.8/site-packages/pytrack/matching/candidate.py", line 66, in get_candidates
G = distance.interpolate_graph(G, dist=interp_dist)
File "/home/pww3/lib/python3.8/site-packages/pytrack/graph/distance.py", line 155, in interpolate_graph
geom = data["geometry"]
KeyError: 'geometry'
The values of G and points are correct:
G:
MultiDiGraph with 195 nodes and 300 edges
points:
[(41.391026049285344, 2.163678830146503), (41.391070215189984, 2.163620451465465), (41.39111036090477, 2.1635620742324218), (41.39115406618348, 2.16350370222313), (41.39119705576544, 2.1634453332919166), (41.39123736983398, 2.163386966093803), (41.39127868897586, 2.163328602793066), (41.39132019968665, 2.163270241336454), (41.391358679200195, 2.1632118830298586), (41.39140113607066, 2.16315352787142)]
Mention that in Colab, it worked correctly.
G_interp, candidates = candidate.get_candidates(G, points, interp_dist=5, closest=True, radius=5)
G:
MultiDiGraph with 195 nodes and 300 edges
points:
[(41.391026049285344, 2.163678830146503), (41.391070215189984, 2.163620451465465), (41.39111036090477, 2.1635620742324218), (41.39115406618348, 2.16350370222313), (41.39119705576544, 2.1634453332919166), (41.39123736983398, 2.163386966093803), (41.39127868897586, 2.163328602793066), (41.39132019968665, 2.163270241336454), (41.391358679200195, 2.1632118830298586), (41.39140113607066, 2.16315352787142)]
KeyError: 'geometry'
2.0.4 / 3.8
No response
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of PyTrack.
I have confirmed this bug exists on the main branch of PyTrack.
I had an error when installing PyTrack by pip.
pip install PyTrack-lib
Collecting PyTrack-lib
Downloading PyTrack_lib-2.0.8-py3-none-any.whl.metadata (5.5 kB)
Collecting numpy~=1.23.2 (from PyTrack-lib)
Downloading numpy-1.23.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.3 kB)
Collecting pandas~=1.4.4 (from PyTrack-lib)
Downloading pandas-1.4.4.tar.gz (4.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.9/4.9 MB 61.9 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting networkx~=2.8.6 (from PyTrack-lib)
Downloading networkx-2.8.8-py3-none-any.whl.metadata (5.1 kB)
Collecting shapely~=1.8.4 (from PyTrack-lib)
Downloading Shapely-1.8.5.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (43 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.1/43.1 kB 4.7 MB/s eta 0:00:00
Collecting pyproj~=3.3.1 (from PyTrack-lib)
Downloading pyproj-3.3.1.tar.gz (219 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 219.1/219.1 kB 22.5 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [2 lines of output]
<string>:9: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
ERROR: Minimum supported PROJ version is 8.0.0, installed version is 5.2.0. For more information see: https://pyproj4.github.io/pyproj/stable/installation.html
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Python 3.11.4
PyTrack_lib-2.0.8-py3-none-any.whl
No response
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of PyTrack.
I have confirmed this bug exists on the main branch of PyTrack.
I am trying to check the sample as appearing in the documentation. for finding the path as it should be induced on OSM nodes.
I am using the following data :
all_points = [(42.343981, -83.068282),(42.344557, -83.06855),(42.345158, -83.068826),(42.345739, -83.069091),(42.346302, -83.069342),(42.346882, -83.06961),(42.347475, -83.069879),(42.348061, -83.070143),
(42.348634, -83.070406),(42.349217, -83.070679),(42.349808, -83.070997),(42.35039, -83.071336),(42.350993, -83.071686),(42.351586, -83.072038),(42.352192, -83.072393),(42.352813, -83.072754),(42.35344, -83.073121),
(42.354081, -83.073484),(42.354718, -83.073834),(42.355347, -83.07416),(42.355961, -83.074406),(42.356566, -83.074608),(42.357158, -83.074775),(42.357734, -83.074922),(42.358335, -83.074962),(42.358951, -83.07485),
(42.359548, -83.074571),(42.360128, -83.074126),(42.360585, -83.07362),(42.360991, -83.073111),(42.361731, -83.072093),(42.362051, -83.071603),(42.362373, -83.07109),(42.362699, -83.070568),(42.363038, -83.069994),
(42.363382, -83.069346),(42.363716, -83.068678),(42.364031, -83.068009),(42.364324, -83.067383),(42.364612, -83.066773),(42.364906, -83.066133),(42.365196, -83.065498),(42.365482, -83.064841),(42.365752, -83.064162),
(42.365985, -83.063562), (42.366205, -83.062984),(42.36638, -83.062431),(42.366498, -83.06189),(42.366559, -83.061304),(42.36657, -83.060721),(42.366535, -83.060186),(42.366487, -83.059704),(42.366442, -83.059258),
(42.366413, -83.05882),(42.366457, -83.058362),(42.366611, -83.057939),(42.366845, -83.057612),(42.367143, -83.057395),(42.367517, -83.057308),(42.367924, -83.057414),(42.368374, -83.057617),(42.368884, -83.057858),
(42.369424, -83.058138),(42.369975, -83.058455),(42.370521, -83.058753),(42.371084, -83.058982),(42.37172, -83.059162),(42.372423, -83.059326),(42.373146, -83.059485),(42.373877, -83.059694),(42.37461, -83.06005),
(42.375353, -83.06052),(42.376113, -83.061019),(42.376876, -83.061525),(42.37761, -83.062009),(42.378308, -83.062475),(42.378983, -83.062909),(42.379634, -83.063329),(42.380269, -83.063755),(42.380912, -83.064185),
(42.381564, -83.064626),(42.382227, -83.065073),(42.382888, -83.065521),(42.383551, -83.065964),(42.384226, -83.066415),(42.384914, -83.066879),(42.385623, -83.067359),(42.386344, -83.067846),(42.387071, -83.068332),
(42.387795, -83.068802),(42.388511, -83.069236)]
After getting candidates , I am getting some problems -
[1] The code itself throws many errors, on which I've no control, as it seems, some of them like math domain error, are quite an issue. This should be checked.
[2] For using the closest=True, after all if "finds" some path, which is not the correct one, as there is a jump between a highway, and another highway with different altitude.
[3] Using closest=False, results in no path found, which is something that I cannot comprehend at all. The idea is that giving more candidates at the first stage should results in more possible options, but certainly no diminish into a situation where "no solution is found".
This is the code :
after this calling the trellis and viterbi search, as in the sample, will result in the errors I am talking about.
note that in order to see the other problems one would need to set in the above to "closest=False"
# Import libraries
import numpy as np
import pandas as pd
from pytrack.graph import graph, distance
from pytrack.analytics import visualization
from pytrack.matching import candidate, mpmatching_utils, mpmatching
# insert the "all_points" from the above explanation
#df = pd.read_excel("dataset.xlsx")
latitude, longitude = zip(*all_points)
#latitude = df["latitude"].to_list()
#longitude = df["longitude"].to_list()
points = [(lat, lon) for lat, lon in zip(latitude[:30], longitude[:30])]
# Create BBOX
north, east = np.max(np.array([*points]), 0)
south, west = np.min(np.array([*points]), 0)
# Extract road graph
G = graph.graph_from_bbox(*distance.enlarge_bbox(north, south, west, east, 500), simplify=True, network_type='drive')
# Extract candidates
G_interp, candidates = candidate.get_candidates(G, points, interp_dist=5, closest=True, radius=10)
can run to see that
last version
nothing to add
Using the GPS trajectory as points=[(42.343981, -83.068282), (42.344557, -83.06855), (42.345158, -83.068826), (42.345739, -83.069091), (42.346302, -83.069342), (42.346882, -83.06961), (42.347475, -83.069879), (42.348061, -83.070143), (42.348634, -83.070406), (42.349217, -83.070679), (42.349808, -83.070997), (42.35039, -83.071336), (42.350993, -83.071686), (42.351586, -83.072038), (42.352192, -83.072393), (42.352813, -83.072754), (42.35344, -83.073121), (42.354081, -83.073484), (42.354718, -83.073834), (42.355347, -83.07416), (42.355961, -83.074406), (42.356566, -83.074608), (42.357158, -83.074775), (42.357734, -83.074922), (42.358335, -83.074962), (42.358951, -83.07485), (42.359548, -83.074571), (42.360128, -83.074126), (42.360585, -83.07362), (42.360991, -83.073111), (42.361731, -83.072093), (42.362051, -83.071603), (42.362373, -83.07109), (42.362699, -83.070568), (42.363038, -83.069994), (42.363382, -83.069346), (42.363716, -83.068678), (42.364031, -83.068009), (42.364324, -83.067383), (42.364612, -83.066773), (42.364906, -83.066133), (42.365196, -83.065498), (42.365482, -83.064841), (42.365752, -83.064162), (42.365985, -83.063562), (42.366205, -83.062984), (42.36638, -83.062431), (42.366498, -83.06189), (42.366559, -83.061304), (42.36657, -83.060721), (42.366535, -83.060186), (42.366487, -83.059704), (42.366442, -83.059258), (42.366413, -83.05882), (42.366457, -83.058362), (42.366611, -83.057939), (42.366845, -83.057612), (42.367143, -83.057395), (42.367517, -83.057308), (42.367924, -83.057414), (42.368374, -83.057617), (42.368884, -83.057858), (42.369424, -83.058138), (42.369975, -83.058455), (42.370521, -83.058753), (42.371084, -83.058982), (42.37172, -83.059162), (42.372423, -83.059326), (42.373146, -83.059485), (42.373877, -83.059694), (42.37461, -83.06005), (42.375353, -83.06052), (42.376113, -83.061019), (42.376876, -83.061525), (42.37761, -83.062009), (42.378308, -83.062475), (42.378983, -83.062909), (42.379634, -83.063329), (42.380269, -83.063755), (42.380912, -83.064185), (42.381564, -83.064626), (42.382227, -83.065073), (42.382888, -83.065521), (42.383551, -83.065964), (42.384226, -83.066415), (42.384914, -83.066879), (42.385623, -83.067359), (42.386344, -83.067846), (42.387071, -83.068332), (42.387795, -83.068802), (42.388511, -83.069236)]
But this time taking a map as (since I wish to check for several trajectories in this area) :
north = 42.534092
south = 42.118413
west = -83.343126
east = -82.727472
downloaded_g = graph.download.osm_download((north,south,west,east), network_type='drive')
G = graph.create_graph(downloaded_g)
start = datetime.datetime.now()
G_interp, candidates = candidate.get_candidates(G, points, interp_dist=5, closest=True, radius=10)
p1 = datetime.datetime.now()
trellis = mpmatching_utils.create_trellis(candidates)
path_prob, predecessor = mpmatching.viterbi_search(G_interp, trellis, "start", "target")
p2 = datetime.datetime.now()
l_ids, l_coords = mpmatching_utils.create_matched_path(G_interp, trellis, predecessor)
print('Got results : ',len(points),',',len(l_ids),',',len(l_coords),' times : ',int((p1-start).total_seconds()*1000),';',int((p2-p1).total_seconds()*1000))
The get_candidates never returns till some memory error inside this function, but it takes more than an hour to reach there.
Haven't analyzed the code so far, but it seems like there is no "smart" search for candidates, but passing over the whole graph edge by edge.
If you can please tell me what is wrong there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.