Sfoglia il codice sorgente

修改画图部分的图例名称

XGJ_zhaoyuan 3 giorni fa
parent
commit
c3dc03d6ca

+ 56 - 38
modules/lib/chart_generator.py

@@ -71,6 +71,7 @@ scenario_sign_dict 场景签名字典(简化实现)
 import os
 import numpy as np
 import pandas as pd
+import matplotlib.pyplot as plt
 
 from typing import Optional, Dict, List, Any, Union
 from pathlib import Path
@@ -953,7 +954,7 @@ def generate_limit_speed_chart(function_calculator, output_dir: str) -> Optional
         df_csv = pd.DataFrame({
             'simTime': ego_df['simTime'],
             'speed': ego_df['v'],
-            'speed_limit': ego_df.get('speed_limit', pd.Series([max_threshold] * len(ego_df)))
+            'max_threshold': ego_df.get('speed_limit', pd.Series([max_threshold] * len(ego_df)))
         })
         df_csv.to_csv(csv_filename, index=False)
         logger.info(f"{metric_name} data saved to: {csv_filename}")
@@ -966,7 +967,7 @@ def generate_limit_speed_chart(function_calculator, output_dir: str) -> Optional
 
         # # Plot speed
         # plt.plot(df['simTime'], df['speed'], 'b-', label='Vehicle Speed')
-        # plt.plot(df['simTime'], df['speed_limit'], 'r--', label='Speed Limit')
+        # plt.plot(df['simTime'], df['max_threshold'], 'r--', label='Max Threshold')
 
         # # Set y-axis range
         # plt.ylim(bottom=0, top=max(max_threshold * 1.1, df['speed'].max() * 1.1))
@@ -1028,7 +1029,7 @@ def generate_limit_speed_past_sign_chart(function_calculator, output_dir: str) -
         df_csv = pd.DataFrame({
             'simTime': ego_df['simTime'],
             'speed': ego_df['v'],
-            'speed_limit': ego_df.get('speed_limit', pd.Series([max_threshold] * len(ego_df))),
+            'max_threshold': ego_df.get('speed_limit', pd.Series([max_threshold] * len(ego_df))),
             'sign_pass_time': sign_time
         })
         df_csv.to_csv(csv_filename, index=False)
@@ -1043,7 +1044,7 @@ def generate_limit_speed_past_sign_chart(function_calculator, output_dir: str) -
 
         # # Plot speed
         # plt.plot(df['simTime'], df['speed'], 'b-', label='Vehicle Speed')
-        # plt.plot(df['simTime'], df['speed_limit'], 'r--', label='Speed Limit')
+        # plt.plot(df['simTime'], df['max_threshold'], 'r--', label='Max Speed')
 
         # # Mark sign passing time
         # plt.axvline(x=sign_time, color='g', linestyle='--', label='Speed Limit Sign')
@@ -1525,8 +1526,8 @@ def generate_cadence_chart(comfort_calculator, output_dir: str) -> Optional[str]
             'simTime': df['simTime'],
             'lon_acc': df['lon_acc'],
             'v': df['v'],
-            'ip_acc': df.get('ip_acc', pd.Series([None] * len(df))),
-            'ip_dec': df.get('ip_dec', pd.Series([None] * len(df)))
+            'max_threshold': df.get('ip_acc', pd.Series([None] * len(df))),
+            'min_threshold': df.get('ip_dec', pd.Series([None] * len(df)))
         })
         df_csv.to_csv(csv_filename, index=False)
         logger.info(f"Cadence data saved to: {csv_filename}")
@@ -1541,9 +1542,9 @@ def generate_cadence_chart(comfort_calculator, output_dir: str) -> Optional[str]
         # # 图 1:纵向加速度
         # ax1 = plt.subplot(2, 1, 1)
         # ax1.plot(df['simTime'], df['lon_acc'], 'b-', label='Longitudinal Acceleration')
-        # if 'ip_acc' in df.columns and 'ip_dec' in df.columns:
-        #     ax1.plot(df['simTime'], df['ip_acc'], 'r--', label='Acceleration Threshold')
-        #     ax1.plot(df['simTime'], df['ip_dec'], 'g--', label='Deceleration Threshold')
+        # if 'max_threshold' in df.columns and 'min_threshold' in df.columns:
+        #     ax1.plot(df['simTime'], df['max_threshold'], 'r--', label='Max Threshold')
+        #     ax1.plot(df['simTime'], df['min_threshold'], 'g--', label='Min Threshold')
 
         # # 添加橙色背景标识顿挫事件
         # for idx, event in cadence_events.iterrows():
