def _extract_detector_data(self): """Extracts detector data form xml files.""" data_parser = simulation_data_parser.SimulationDataParser() visualizer = map_visualizer.MapVisualizer() detector_folder = os.path.join(self._output_dir, 'detector/') detector_trajectory_folder = os.path.join(detector_folder, 'detector_trajectory/') if not file_util.exists(detector_trajectory_folder): file_util.mkdir(detector_trajectory_folder) detector_files = os.listdir(detector_folder) for detector_file in detector_files: if not detector_file.endswith('.xml'): continue # print('Extract file: ', detector_file) output_file = os.path.splitext(detector_file)[0] + '.pkl' output_file = os.path.join(detector_trajectory_folder, output_file) detector_file = os.path.join(detector_folder, detector_file) print('Save file: ', output_file) data_parser.get_and_save_detector_data(detector_file, output_file) # Creates figures for individual detector. output_figure_folder = os.path.join(detector_folder, 'detector_fig/') if not file_util.f_exists(output_figure_folder): file_util.f_mkdir(output_figure_folder) visualizer.plot_individual_detector(detector_trajectory_folder, output_figure_folder)
def plot_save_detector_data_reverse(self): """Plots detector data. Paradise evacuation edges: '27323694.1622', # Skyway Rd. '37625137#0.49' # Skyway Rd reverse. '10293408#4', # Neal Rd. '-184839999#0', # Clark Rd. '-538864403#0' # Pentz Rd. """ self._extract_detector_data() detector_trajectory_folder = os.path.join( self._output_dir, 'detector/detector_trajectory/') output_figure_folder = os.path.join( self._output_dir, 'detector/detector_fig/') if not file_util.exists(output_figure_folder): file_util.mkdir(output_figure_folder) visualizer = map_visualizer.MapVisualizer() detector_pkl_files_by_group = [ [detector_trajectory_folder + 'e1Detector_27323694_0_0.pkl', detector_trajectory_folder + 'e1Detector_27323694_1_1.pkl', detector_trajectory_folder + 'e1Detector_37625137#1_0_6.pkl', detector_trajectory_folder + 'e1Detector_37625137#1_1_7.pkl'], [detector_trajectory_folder + 'e1Detector_10293408#4_0_2.pkl'], [detector_trajectory_folder + 'e1Detector_-184839999#0_0_3.pkl', detector_trajectory_folder + 'e1Detector_-184839999#0_1_4.pkl', detector_trajectory_folder + 'e1Detector_-184839999#0_2_8.pkl', detector_trajectory_folder + 'e1Detector_-184839999#0_3_9.pkl'], [detector_trajectory_folder + 'e1Detector_-538864403#0_0_5.pkl', detector_trajectory_folder + 'e1Detector_-538864403#0_1_10.pkl']] visualizer.plot_detector_flow_density_by_group( detector_pkl_files_by_group, ['Skyway', 'Neal_Rd', 'Clark_Rd', 'Pentz_Rd'], output_figure_folder=output_figure_folder) # Cumulative vehicle flow. detector_pkl_files = [ 'e1Detector_27323694_0_0.pkl', 'e1Detector_27323694_1_1.pkl', 'e1Detector_37625137#1_0_6.pkl', 'e1Detector_37625137#1_1_7.pkl', 'e1Detector_10293408#4_0_2.pkl', 'e1Detector_-184839999#0_0_3.pkl', 'e1Detector_-184839999#0_1_4.pkl', 'e1Detector_-184839999#0_2_8.pkl', 'e1Detector_-184839999#0_3_9.pkl', 'e1Detector_-538864403#0_0_5.pkl', 'e1Detector_-538864403#0_1_10.pkl'] detector_pkl_files = [os.path.join(detector_trajectory_folder, filename) for filename in detector_pkl_files] visualizer.plot_detector_arrival_time_by_group( detector_pkl_files, output_figure_folder)