Skip to content

Instantly share code, notes, and snippets.

@joaofig
Last active January 7, 2024 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaofig/1219521593cca798d6445963d43edfb1 to your computer and use it in GitHub Desktop.
Save joaofig/1219521593cca798d6445963d43edfb1 to your computer and use it in GitHub Desktop.
Main loop for speed inference data preparation.
def main():
config = get_config(tile_extract='./valhalla/custom_files/valhalla_tiles.tar',
verbose=True)
trips = get_all_trips()
for traj_id, vehicle_id, trip_id in trips:
print(f"Vehicle {vehicle_id}, trip {trip_id}, trajectory: {traj_id}")
trip_df = get_trip_signals(vehicle_id, trip_id)
lat_array = trip_df["match_latitude"].values
lon_array = trip_df["match_longitude"].values
time_stamps = trip_df["time_stamp"].values
day_num = float(trip_df["day_num"].values[0])
trajectory = Trajectory(lat=lat_array, lon=lon_array, time=time_stamps)
try:
actor = Actor(config)
encoded_line = map_match(actor, list(zip(lon_array, lat_array)))
except RuntimeError as e:
print(e)
continue
polyline = np.array(decode_polyline(encoded_line, order="latlng"))
compound = CompoundTrajectory(trajectory, polyline[:,0], polyline[:,1])
converted = compound.to_trajectory()
segments = generate_segments(converted, day_num, traj_id)
if len(segments):
insert_segments(segments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment