Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index is out of bounds #13

Open
jks-liu opened this issue Jan 1, 2022 · 6 comments
Open

Index is out of bounds #13

jks-liu opened this issue Jan 1, 2022 · 6 comments

Comments

@jks-liu
Copy link

jks-liu commented Jan 1, 2022

import numpy as np
from noiseplanet.matcher.model.route import route_from_track, graph_from_track
from noiseplanet.matcher import matching
import pandas as pd

track = np.array([[22.268942156, 114.184837977],
[22.26886763, 114.184626828],
[22.26876443, 114.184181684],
[22.268763939, 114.184155534],
[22.268766766, 114.184134369],
[22.268774784, 114.184118914],
[22.268783376, 114.184106381],
[22.268798513, 114.184089471],
[22.26892887, 114.18396158],
[22.269265791, 114.183630446],
[22.269747789, 114.183162936],
[22.270157877, 114.182682855]])
graph = matching.model.graph_from_track(track)
track_coor, route_corr, edgeid, stats = matching.match(graph, track, method='hmm')

error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-b90d1030b8a8> in <module>
     17 [22.270157877, 114.182682855]])
     18 graph = matching.model.graph_from_track(track)
---> 19 track_coor, route_corr, edgeid, stats = matching.match(graph, track, method='hmm')

~/nb/p/py/noiseplanet/noiseplanet/matcher/matching.py in match(graph, track, method)
     61         track_corr, route_corr, edgeid, stats = model.match_nearest_edge(graph, track)
     62     elif method == 'hmm':
---> 63         track_corr, route_corr, edgeid, stats = model.match_leuven(graph, track)
     64     return track_corr, route_corr, edgeid, stats
     65 

~/nb/p/py/noiseplanet/noiseplanet/matcher/model/leuven.py in match_leuven(graph, track)
    123         lon_corr.append(lon)
    124 
--> 125         _, _, distance = geod.inv(track[idx][1], track[idx][0], lon, lat)
    126         proj_dist[idx] += distance
    127 

IndexError: index 12 is out of bounds for axis 0 with size 12

PS:
Origin issue is from user @1213314896

#11 (comment)

@jks-liu
Copy link
Author

jks-liu commented Jan 1, 2022

Root cause for this issue is: One GPS points will match more than one points in the road graph.

Some GPS points are too far, so that the road the belong to are not adjacent, so some points (road) are added on the fly to make match roads are all adjacent.

@Rajjat
Copy link

Rajjat commented Feb 6, 2022

I am facing the same issue. Did you find any solution?

@jks-liu
Copy link
Author

jks-liu commented Mar 3, 2022

I'll post a solution in few days.

@pimakshay
Copy link

This solution was published by the author @arthurdjn
By adding the two lines of code, the index out of bound issue can be solved. Please correct me if I am wrong!
++++++++++++++++++++++++++
Ok, I found the error. It seems it is a particular case of the map. The last GPS point is near two good candidates, thus they are both kept in leuven package which leads to an error in the indexing.

If you want to update the code to handle this specific case, you just need to add two extra lines at noiseplanet/matcher/model/leuven.py, line 121:

for idx, m in enumerate(lat_nodes):
+   if idx >= len(track):
+       break
    lat, lon = m.edge_m.pi[:2]
    lat_corr.append(lat)
    lon_corr.append(lon)

This is some crappy code and won't update the git repository, at least for now. I need to rearrange the whole project, but as it is old I don't have the courage to clean and update it.

@jks-liu
Copy link
Author

jks-liu commented Apr 19, 2022

@pimakshay The solution can walk around the "index out of bound" error. However the result turns out to be a little bit wrong. Result index are mismatched.

@lixian66670
Copy link

@jks-liu Hi,I am facing the same issue. Did you find any solution?Looking for your message!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants