def simple_match(filename, **kwargs): max_distance = kwargs['max_distance'] if 'max_distance' in kwargs else DEFAULT_MAX_DISTANCE with open(filename, 'r') as f: data = read_gps_file(f, delimiter=',') points = zip(data['lat'], data['long']) matches = [] for i, point in enumerate(points): # Don't query the same point twice if i==0 or point != points[i-1]: point_merc, ways = query_ways_within_radius(point[0], point[1], max_distance) min_dist = sys.maxint min_way = None min_idx = None if ways: _add_segments(ways) _add_distances(ways, point_merc) for way in ways: if way['osm_id'] < 0: continue local_min_idx, local_min_dist = min(enumerate(way['distances']), key=lambda x: x[1]) if local_min_dist <= min_dist: min_dist = local_min_dist min_idx = local_min_idx min_way = way['osm_id'] point_dict = {'point_index': i, 'point': point_merc, 'way': min_way, 'index_of_segment': min_idx} matches.append(point_dict) return matches
def compute_emission_probabilities(observation, radius, n): #print(observation) lat, lon, course, speed = observation course = math.radians(-course+90) point, ways = query_ways_within_radius(lat, lon, radius) if ways is None or point is None: return ways = _add_segments(ways) ways = _add_distances(ways, point) ways = _add_tangents(ways) ways = _add_tangent_scores(ways, course) ways = _add_distance_scores(ways, GPS_SIGMA) ways = _add_emission_probabilities(ways) segments, probabilities = _get_top_n(ways, n) return segments, probabilities, point
def compute_emission_probabilities(observation, radius, n): #print(observation) lat, lon, course, speed = observation course = math.radians(-course + 90) point, ways = query_ways_within_radius(lat, lon, radius) if ways is None or point is None: return ways = _add_segments(ways) ways = _add_distances(ways, point) ways = _add_tangents(ways) ways = _add_tangent_scores(ways, course) ways = _add_distance_scores(ways, GPS_SIGMA) ways = _add_emission_probabilities(ways) segments, probabilities = _get_top_n(ways, n) return segments, probabilities, point
def simple_match(filename, **kwargs): max_distance = kwargs[ 'max_distance'] if 'max_distance' in kwargs else DEFAULT_MAX_DISTANCE with open(filename, 'r') as f: data = read_gps_file(f, delimiter=',') points = zip(data['lat'], data['long']) matches = [] for i, point in enumerate(points): # Don't query the same point twice if i == 0 or point != points[i - 1]: point_merc, ways = query_ways_within_radius( point[0], point[1], max_distance) min_dist = sys.maxint min_way = None min_idx = None if ways: _add_segments(ways) _add_distances(ways, point_merc) for way in ways: if way['osm_id'] < 0: continue local_min_idx, local_min_dist = min(enumerate( way['distances']), key=lambda x: x[1]) if local_min_dist <= min_dist: min_dist = local_min_dist min_idx = local_min_idx min_way = way['osm_id'] point_dict = { 'point_index': i, 'point': point_merc, 'way': min_way, 'index_of_segment': min_idx } matches.append(point_dict) return matches