-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_track_layout.py
76 lines (66 loc) · 2.24 KB
/
plot_track_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from argparse import ArgumentParser
import json
from pathlib import Path
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
def plot_track_layout(track_file: Path, output: Path | None = None):
if not track_file.exists():
raise FileNotFoundError(f"Error: {track_file} does not exist")
with open(track_file, "r") as file:
track = json.load(file)
df = pd.DataFrame(
{
"x": [
point[0]
for point in track["big_cones"]
+ track["blue_cones"]
+ track["yellow_cones"]
],
"y": [
point[1]
for point in track["big_cones"]
+ track["blue_cones"]
+ track["yellow_cones"]
],
"color": (
["orange"] * len(track["big_cones"])
+ ["blue"] * len(track["blue_cones"])
+ ["yellow"] * len(track["yellow_cones"])
),
}
)
fig = px.scatter(
df,
x="x",
y="y",
color="color",
color_discrete_map={"orange": "#FF7300", "blue": "#002FFF", "yellow": "#E6D600"},
size=[7] * len(df),
size_max=7,
template="plotly_dark"
)
fig.add_trace(
go.Scatter(
x=[point[0] for point in track["path"]],
y=[point[1] for point in track["path"]],
mode="lines",
line=dict(color="white", width=2),
)
)
fig.update_layout(yaxis_scaleanchor="x", xaxis_scaleanchor="y", showlegend=False, width=800, height=800)
if output:
if output.is_dir():
output = output / track_file.with_suffix(".png").name
fig.write_image(str(output))
print(f"Track layout saved to {output}")
else:
fig.show()
def main():
parser = ArgumentParser()
parser.add_argument("track_file", type=Path, help="Path to the track.json file")
parser.add_argument("-o", "--output", type=Path, help="Path to the output image file", default=None)
args = parser.parse_args()
plot_track_layout(args.track_file, output=args.output)
if __name__ == "__main__":
main()