Skip to content

Commit c611be8

Browse files
committed
feat: create combined tsv files for backward compatibility
Signed-off-by: Motsu-san <83898149+Motsu-san@users.noreply.github.com>
1 parent dfa0093 commit c611be8

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

localization/autoware_localization_evaluation_scripts/scripts/plot_diagnostics.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,83 @@ def main(rosbag_path: Path, save_dir: Path = None) -> None:
122122
float_format="%.9f",
123123
)
124124

125+
# Create combined TSV files for backward compatibility
126+
# Group diagnostic items by their common prefix (major category)
127+
category_groups = {}
128+
for key in data_dict.keys():
129+
parts = key.split(": ")
130+
if len(parts) >= 3: # Format: "category: subcategory: item"
131+
major_category = f"{parts[0]}: {parts[1]}"
132+
if major_category not in category_groups:
133+
category_groups[major_category] = []
134+
category_groups[major_category].append(key)
135+
136+
# Create combined TSV for each major category
137+
for major_category, diag_items in category_groups.items():
138+
if len(diag_items) <= 1:
139+
continue # Skip if only one item (no need to combine)
140+
141+
# Find the first available item to use as base for timestamps
142+
base_data = None
143+
for item in diag_items:
144+
if item in data_dict and data_dict[item]:
145+
base_data = data_dict[item]
146+
break
147+
148+
if not base_data:
149+
continue
150+
151+
combined_data = []
152+
153+
for base_entry in base_data:
154+
timestamp = base_entry["timestamp_header"]
155+
156+
# Start with base entry
157+
combined_entry = {
158+
"timestamp_header": timestamp,
159+
"timestamp_rosbag": base_entry["timestamp_rosbag"],
160+
}
161+
162+
# Add data from each diagnostic item in this category
163+
for diag_item in diag_items:
164+
if diag_item in data_dict:
165+
target_data = data_dict[diag_item]
166+
# Find closest timestamp match
167+
closest_entry = min(
168+
target_data,
169+
key=lambda x: abs(
170+
float(x["timestamp_header"]) - float(timestamp)
171+
),
172+
default=None,
173+
)
174+
if closest_entry:
175+
# Add all columns except timestamps
176+
for col_name, col_value in closest_entry.items():
177+
if col_name not in ["timestamp_header", "timestamp_rosbag"]:
178+
combined_entry[col_name] = col_value
179+
180+
combined_data.append(combined_entry)
181+
182+
# Save combined data as TSV
183+
if combined_data:
184+
df_combined = pd.DataFrame(combined_data)
185+
for col in df_combined.columns:
186+
if pd.api.types.is_numeric_dtype(df_combined[col]):
187+
df_combined[col] = df_combined[col].astype(float)
188+
df_combined[col] = df_combined[col].apply(
189+
lambda x: int(x) if x.is_integer() else x
190+
)
191+
192+
# Create filename from major category
193+
filename = diag_name_to_filename(major_category)
194+
df_combined.to_csv(
195+
save_dir / f"{filename}.tsv",
196+
index=False,
197+
sep="\t",
198+
float_format="%.9f",
199+
)
200+
print(f"Created combined TSV for backward compatibility: {major_category}")
201+
125202
# Fix timestamp to relative time from the first message and convert to seconds
126203
# (for better visualization)
127204
for one_data_dict_key in data_dict:

0 commit comments

Comments
 (0)