def convert_json_to_actor(actor_dict): """ Convert a JSON string to an ActorConfigurationData dictionary """ node = ET.Element('waypoint') node.set('x', actor_dict['x']) node.set('y', actor_dict['y']) node.set('z', actor_dict['z']) node.set('yaw', actor_dict['yaw']) return ActorConfigurationData.parse_from_node(node, 'simulation')
def parse_scenario_configuration(scenario_config_file, scenario_name): """ Parse scenario configuration file and provide a list of ScenarioConfigurations @return If scenario_name starts with "group:" all scenarios within the config file will be returned. Otherwise only the scenario, that matches the scenario_name. """ single_scenario_only = True if scenario_name.startswith("group:"): single_scenario_only = False scenario_name = scenario_name[6:] tree = ET.parse(scenario_config_file) scenario_configurations = [] for scenario in tree.iter("scenario"): new_config = ScenarioConfiguration() new_config.town = scenario.attrib.get('town', None) new_config.name = scenario.attrib.get('name', None) new_config.type = scenario.attrib.get('type', None) new_config.other_actors = [] new_config.ego_vehicles = [] new_config.trigger_points = [] for weather in scenario.iter("weather"): new_config.weather.cloudiness = float( weather.attrib.get("cloudiness", 0)) new_config.weather.precipitation = float( weather.attrib.get("precipitation", 0)) new_config.weather.precipitation_deposits = float( weather.attrib.get("precipitation_deposits", 0)) new_config.weather.wind_intensity = float( weather.attrib.get("wind_intensity", 0.35)) new_config.weather.sun_azimuth_angle = float( weather.attrib.get("sun_azimuth_angle", 0.0)) new_config.weather.sun_altitude_angle = float( weather.attrib.get("sun_altitude_angle", 15.0)) new_config.weather.fog_density = float( weather.attrib.get("fog_density", 0.0)) new_config.weather.fog_distance = float( weather.attrib.get("fog_distance", 0.0)) new_config.weather.wetness = float( weather.attrib.get("wetness", 0.0)) for ego_vehicle in scenario.iter("ego_vehicle"): new_config.ego_vehicles.append( ActorConfigurationData.parse_from_node( ego_vehicle, 'hero')) new_config.trigger_points.append( new_config.ego_vehicles[-1].transform) for target in scenario.iter("target"): new_config.target = TargetConfiguration(target) for route in scenario.iter("route"): route_conf = RouteConfiguration() route_conf.parse_xml(route) new_config.route = route_conf for other_actor in scenario.iter("other_actor"): new_config.other_actors.append( ActorConfigurationData.parse_from_node( other_actor, 'scenario')) if single_scenario_only: if new_config.name == scenario_name: scenario_configurations.append(new_config) else: scenario_configurations.append(new_config) return scenario_configurations