-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_xyth.py
198 lines (169 loc) · 6.95 KB
/
plot_xyth.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# python plot_xyth.py --path /workspace/data/landmark-distortion/final-results/2019-01-10-14-50-05 --num_samples 2000
import numpy as np
from pathlib import Path
import shutil
from argparse import ArgumentParser
import settings
import pdb
# from pyslam.metrics import TrajectoryMetrics
import pandas as pd
import csv
# from liegroups import SE3
def make_plot(params, gt_x_y_th, aux0_x_y_th, aux1_x_y_th):
figure_path = Path(params.path) / "figs_odometry"
output_path = Path(figure_path)
if output_path.exists() and output_path.is_dir():
shutil.rmtree(output_path)
output_path.mkdir(parents=True)
x0 = []
y0 = []
th0 = []
for sample in aux0_x_y_th:
x0.append(float(sample[0]))
y0.append(float(sample[1]))
th0.append(float(sample[2]))
x1 = []
y1 = []
th1 = []
for sample in aux1_x_y_th:
x1.append(float(sample[0]))
y1.append(float(sample[1]))
th1.append(float(sample[2]))
import matplotlib.pyplot as plt
plt.rc('text', usetex=False)
plt.rc('font', family='serif')
plt.figure(figsize=(9, 4))
start_idx = 0
plt.xlim(start_idx, start_idx + params.num_samples)
plt.grid()
m_size = 3
line_width = 0.3
mew = 0.5 # marker edge width
# plt.plot(np.array(gt_x_y_th[0]), '+-', color="black", linewidth=line_width, markersize=m_size, mew=mew,
# label="dx_GT")
plt.plot(np.array(gt_x_y_th[1]), 'x-', color="black", linewidth=line_width, markersize=m_size, mew=mew,
label="dy_GT")
plt.plot(np.array(gt_x_y_th[2]), '.-', color="black", linewidth=line_width, markersize=m_size, mew=mew,
fillstyle="none",
label="dth_GT")
# plt.plot(np.array(x0), '+-', color="tab:red", linewidth=line_width, markersize=m_size, mew=mew, label="dx_RO")
plt.plot(np.array(y0), 'x-', color="tab:red", linewidth=line_width, markersize=m_size, mew=mew, label="dy_RO")
plt.plot(np.array(th0), '.-', color="tab:red", linewidth=line_width, markersize=m_size, mew=mew, fillstyle="none",
label="dth_RO")
# plt.plot(np.array(x1), '+-', color="tab:blue", linewidth=line_width, markersize=m_size, mew=mew, label="dx_CC")
plt.plot(np.array(y1), 'x-', color="tab:blue", linewidth=line_width, markersize=m_size, mew=mew, label="dy_CC")
plt.plot(np.array(th1), '.-', color="tab:blue", linewidth=line_width, markersize=m_size, mew=mew, fillstyle="none",
label="dth_CC")
plt.title("Pose estimate performance for lateral and yaw motion")
plt.xlabel("Sample index")
plt.ylabel("m/sample, rad/sample")
plt.legend()
plt.tight_layout()
figure_path = "%s%s" % (output_path, "/xyth_comparison.pdf")
plt.savefig(figure_path)
plt.close()
print("Saved figure to:", figure_path)
def make_y_only_plot(params, gt_x_y_th, aux0_x_y_th, aux1_x_y_th):
figure_path = Path(params.path) / "figs_odometry"
output_path = Path(figure_path)
if output_path.exists() and output_path.is_dir():
shutil.rmtree(output_path)
output_path.mkdir(parents=True)
x0 = []
y0 = []
th0 = []
for sample in aux0_x_y_th:
x0.append(float(sample[0]))
y0.append(float(sample[1]))
th0.append(float(sample[2]))
x1 = []
y1 = []
th1 = []
for sample in aux1_x_y_th:
x1.append(float(sample[0]))
y1.append(float(sample[1]))
th1.append(float(sample[2]))
import matplotlib.pyplot as plt
font_size = 20
plt.rc('text', usetex=False)
plt.rc('font', family='serif')
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['ps.fonttype'] = 42
plt.figure(figsize=(18, 5))
start_idx = 0
plt.xlim(start_idx, start_idx + params.num_samples)
plt.xticks(fontsize=font_size)
plt.yticks(fontsize=font_size)
plt.grid()
m_size = 4
line_width = 0.4
mew = 0.5 # marker edge width
plt.plot(np.array(y0), 'o', color="tab:red", linewidth=line_width, markersize=m_size, mew=mew, label="RO")
plt.plot(np.array(y1), 'o', color="tab:blue", linewidth=line_width, markersize=m_size, mew=mew, label="CC-means")
plt.plot(np.array(gt_x_y_th[1]), '-', color="black", linewidth=1.5, markersize=m_size, mew=mew,
label="GT")
plt.title("Comparison of lateral motion estimates", fontsize=font_size)
plt.xlabel("Sample index", fontsize=font_size)
plt.ylabel("Displacement (m)", fontsize=font_size)
plt.legend(fontsize=font_size)
plt.tight_layout()
figure_path = "%s%s" % (output_path, "/xyth_comparison.pdf")
plt.savefig(figure_path)
plt.close()
print("Saved figure to:", figure_path)
def get_ground_truth_poses_from_csv(path_to_gt_csv):
"""
Load poses from csv for the Oxford radar robotcar 10k dataset.
"""
df = pd.read_csv(path_to_gt_csv)
# print(df.head())
x_vals = df['x']
y_vals = df['y']
th_vals = df['yaw']
timestamps = df['source_radar_timestamp']
x_y_th = [x_vals, y_vals, th_vals]
se3s = []
for i in range(len(df.index)):
th = th_vals[i]
pose = np.identity(4)
pose[0, 0] = np.cos(th)
pose[0, 1] = -np.sin(th)
pose[1, 0] = np.sin(th)
pose[1, 1] = np.cos(th)
pose[0, 3] = x_vals[i]
pose[1, 3] = y_vals[i]
se3s.append(pose)
return se3s, timestamps, x_y_th
def get_timestamps_and_x_y_th_from_csv(csv_file):
with open(csv_file, newline='') as f:
reader = csv.reader(f)
pose_data = list(reader)
timestamps = [int(item[0]) for item in pose_data]
x_y_th = [items[1:] for items in pose_data]
return timestamps, x_y_th
def get_timestamps_and_x_y_th_from_circular_motion_estimate_csv(csv_file):
with open(csv_file, newline='') as f:
reader = csv.reader(f)
pose_data = list(reader)
# timestamps = [int(item[0]) for item in pose_data]
timestamps = [int(0) for item in pose_data]
x_y_th = [items[3:] for items in pose_data]
return timestamps, x_y_th
def main():
parser = ArgumentParser(add_help=False)
parser.add_argument('--path', type=str, default="",
help='Path to folder where inputs are and where outputs will be saved')
parser.add_argument('--num_samples', type=int, default=1000,
help='Number of samples to process')
params = parser.parse_args()
print("Running script...")
gt_se3s, gt_timestamps, gt_x_y_th = get_ground_truth_poses_from_csv(
"/Users/roberto/data/ro-state-files/radar_oxford_10k/2019-01-10-14-50-05/radar_odometry.csv")
# gt_se3s = gt_se3s[settings.K_RADAR_INDEX_OFFSET:]
_, aux0_x_y_th = get_timestamps_and_x_y_th_from_csv(
"/Users/roberto/data/landmark-distortion/final-results/2019-01-10-14-50-05/full_matches_poses.csv")
_, aux1_x_y_th = get_timestamps_and_x_y_th_from_csv(
"/Users/roberto/data/landmark-distortion/final-results/2019-01-10-14-50-05/35-65-percentiles/cm_matches_poses.csv")
make_y_only_plot(params, gt_x_y_th, aux0_x_y_th, aux1_x_y_th)
if __name__ == "__main__":
main()