smarts.core.sumo_road_network module

class smarts.core.sumo_road_network.SumoRoadNetwork(graph: Net, net_file: str, map_spec: MapSpec)[source]

A road network for a SUMO source.

DEFAULT_LANE_WIDTH = 3.2
3.2 is the default Sumo road network lane width if it’s not specified

explicitly in Sumo’s NetEdit or the map.net.xml file.

This corresponds on a 1:1 scale to lanes 3.2m wide, which is typical

in North America (although US highway lanes are wider at ~3.7m).

class Feature(road_map, feature_id: str, feat_data, feat_type=FeatureType.FIXED_LOC_SIGNAL)[source]

Feature representation for Sumo road networks

property feature_id: str

The identifier for this feature.

property geometry: List[Point]

The geometry that represents this feature.

min_dist_from(point: Point) float[source]

Returns the euclidean (as-the-crow-flies) distance between point and the nearest part of this feature.

property type: FeatureType

The type of this feature.

property type_as_str: str

The type of this feature as a string. This is useful for resolving CUSTOM feature types.

property type_specific_info: Any | None

Can be anything specific to the feature type; defaults to None.

class Lane(lane_id: str, sumo_lane: Lane, road_map: SumoRoadNetwork)[source]

Describes a Sumo lane surface.

property bounding_box

Gets the lane bounding box.

center_at_point(point: Point) Point[source]

Get the ‘center’ of the lane closest to the given world coordinate.

center_pose_at_point(point: Point) Pose[source]

The pose at the center of the lane closest to the given point.

contains_point(point: Point) bool[source]

Returns True if this point is fully contained by this surface. For some regions of some maps, it may not be possible to determine this. In such indeterminate cases, it is recommended to return True.

curvature_radius_at_offset(offset: float, lookahead: int = 5) float[source]

lookahead (in meters) is the size of the window to use to compute the curvature, which must be at least 1 to make sense. This may return math.inf if the lane is straight.

property entry_surfaces: List[Surface]

Surfaces by which one might enter this surface.

property exit_surfaces: List[Surface]

Surfaces by which one might exit this surface.

property foes: List[Lane]

All lanes that in some ways intersect with (cross) this one, including those that have the same outgoing lane as this one, and so might require right-of-way rules. This should only ever happen in junctions.

from_lane_coord(lane_point: RefLinePoint) Point[source]

Get a world point on the lane from the given lane coordinate point.

get_distance(point: Point, radius: float) float[source]
get_distance(point: Point, radius: float, *, get_offset: bool) Tuple[float, float | None]
get_distance(point: Point, radius: float, *, perpendicular: bool) float
get_distance(point: Point, radius: float, /, get_offset: bool, perpendicular: bool) Tuple[float, float | None]

Get the distance on the lane from the given point within the given radius. Specifying to get the offset returns the offset value.

property in_junction: bool

If this lane is a part of a junction (usually an intersection.)

property incoming_lanes: List[Lane]

Lanes leading into this lane.

property index: int

when not in_junction, 0 is outer / right-most (relative to lane heading) lane on road. otherwise, index scheme is implementation-dependent, but must be deterministic.

property lane_id: str

Unique identifier for this Lane.

property lane_to_left: Tuple[Lane | None, bool]

Get the parallel lane to the left side of the direction this current lane.

Note

Left is defined as 90 degrees clockwise relative to the lane heading. (I.e., positive t in the RefLine coordinate system.) Second result is True if lane is in the same direction as this one In junctions, diverging lanes should not be included.

property lane_to_right: Tuple[Lane | None, bool]

Get the parallel lane to the right side of the direction this current lane.

Note

Right is defined as 90 degrees counter-clockwise relative to the lane heading. (I.e., negative t in the RefLine coordinate system.) Second result is True if lane is in the same direction as this one. In junctions, diverging lanes should not be included.

property lanes_in_same_direction: List[Lane]

