Esempio n. 1
0
  def visualize_fcd_on_map(self):
    """Plot metric maps.

    Pay attention to the map.
    """
    net = sumolib.net.readNet(self._sumo_net_file)
    visualizer = map_visualizer.MapVisualizer(net)
    plot_edges = net.getEdges()

    trajectory_folder = os.path.join(self._output_dir, 'trajectory/')
    output_folder = os.path.join(trajectory_folder, 'trajectory_fig/')
    if not file_util.f_exists(output_folder):
      file_util.f_mkdir(output_folder)

    trajectory_file_list = os.listdir(trajectory_folder)
    # trajectory_file_list = [
    #     'edge_id_to_trajectory_9000_10800.pkl']

    for trajectory_file in trajectory_file_list:
      if not trajectory_file.endswith('.pkl'):
        continue
      trajectory_pkl_file = os.path.join(trajectory_folder, trajectory_file)
      print('Loading file: ', trajectory_pkl_file)
      edge_id_to_trajectory = file_util.load_variable(trajectory_pkl_file)
      print('Time range: ', edge_id_to_trajectory['time_interval'])
      output_figure_path = (output_folder + 'speed_map_%s_%s.pdf' %
                            (int(edge_id_to_trajectory['time_interval'][0]),
                             int(edge_id_to_trajectory['time_interval'][1])))

      visualizer.plot_edge_trajectory_histogram_on_map(
          plot_edges,
          edge_id_to_trajectory,
          output_figure_path=output_figure_path,
          plot_max_speed=13.4112)
Esempio n. 2
0
    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)
Esempio n. 3
0
  def parse_fcd_results_single_file(self, hours):
    """Extract the data then save to file."""
    net = sumolib.net.readNet(self._sumo_net_file)
    data_parser = simulation_data_parser.SimulationDataParser()
    plot_edges = net.getEdges()

    fcd_file = os.path.join(self._output_dir, 'traffic.fcd.xml')
    output_folder = os.path.join(self._output_dir, 'trajectory/')
    if not file_util.f_exists(output_folder):
      file_util.f_mkdir(output_folder)

    time_segment_length_seconds = hours * 3600
    time_range_seconds = [0, 3600 * 12]
    data_parser.save_batch_edge_id_to_trajectory(
        fcd_file, plot_edges,
        time_range=time_range_seconds,
        time_segment_length=time_segment_length_seconds,
        parse_time_step=10, output_folder=output_folder)