Compare commits

..

3 Commits

Author SHA1 Message Date
Lukas Prause
b7e09741e1 Merge branch 'master' of ssh://git.black-mesa.xyz:434/langspielplatte/measurement-scripts 2023-06-26 12:26:46 +02:00
Lukas Prause
180f4dcc8a Refactor GPS scripts. 2023-06-21 14:35:07 +02:00
Lukas Prause
80f292767b Bufix: Exiting threads on error. 2023-06-21 14:21:06 +02:00
4 changed files with 77 additions and 51 deletions

View File

@@ -50,18 +50,8 @@ if __name__ == "__main__":
parser.add_argument("-f", "--gps_file", required=True, help="GPS csv file.")
parser.add_argument("-s", "--serial_file", required=True, help="Serial csv file.")
parser.add_argument("-p", "--pcap_csv_folder", required=True, help="PCAP csv folder.")
parser.add_argument("-a", "--column", required=True, help="Column to plot")
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, action="store_true", help="Only calculations without plotting.")
parser.add_argument(
"--show_providerinfo",
default=False,
help="Show providerinfo for map tiles an zoom levels.",
)
parser.add_argument(
"-c",
"--cores",
@@ -180,43 +170,6 @@ if __name__ == "__main__":
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')
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")
# zoom 17 is pretty
cx.add_basemap(ax2, source=cx.providers.OpenStreetMap.Mapnik, zoom=15)
# gdf.plot()
ax2.set_axis_off()
ax2.set_title(args.label if args.label else args.column)
if args.show_providerinfo:
#####################################
# Identifying how many tiles
latlon_outline = gdf.to_crs("epsg:4326").total_bounds
def_zoom = cx.tile._calculate_zoom(*latlon_outline)
print(f"Default Zoom level {def_zoom}")
cx.howmany(*latlon_outline, def_zoom, ll=True)
cx.howmany(*latlon_outline, def_zoom + 1, ll=True)
cx.howmany(*latlon_outline, def_zoom + 2, ll=True)
# Checking out some of the other providers and tiles
print(cx.providers.CartoDB.Voyager)
print(cx.providers.Stamen.TonerLite)
print(cx.providers.Stamen.keys())
#####################################
# df.plot(x="longitude", y="latitude", kind="scatter", colormap="YlOrRd")
if args.save:
plt.savefig("{}gps_plot.pdf".format(args.save))
else:
plt.show()
df_wm.to_csv("{}gps_plot.csv".format(args.save))
print("Saved calculations to: {}gps_plot.csv".format(args.save))

View File

@@ -188,7 +188,7 @@ def format_pcaps_to_csv(pcaps, dummy):
pcap_df = pcap_df.sort_values("arrival_time")
try:
# join tcp_trace data with pcap data
merge_srtt = False
merge_srtt = True
if merge_srtt:
tcp_trace_df = format_tcp_trace_to_csv(
pcap_number,
@@ -202,7 +202,7 @@ def format_pcaps_to_csv(pcaps, dummy):
pcap_number
)
)
break
continue ## break before but stoped the thread
merged_df = pd.merge_asof(
pcap_df.loc[pcap_df["src_ip"] != args.server],
tcp_trace_df,

73
plot_gps_csv.py Executable file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
import numpy as np
import pandas as pd
import geopandas as gpd
import contextily as cx
import matplotlib.pyplot as plt
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-f", "--file", required=True, help="Messfahrt csv")
parser.add_argument("-a", "--column", required=True, help="Column to plot")
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(
"--show_providerinfo",
default=False,
help="Show providerinfo for map tiles an zoom levels.",
)
args = parser.parse_args()
df = pd.read_csv(args.file)
gdf = gpd.GeoDataFrame(
df,
geometry=gpd.points_from_xy(df["longitude"], df["latitude"]),
crs="EPSG:4326",
)
gdf["srtt"] = gdf["srtt"].apply(lambda x: x / 10 ** 6)
gdf["is_retranmission"] = gdf["is_retranmission"].replace(True, np.NaN).dropna().astype(float)
print("Start plotting...")
df_wm = gdf.to_crs(epsg=3857)
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")
# zoom 17 is pretty
cx.add_basemap(ax2, source=cx.providers.OpenStreetMap.Mapnik, zoom=17)
# gdf.plot()
ax2.set_axis_off()
ax2.set_title(args.label if args.label else args.column)
if args.show_providerinfo:
#####################################
# Identifying how many tiles
latlon_outline = gdf.to_crs("epsg:4326").total_bounds
def_zoom = cx.tile._calculate_zoom(*latlon_outline)
print(f"Default Zoom level {def_zoom}")
cx.howmany(*latlon_outline, def_zoom, ll=True)
cx.howmany(*latlon_outline, def_zoom + 1, ll=True)
cx.howmany(*latlon_outline, def_zoom + 2, ll=True)
# Checking out some of the other providers and tiles
print(cx.providers.CartoDB.Voyager)
print(cx.providers.Stamen.TonerLite)
print(cx.providers.Stamen.keys())
#####################################
# df.plot(x="longitude", y="latitude", kind="scatter", colormap="YlOrRd")
if args.save:
plt.savefig("{}gps_plot.pdf".format(args.save))
else:
plt.show()

View File