def analyze_drive(drive_name, drive_data): print("Processing " + drive_name + " With Columns: ") print(list(drive_data)) n_sec = 1 drive_data = drive_data.iloc[::n_sec, :] route = Route(latitudes=drive_data["Latitude"], longitudes=drive_data["Longitude"]) min_dist = 0.0001 indices = route.not_too_close_points_indices(min_dist=min_dist) drive_data = drive_data.iloc[indices, :] route = Route(latitudes=drive_data["Latitude"], longitudes=drive_data["Longitude"]) route_sector = route.get_sector() way_set = WaySet.download_all_ways(route_sector, tram_only=True, timestamp="2012-09-14T15:00:00") snapped_route = route.snap_points(way_set) latitudes, longitudes = Route.get_lat_lon_from_points(snapped_route.points) drive_data.insert(0, "Snapped_Lat", latitudes) drive_data.insert(0, "Snapped_Lon", longitudes) drive_data.insert(0, "Heading", snapped_route.headings) # Check length drive_data.to_csv("Results/%s.csv" % drive_name) wps = [{ "Time": row["Time"], "Lat": row["Snapped_Lat"], "Lon": row["Snapped_Lon"], "Heading": row["Heading"], "Value": row["1MinMean"] } for index, row in drive_data.iterrows()] with open("Results/%s.json" % drive_name, 'w') as outfile: json.dump(wps, outfile, indent=4, sort_keys=True) figure(num=None, figsize=(10, 10), dpi=80, facecolor='w', edgecolor='k') route.plot(style='or') snapped_route.plot() way_set.plot() #plt.show() plt.savefig("Results/" + drive_name + ".svg") plt.clf() hm_image = generate_heatmap(drive_data["Longitude"], drive_data["Latitude"], drive_data["1MinMean"], img_size=(200, 200)) hm_image = np.flip(hm_image.T, axis=0) matplotlib.image.imsave("Results/" + drive_name + "_HeatMap.png", hm_image, cmap='hot') figure(num=None, figsize=(10, 10), dpi=80, facecolor='w', edgecolor='k') plt.plot(np.array(drive_data["1MinMean"])) plt.savefig("Results/" + drive_name + "_DataProfile.png") plt.clf()