Utils#
- class invertedai.utils.ScenePlotter(map_image: Optional[array] = None, fov: Optional[float] = None, xy_offset: Optional[Tuple[float, float]] = None, static_actors: Optional[List[StaticMapActor]] = None, open_drive: Optional[str] = None, resolution: Tuple[int, int] = (640, 480), dpi: float = 100, left_hand_coordinates: bool = False, **kwargs)[source]#
A class providing features for handling the data visualization of a scene involving IAI data.
- Parameters:
map_image – An image used as the background for the visualization decoded from the birdview map taken from location info.
fov – A single float value representing the field of view of the visualization that can be taken from location info.
xy_offset – A tuple coordinate of the center of the map in metres that can be taken from location info.
static_actors – A list of StaticMapActor objects representing objects such as traffic lights that can be taken from location info.
open_drive – If using an ASAM OpenDRIVE format map for visualization, this string parameter is used to indicate the path to the corresponding CSV file.
resolution – The desired resolution of the map image expressed as a Tuple with two integers for the width and height respectively.
dpi – Dots per inch to define the level of detail in the image.
left_hand_coordinates – Boolean flag dictating whether the X-coordinates of all agents and actors should be reversed to fit a left hand coordinate system.
- Keyword Arguments:
map_image – Base image onto which the scene is visualized. This parameter must be provided if using an ASAM OpenDRIVE format map.
fov (float) – The field of view in meters corresponding to the map_image attribute. This parameter must be provided if using an ASAM OpenDRIVE format map.
xy_offset – The left-hand offset for the center of the map image. This parameter must be provided if using an ASAM OpenDRIVE format map.
static_actors – A list of static actor agents (e.g. traffic lights) represented as StaticMapActor objects, in the scene. This parameter must be provided if using an ASAM OpenDRIVE format map.
See also
location_info()
- animate_scene(output_name: Optional[str] = None, start_idx: int = 0, end_idx: int = -1, ax: Optional[Axes] = None, numbers: Optional[List[int]] = None, direction_vec: bool = True, velocity_vec: bool = False, plot_frame_number: bool = False, agent_face_colors: Optional[Union[List[Optional[Tuple[float, float, float]]], List[List[Optional[Tuple[float, float, float]]]]]] = None, agent_edge_colors: Optional[Union[List[Optional[Tuple[float, float, float]]], List[List[Optional[Tuple[float, float, float]]]]]] = None) FuncAnimation [source]#
Produce an animation of sequentially recorded steps. A matplotlib animation object can be returned and/or a gif saved of the scene.
- Parameters:
output_name – File name of the gif to which the animation will be saved.
start_idx – The index of the time step from which the animation will begin. By default it is assumed all recorded steps are desired to be animated.
end_idx – The index of the time step from which the animation will end. By default it is assumed all recorded steps are desired to be animated.
ax – A matplotlib Axes object used to plot the animation. By default, an Axes object is created if a value of None is passed.
numbers – A list of agent ID’s that should be plotted in the image. By default this value is set to None.
direction_vec – Flag to determine if a vector showing the vehicles direction should be plotted in the animation. By default this flag is set to True.
velocity_vec – Flag to determine if the a vector showing the vehicles velocity should be plotted in the animation. By default this flag is set to False.
plot_frame_number – Flag to determine if the frame numbers should be plotted in the animation. By default this flag is set to False.
agent_face_colors – An optional parameter containing a list of RGB tuples indicating the desired color of the agent with the corresponding index ID. A value of None in this list will use the default color. If the number of agents change throughout the simulation, the color of each agent must be specified per time step.
agent_edge_colors – An optional parameter containing a list of RGB tuples indicating the desired color of a border around the agent with the corresponding index ID. A value of None in this list will use the default color. If the number of agents change throughout the simulation, the color of each agent must be specified per time step.
- initialize_recording(agent_states: List[AgentState], agent_attributes: Optional[List[AgentAttributes]] = None, agent_properties: Optional[List[AgentProperties]] = None, traffic_light_states: Optional[Dict[int, TrafficLightState]] = None)[source]#
Record the initial state of the scene to be visualized. This function also acts as an implicit reset of the recording and removes previous agent state, agent attribute, traffic light, and agent style data.
- Parameters:
agent_states – A list of AgentState objects corresponding to the initial time step to be visualized.
agent_attributes – Static attributes of the agents present in the initial step of the simulation. We assume every agent is a rectangle obeying a kinematic bicycle model. The attributes of each agent respectively may not change but if agents are added or removed from the simulation, this list will change.
agent_properties – Static properties of the agent (with the AgentProperties data type), present in the initial step of the simulation. We assume every agent is a rectangle obeying a kinematic bicycle model. The properties of each agent respectively may not change but if agents are added or removed from the simulation, this list will change.
traffic_light_states – Optional parameter containing the state of the traffic lights corresponding to the initial time step to be visualized. This parameter should only be used if the corresponding map contains traffic light static actors.
- plot_scene(agent_states: List[AgentState], agent_attributes: Optional[List[AgentAttributes]] = None, agent_properties: Optional[List[AgentProperties]] = None, traffic_light_states: Optional[Dict[int, TrafficLightState]] = None, ax: Optional[Axes] = None, numbers: Optional[List[int]] = None, direction_vec: bool = True, velocity_vec: bool = False, agent_face_colors: Optional[List[Optional[Tuple[float, float, float]]]] = None, agent_edge_colors: Optional[List[Optional[Tuple[float, float, float]]]] = None)[source]#
Plot a single timestep of data then reset the recording.
- Parameters:
agent_states – A list of agents to be visualized in the image.
agent_attributes – Static attributes of the agent, which don’t change over the course of a simulation. We assume every agent is a rectangle obeying a kinematic bicycle model.
agent_properties – Static attributes of the agent (with the AgentProperties data type), which don’t change over the course of a simulation. We assume every agent is a rectangle obeying a kinematic bicycle model.
traffic_light_states – Optional parameter containing the state of the traffic lights to be visualized in the image. This parameter should only be used if the corresponding map contains traffic light static actors.
ax – A matplotlib Axes object used to plot the image. By default, an Axes object is created if a value of None is passed.
numbers – A list of agent ID’s that should be plotted in the image. By default this value is set to None.
direction_vec – Flag to determine if a vector showing the vehicles direction should be plotted in the image. By default this flag is set to True.
velocity_vec – Flag to determine if the a vector showing the vehicles velocity should be plotted in the animation. By default this flag is set to False.
agent_face_colors – An optional parameter containing a list of either RGB tuples indicating the desired color of the agent with the corresponding index ID. A value of None in this list will use the default color.
agent_edge_colors – An optional parameter containing a list of either RGB tuples indicating the desired color of a border around the agent with the corresponding index ID. A value of None in this list will use the default color.
- record_step(agent_states: List[AgentState], traffic_light_states: Optional[Dict[int, TrafficLightState]] = None, agent_properties: Optional[List[AgentProperties]] = None)[source]#
Record a single timestep of scene data to be used in a visualization.
- Parameters:
agent_states – A list of AgentState objects corresponding to the initial time step to be visualized.
traffic_light_states – Optional parameter containing the state of the traffic lights corresponding to the initial time step to be visualized. This parameter should only be used if the corresponding map contains traffic light static actors.
agent_properties – A list of AgentProperties for the agents present during this time step. The indexes of these properties will be matched with corresponding indexes of the states given in the agent_states parameter. If no argument is given, it is assumed the agent properties have not changed since the previous time step, including which agents are present.