Upload automatum_data_full_highway_drone_dataset — Sample_Data, docs, examples, archive
9d62b12 verified | """ | |
| Traffic Density Heatmap — Automatum Data Full Highway Dataset | |
| Generates a 2D heatmap of all vehicle positions over time. | |
| Usage: | |
| python 02_heatmap_density.py <path_to_recording_folder> | |
| Example: | |
| python 02_heatmap_density.py ../hw-a9-denkendorf-001-d8087340-8287-46b6-9612-869b09e68448 | |
| Output: | |
| traffic_heatmap.png in the current directory | |
| """ | |
| import sys | |
| import os | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from openautomatumdronedata.dataset import droneDataset | |
| def generate_density_heatmap(dataset_path, output_filename="traffic_heatmap.png"): | |
| print(f"Loading dataset from: {dataset_path}") | |
| dataset = droneDataset(dataset_path) | |
| dynWorld = dataset.dynWorld | |
| print("Extracting position data...") | |
| all_x, all_y = [], [] | |
| for dynObj in dynWorld.dynamicObjects.values(): | |
| x_valid = [x for x in dynObj.x_vec if not np.isnan(x)] | |
| y_valid = [y for y in dynObj.y_vec if not np.isnan(y)] | |
| all_x.extend(x_valid) | |
| all_y.extend(y_valid) | |
| if not all_x: | |
| print("No position data found!") | |
| return | |
| print(f"Extracted {len(all_x)} data points. Creating heatmap...") | |
| plt.figure(figsize=(16, 6)) | |
| plt.style.use("dark_background") | |
| plt.hist2d(all_x, all_y, bins=(300, 100), cmap="inferno", cmin=1) | |
| plt.colorbar(label="Traffic density (data points)") | |
| plt.title("Highway Traffic Density Heatmap (Top-View)") | |
| plt.xlabel("X-Position [m]") | |
| plt.ylabel("Y-Position [m]") | |
| plt.gca().set_aspect("equal", adjustable="box") | |
| plt.tight_layout() | |
| plt.savefig(output_filename, dpi=300) | |
| print(f"Heatmap saved: {os.path.abspath(output_filename)}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 2: | |
| print("Usage: python 02_heatmap_density.py <path_to_recording_folder>") | |
| else: | |
| generate_density_heatmap(sys.argv[1]) | |