@@ -1617,41 +1618,58 @@ def generate_slam_brake_chart(comfort_calculator, output_dir: str) -> Optional[s
         df_csv = pd.DataFrame({
             'simTime': df['simTime'],
             'lon_acc': df['lon_acc'],
+            'lon_acc_diff': df['lon_acc_diff'],
             'v': df['v'],
             'min_threshold': df.get('ip_dec', pd.Series([None] * len(df))),
             'max_threshold': 0.0
         })
         df_csv.to_csv(csv_filename, index=False)
         logger.info(f"Slam brake data saved to: {csv_filename}")
-        return csv_filename
+        # return csv_filename
 
         # # 第二步:从 CSV 读取(可验证保存数据无误)
-        # df = pd.read_csv(csv_filename)
+        df = pd.read_csv(csv_filename)
 
         # # 创建图表(第三步)
-        # plt.figure(figsize=(12, 8), constrained_layout=True)
+        plt.figure(figsize=(12, 8), constrained_layout=True)
 
         # # 图 1:纵向加速度
-        # ax1 = plt.subplot(2, 1, 1)
-        # ax1.plot(df['simTime'], df['lon_acc'], 'b-', label='Longitudinal Acceleration')
-        # if 'min_threshold' in df.columns:
-        #     ax1.plot(df['simTime'], df['min_threshold'], 'r--', label='Deceleration Threshold')
+        ax1 = plt.subplot(3, 1, 1)
+        ax1.plot(df['simTime'], df['lon_acc'], 'b-', label='Longitudinal Acceleration')
+        if 'min_threshold' in df.columns:
+            ax1.plot(df['simTime'], df['min_threshold'], 'r--', label='Min Threshold')
 
         # # 添加橙色背景标识急刹车事件
-        # for idx, event in slam_brake_events.iterrows():
-        #     label = 'Slam Brake Event' if idx == 0 else None
-        #     ax1.axvspan(event['start_time'], event['end_time'],
-        #                 alpha=0.3, color='orange', label=label)
+        for idx, event in slam_brake_events.iterrows():
+            label = 'Slam Brake Event' if idx == 0 else None
+            ax1.axvspan(event['start_time'], event['end_time'],
+                        alpha=0.3, color='orange', label=label)
 
-        # ax1.set_xlabel('Time (s)')
-        # ax1.set_ylabel('Longitudinal Acceleration (m/s²)')
-        # ax1.set_title('Slam Brake Event Detection - Longitudinal Acceleration')
-        # ax1.grid(True)
-        # ax1.legend()
+        ax1.set_xlabel('Time (s)')
+        ax1.set_ylabel('Longitudinal Acceleration (m/s²)')
+        ax1.set_title('Slam Brake Event Detection - Longitudinal Acceleration')
+        ax1.grid(True)
+        ax1.legend()
 
         # # 图 2:速度
-        # ax2 = plt.subplot(2, 1, 2)
-        # ax2.plot(df['simTime'], df['v'], 'g-', label='Velocity')
+        ax2 = plt.subplot(3, 1, 2)
+        ax2.plot(df['simTime'], df['v'], 'g-', label='Velocity')
+
+        # # 添加橙色背景标识急刹车事件
+        for idx, event in slam_brake_events.iterrows():
+            label = 'Slam Brake Event' if idx == 0 else None
+            ax2.axvspan(event['start_time'], event['end_time'],
+                        alpha=0.3, color='orange', label=label)
+
+        ax2.set_xlabel('Time (s)')
+        ax2.set_ylabel('Velocity (m/s)')
+        ax2.set_title('Slam Brake Event Detection - Vehicle Speed')
+        ax2.grid(True)
+        ax2.legend()
+
+        # # 图 3:加速度变化率
+        ax3 = plt.subplot(3, 1, 3)
+        ax3.plot(df['simTime'], df['lon_acc_diff'], 'r-', label='lon_acc_diff')
 
         # # 添加橙色背景标识急刹车事件
         # for idx, event in slam_brake_events.iterrows():
@@ -1659,19 +1677,19 @@ def generate_slam_brake_chart(comfort_calculator, output_dir: str) -> Optional[s
         #     ax2.axvspan(event['start_time'], event['end_time'],
         #                 alpha=0.3, color='orange', label=label)
 
-        # ax2.set_xlabel('Time (s)')
-        # ax2.set_ylabel('Velocity (m/s)')
-        # ax2.set_title('Slam Brake Event Detection - Vehicle Speed')
-        # ax2.grid(True)
-        # ax2.legend()
+        ax3.set_xlabel('Time (s)')
+        ax3.set_ylabel('lon_acc_diff (m/s^3)')
+        ax3.set_title('Slam Brake Event Detection - Longitudinal Acceleration Difference')
+        ax3.grid(True)
+        ax3.legend()
 
         # # 保存图像
-        # chart_filename = os.path.join(output_dir, f"slam_brake_chart.png")
-        # plt.savefig(chart_filename, dpi=300)
-        # plt.close()
+        chart_filename = os.path.join(output_dir, f"slam_brake_chart.png")
+        plt.savefig(chart_filename, dpi=300)
+        plt.close()
 
-        # logger.info(f"Slam brake chart saved to: {chart_filename}")
-        # return chart_filename
+        logger.info(f"Slam brake chart saved to: {chart_filename}")
+        return chart_filename
 
     except Exception as e:
         logger.error(f"Failed to generate slam brake chart: {str(e)}", exc_info=True)
@@ -1734,7 +1752,7 @@ def generate_slam_accelerate_chart(comfort_calculator, output_dir: str) -> Optio
 
         # # 添加加速度阈值线
         # if 'max_threshold' in df.columns and not df['max_threshold'].isnull().all():
-        #     ax1.plot(df['simTime'], df['max_threshold'], 'r--', label='Acceleration Threshold')
+        #     ax1.plot(df['simTime'], df['max_threshold'], 'r--', label='Max Threshold')
 
         # # 添加橙色背景标识急加速事件
         # for idx, event in slam_accel_events.iterrows():

+ 1 - 1
modules/metric/comfort.py

@@ -149,7 +149,7 @@ COMFORT_INFO = [
     "acc_z_vehicle",  # 车辆坐标系下的垂向加速度
     "lon_v_vehicle",  # 车辆坐标系下的纵向速度
     "lat_v_vehicle",  # 车辆坐标系下的横向速度
-    "vel_z_vehicle"  # 车辆坐标系下的垂向速度
+    "vel_z_vehicle",  # 车辆坐标系下的垂向速度
 ]
 
 

+ 2 - 1
modules/metric/function.py

@@ -1121,7 +1121,7 @@ def launchTimeinTrafficLight_PGVIL(data, plot_path):
     if car_move_times.empty:
         return {"timeInterval_PGVIL": -1}
 
-    time_move = move_times.iloc[0]
+    time_move = car_move_times.iloc[0]
     return {"timeInterval_PGVIL": time_move - time_red2green}
 
 
@@ -1145,6 +1145,7 @@ def noStop_PGVIL(data, plot_path):
     exclude_end_seconds = 5.0
     exclude_start_seconds = 5.0
     ego_df = data.ego_data
+    min_sim_time = ego_df["simTime"].min()
     max_sim_time = ego_df["simTime"].max()
 
     start_threshold = min_sim_time + exclude_start_seconds

+ 9 - 4
scripts/evaluator_enhanced.py

@@ -665,7 +665,10 @@ def main():
         # default=r"D:\Cicv\招远\V2V_CSAE53-2020_ForwardCollision_LST_01-02_new",
         # default=r"D:\Cicv\招远\AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_01",
         # default=r"/home/server/桌面/XGJ/zhaoyuan_DataPreProcess/output/AD_GBT41798-2022_TrafficSignalRecognitionAndResponse_LST_02",
-        default=r"/home/server/桌面/XGJ/zhaoyuan_DataPreProcess/output/V2I_CSAE53-2020_LeftTurnAssist_PGVIL_demo",
+        # default=r"/home/server/桌面/XGJ/zhaoyuan_DataPreProcess/output/V2I_CSAE53-2020_LeftTurnAssist_PGVIL_demo",
+        # default=r"D:\Cicv\招远\delivery_car_data\V2I_CSAE53-2020_HazardousLocationW_LST_02",
+        # default=r"D:\Cicv\招远\PGVILdata\AD_GBT41798-2022_AutoEmergencyEvacuation_PGVL_05", # 紧急避险未通过
+        default=r"D:\Cicv\招远\PGVILdata\AD_GBT41798-2022_RoadTraInfraObstRR_PGVL_25", # 急刹
         help="Input data directory",
     )
 
@@ -674,13 +677,15 @@ def main():
     config_group.add_argument(
         "--allConfigPath",
         type=str,
-        default=r"/home/server/anaconda3/envs/vitual_XGJ/zhaoyuan_0617/zhaoyuan/config/all_metrics_config.yaml",
+        # default=r"D:\Cicv\招远\zhaoyuan\config\all_metrics_config_delivery.yaml",
+        default=r"D:\Cicv\招远\zhaoyuan\config\all_metrics_config.yaml",
         help="Full metrics config file path (built-in + custom)",
     )
     config_group.add_argument(
         "--baseConfigPath",
         type=str,
-        default=r"/home/server/anaconda3/envs/vitual_XGJ/zhaoyuan_0617/zhaoyuan/config/all_metrics_config.yaml",
+        # default=r"D:\Cicv\招远\zhaoyuan\config\all_metrics_config_delivery.yaml",
+        default=r"D:\Cicv\招远\zhaoyuan\config\all_metrics_config.yaml",
         help="Built-in metrics config file path",
     )
     config_group.add_argument(
@@ -707,7 +712,7 @@ def main():
     output_group.add_argument(
         "--plotPath",
         type=str,
-        default=r"/home/server/anaconda3/envs/vitual_XGJ/zhaoyuan_0617/zhaoyuan/scripts/reports/datas",
+        default=r"D:\Cicv\招远\zhaoyuan\scripts\reports\datas",
         help="Output plot csv directory",
     )