From 37412e4f96b1a1a0c2c45d7cb6fc14fe9789a533 Mon Sep 17 00:00:00 2001 From: Lukas Prause Date: Wed, 1 Feb 2023 14:48:48 +0100 Subject: [PATCH] Adds only calculation mode. --- plot_gps.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plot_gps.py b/plot_gps.py index 9e4e0f9..18d34a4 100755 --- a/plot_gps.py +++ b/plot_gps.py @@ -23,7 +23,8 @@ def csv_to_dataframe(csv_list, dummy): "{}{}".format(args.pcap_csv_folder, csv), dtype=dict(is_retranmission=bool, is_dup_ack=bool), ) - tmp_df["datetime"] = pd.to_datetime(tmp_df["datetime"]) - pd.Timedelta(hours=1) + #tmp_df["datetime"] = pd.to_datetime(tmp_df["datetime"]) - pd.Timedelta(hours=1) + tmp_df["datetime"] = pd.to_datetime(tmp_df["datetime"]) tmp_df = tmp_df.set_index("datetime") tmp_df.index = pd.to_datetime(tmp_df.index) if transmission_df is None: @@ -53,6 +54,8 @@ if __name__ == "__main__": parser.add_argument("-l", "--label", help="Label above the plot.") parser.add_argument("--no_legend", action="store_false", default=True, help="Do not show legend.") parser.add_argument("--save", default=None, help="Location to save pdf file.") + parser.add_argument("--time_offset", default=None, type=int, help="Minutes added to GPS datetime.") + parser.add_argument("--no_plot", default=False, type=bool, help="Only calculations without plotting.") parser.add_argument( "--show_providerinfo", @@ -138,6 +141,10 @@ if __name__ == "__main__": # load dataframe an put it into geopandas df = pd.read_csv(args.gps_file) df["kmh"] = df["speed (knots)"].apply(lambda x: x * 1.852) + if args.time_offset: + df["datetime"] = pd.to_datetime(df["datetime"]) + pd.Timedelta(minutes=args.time_offset) + else: + df["datetime"] = pd.to_datetime(df["datetime"]) df = df.set_index("datetime") df.index = pd.to_datetime(df.index) @@ -156,7 +163,8 @@ if __name__ == "__main__": # read serial csv serial_df = pd.read_csv(args.serial_file) - serial_df["datetime"] = pd.to_datetime(serial_df["datetime"]) - pd.Timedelta(hours=1) + #serial_df["datetime"] = pd.to_datetime(serial_df["datetime"]) - pd.Timedelta(hours=1) + serial_df["datetime"] = pd.to_datetime(serial_df["datetime"]) serial_df = serial_df.set_index("datetime") serial_df.index = pd.to_datetime(serial_df.index) @@ -168,14 +176,17 @@ if __name__ == "__main__": left_index=True, ) - print(gdf) - - print("Start plotting...") # format to needed format and add basemap as background df_wm = gdf.to_crs(epsg=3857) #df_wm.to_csv("debug-data.csv") # ax2 = df_wm.plot(figsize=(10, 10), alpha=0.5, edgecolor='k') - print(df_wm) + if args.no_plot: + df_wm.to_csv("{}gps_plot.csv".format(args.save)) + print("Saved calculations to: {}gps_plot.csv".format(args.save)) + exit(0) + + print("Start plotting...") + ax2 = df_wm.plot() ax2 = df_wm.plot(args.column, cmap="hot", legend=args.no_legend, ax=ax2) # ax2 = df_wm.plot.scatter(x="longitude", y="latitude", c="kmh", cmap="hot")