returns all other lanes on this road where traffic goes in the same direction. it is currently assumed these will be adjacent to one another. In junctions, diverging lanes should not be included.

property length: float

The length of this lane.

offset_along_lane(world_point: Point) float[source]

Get the offset of the given point imposed on this lane.

oncoming_lanes_at_offset(offset: float) List[Lane][source]

Returns a list of nearby lanes at offset that are (roughly) parallel to this one but go in the opposite direction.

property outgoing_lanes: List[Lane]

Lanes leading out of this lane.

project_along(start_offset: float, distance: float) Set[Tuple[Lane, float]][source]

Starting at start_offset along the lane, project locations (lane, offset tuples) reachable within distance, not including lane changes.

property road: SumoRoadNetwork.Road

The road that this lane is a part of.

shape(buffer_width: float = 0.0, default_width: float | None = None) Polygon[source]

Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative), where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to also specify a default_width, in which case the returned polygon should have a convex shape where the distance across it is no less than buffered_width + default_width at any point.

property speed_limit: float | None

The speed limit on this lane. May be None if not defined.

to_lane_coord(world_point: Point) RefLinePoint[source]

Convert from the given world coordinate to a lane coordinate point.

vector_at_offset(start_offset: float) ndarray[source]

The lane direction vector at the given offset (not normalized).

