-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_showcase_figure.py
146 lines (137 loc) · 6.86 KB
/
example_showcase_figure.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import matplotlib.pyplot as plt
from utility.constants_experiments import *
from utility.constants import *
from trackers.all_trackers import *
from utility.visuals import plot_trajectory, show_plot, add_sensor, get_color_cycle, plot_tracker, \
plot_rectangular_state
from utility.data_generation import generate_data_for_seed
USE_FIXED_START = False
def visualize_set_of_trajectories(seed_list, tracker_names, delay=None, maintain_old_plot=False):
lidar_kwargs = OS1_EASY
trackers = {t: get_example_tracker(method_id=t,
lidar_kwargs=lidar_kwargs,
Q=PROCESS_NOISE_COVARIANCE_MATRIX,
use_UT=True,
tau=1,
v_init=20)
for t in tracker_names}
init_pose = FIX_INITIAL_POSE if USE_FIXED_START else INITIAL_RANGES
for seed in seed_list:
states, measurements, estimates = generate_data_for_seed(seed=seed,
trackers=trackers,
initial_ranges=init_pose,
n_steps_per_run=150,
process_noise_covariance=PROCESS_NOISE_COVARIANCE_MATRIX,
lidar_kwargs=lidar_kwargs)
colors = get_color_cycle()
if delay is None:
plot_trajectory(states,
measurements,
label="Ground Truth",
fill=True,
state_color="grey",
state_alpha=0.5,
meas_color='k',
meas_alpha=1,
mark_initial=False)
for i, tracker_id in enumerate(trackers.keys()):
plot_tracker(estimates[tracker_id],
fill=False,
state_color=colors[i % len(colors)],
state_alpha=1,
label=tracker_id)
add_sensor()
show_plot()
else:
for time_ix in range(len(states)):
if time_ix % VISUALIZE_EVERY_N_STEPS != 0:
continue
if not maintain_old_plot:
plt.cla()
x = states[time_ix]
Z = measurements[time_ix]
plot_rectangular_state(m=x[IXS_LOCATiON],
p=x[IXS_SHAPE],
fill=True,
label="Ground Truth" if not maintain_old_plot or time_ix == 0 else None,
color='grey',
alpha=0.5)
plt.scatter(*Z.T,
color='0.5',
alpha=1,
marker='.'
)
for tracker_ix, tracker_id in enumerate(trackers.keys()):
est = estimates[tracker_id][time_ix]
plot_rectangular_state(m=est[IXS_LOCATiON],
p=est[IXS_SHAPE],
fill=False,
label=tracker_id if not maintain_old_plot or time_ix == 0 else None,
color=colors[tracker_ix % len(colors)],
alpha=1)
plt.scatter(0, 0, marker='d', c='k',
label='Sensor' if not maintain_old_plot or time_ix == 0 else None)
plt.axis('equal')
plt.xlabel(r"$m_1$ / m")
plt.ylabel(r"$m_2$ / m")
plt.legend()
plt.tight_layout()
plt.draw()
plt.pause(delay)
plt.show()
def feldmann_comp(seed_list, tracker_names, step_ix_list=None):
plt.rcParams["font.size"] = 26
lidar_kwargs = OS1_EASY
trackers = {t: get_example_tracker(method_id=t,
lidar_kwargs=lidar_kwargs,
Q=PROCESS_NOISE_COVARIANCE_MATRIX,
use_UT=True,
tau=1,
v_init=20)
for t in tracker_names}
init_pose = INITIAL_RANGES
for seed in seed_list:
states, measurements, estimates = generate_data_for_seed(seed=seed,
trackers=trackers,
initial_ranges=init_pose,
n_steps_per_run=150,
process_noise_covariance=PROCESS_NOISE_COVARIANCE_MATRIX,
lidar_kwargs=lidar_kwargs)
print(f"Inital step: {np.around(states[0], 4)}")
if step_ix_list is not None:
if len(step_ix_list) > len(states):
print(f"Trying to access {len(step_ix_list)} steps, but only generated {len(states)}, "
f"using the first ones")
step_ix_list = step_ix_list[:len(states)]
states = np.array(states)[step_ix_list]
measurements = np.array(measurements, dtype=object)[step_ix_list]
for key in trackers.keys():
estimates[key] = np.array(estimates[key])[step_ix_list]
colors = get_color_cycle()
plot_trajectory(states,
measurements,
label="Ground Truth",
fill=True,
state_color="grey",
state_alpha=0.5,
meas_color='k',
meas_alpha=1,
mark_initial=False)
for i, tracker_id in enumerate(trackers.keys()):
plot_tracker(estimates[tracker_id],
fill=False,
state_color=colors[i % len(colors)],
state_alpha=1,
label=tracker_id)
plt.ylim(23, 50)
plt.gca().set_aspect('equal', adjustable='box')
# plt.axis('equal')
plt.xlabel(r"$m_1$ / m")
plt.ylabel(r"$m_2$ / m")
plt.legend()
plt.tight_layout()
plt.show()
if __name__ == '__main__':
plt.style.use(STYLE_SHEET)
feldmann_comp(seed_list=[500], tracker_names=["Feldmann", "Ours"],
step_ix_list=np.arange(-6 * VISUALIZE_EVERY_N_STEPS, 0)) # grab last 6 steps