waypoint_paths_at_offset(offset: float, lookahead: int = 30, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting offset into this lane. Constrains paths to the supplied route if specified.

waypoint_paths_for_pose(pose: Pose, lookahead: int, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting in this lane at pose. Constrains paths to the supplied route if specified.

width_at_offset(offset: float) Tuple[float, float][source]

Get the width of the lane at the given offset as well as a measure of certainty in this width between 0 and 1.0, where 1 indicates that the width is exact and certain, and 0 indicates a width estimate with no confidence.

class Road(road_id: str, sumo_edge: Edge, road_map: SumoRoadNetwork)[source]

This is akin to a ‘road segment’ in real life. Many of these might correspond to a single named road in reality.

contains_point(point: Point) bool[source]

Returns True if this point is fully contained by this surface. For some regions of some maps, it may not be possible to determine this. In such indeterminate cases, it is recommended to return True.

property entry_surfaces: List[Surface]

Surfaces by which one might enter this surface.

property exit_surfaces: List[Surface]

Surfaces by which one might exit this surface.

property incoming_roads: List[Road]

All roads that lead into this road.

property is_junction: bool

Note that a junction can be an intersection (‘+’) or a ‘T’, ‘Y’, ‘L’, etc.

lane_at_index(index: int) Lane[source]

Gets the lane with the given index.

property lanes: List[Lane]

The lanes contained in this road.

property length: float

The length of this road.

oncoming_roads_at_point(point: Point) List[Road][source]

Returns a list of nearby roads to point that are (roughly) parallel to this one but have lanes that go in the opposite direction.

property outgoing_roads: List[Road]

All roads that lead out of this road.

property parallel_roads: List[Road]

Returns roads that start and end at the same point as this one.

property road_id: str

The identifier for this road.

shape(buffer_width: float = 0.0, default_width: float | None = None) Polygon[source]

Returns a convex polygon representing this surface, buffered by buffered_width (which must be non-negative), where buffer_width is a buffer around the perimeter of the polygon. In some situations, it may be desirable to also specify a default_width, in which case the returned polygon should have a convex shape where the distance across it is no less than buffered_width + default_width at any point.

class Route(road_map: RoadMap, roads: List[Road] = [], start_lane: Lane | None = None, end_lane: Lane | None = None)[source]

Describes a route between two Sumo roads.

property geometry: Sequence[Sequence[Tuple[float, float]]]

A sequence of polygon vertices describing the shape of each road on the route

property road_length: float

The total road length of this route.

property roads: List[Road]

A possibly-unordered list of roads that this route covers

class Surface(surface_id: str, road_map)[source]

Describes a Sumo surface.

property features: List[Feature]

The features that this surface contains.

features_near(pose: Pose, radius: float) List[Feature][source]

The features on this surface near the given pose.

property is_drivable: bool

Returns true if this surface is legally and physically drivable.

property surface_id: str

The unique identifier for a surface.

property bounding_box: BoundingBox

The minimum bounding box that contains the map geometry. May return None to indicate the map is unbounded.

property dynamic_features: List[Feature]

All dynamic features associated with this road map.

dynamic_features_near(point: Point, radius: float) List[Tuple[Feature, float]][source]

Find features within radius meters of the given point.

empty_route() Route[source]

Generate an empty route.

feature_by_id(feature_id: str) Feature | None[source]

Find a feature in this road map that has the given identifier.

classmethod from_spec(map_spec: MapSpec)[source]

Generate a road network from the given map specification.

get_edge_in_junction(start_edge_id, start_lane_index, end_edge_id, end_lane_index) str[source]

Returns the id of the edge between the start and end edge. Can be used for any edge but is mainly useful for junctions.

is_same_map(map_or_spec: MapSpec | RoadMap) bool[source]

Check if the MapSpec Object source points to the same RoadMap instance as the current

lane_by_id(lane_id: str) SumoRoadNetwork.Lane[source]

Find a lane in this road map that has the given identifier.

nearest_lanes(point: Point, radius: float | None = None, include_junctions=True) List[Tuple[Lane, float]][source]

Find lanes on this road map that are near the given point. Returns a list of tuples of lane and distance, sorted by distance.

nearest_roads(point: Point, radius: float)[source]

Finds the nearest roads to the given point within the given radius.

random_route(max_route_len: int = 10, starting_road: SumoRoadNetwork.Road | None = None, only_drivable: bool = True) Route[source]

Generate a random route.

road_by_id(road_id: str) Road[source]

Find a road in this road map that has the given identifier.

road_with_point(point: Point, *, lanes_to_search: Sequence[RoadMap.Lane] | None = None) Road | None[source]

Find the road that contains the given point. :param point: The point to check. :param lanes_to_search: A sequence of lanes with their distances. If not provided, the nearest lanes will be used.

Returns:

A list of generated routes that satisfy the given restrictions. Routes will be returned in order of increasing length.

route_from_road_ids(road_ids: Sequence[str], resolve_intermediaries: bool = False) Route[source]

Generate a route containing the specified roads. :param road_ids: The road ids of the route. :type road_ids: Sequence[str] :param resolve_intermediaries: If to fill in the gaps in the route. This may be needed to complete an incomplete route or fill in junctions roads. :type resolve_intermediaries: bool

Returns:

A route that satisfies the given road id restrictions.

property scale_factor: float

The ratio between 1 unit on the map and 1 meter.

shifted_net_file_name = 'shifted_map-AUTOGEN.net.xml'
classmethod shifted_net_file_path(net_file_path)[source]

The path of the modified map file after coordinate normalization.

property source: str

This is the .net.xml file that corresponds with our possibly-offset coordinates.

surface_by_id(surface_id: str) Surface | None[source]

Find a surface within the road map that has the given identifier.

to_glb(glb_dir)[source]

Build a .glb file for camera rendering and envision

waypoint_paths(pose: Pose, lookahead: int, within_radius: float = 5, route: Route | None = None) List[List[Waypoint]][source]

Computes equally-spaced Waypoints for all lane paths up to lookahead waypoints ahead, starting on the Road containing the nearest Lane aligned with the vehicle’s pose within within_radius meters. Constrains paths to the supplied route if specified.

smarts.core.sumo_road_network.pairwise(iterable)[source]

Generates pairs of neighboring elements. >>> list(pairwise(‘ABCDEFG’)) [(‘A’, ‘B’), (‘B’, ‘C’), (‘C’, ‘D’), (‘D’, ‘E’), (‘E’, ‘F’), (‘F’, ‘G’)]