scenic.domains.driving.roads
Library for representing road network geometry and traffic information.
A road network is represented by an instance of the Network class, which can
be created from a map file using Network.fromFile.
Note
This library is a prototype under active development. We will try not to make backwards-incompatible changes, but the API may not be entirely stable.
Summary of Module Members
Module Attributes
Alias for types which can be interpreted as positions in Scenic. |
Classes
An intersection where multiple roads meet. |
|
A lane for cars, bicycles, or other vehicles. |
|
A group of parallel lanes with the same type and direction. |
|
Part of a lane in a single |
|
A part of a road network with (mostly) linear 1- or 2-way flow. |
|
A maneuver which can be taken upon reaching the end of a lane. |
|
A type of |
|
A road network. |
|
Abstract class for part of a road network. |
|
A pedestrian crossing (crosswalk). |
|
A road consisting of one or more lanes. |
|
Part of a road with a fixed number of lanes. |
|
A shoulder of a road, including parking lanes by default. |
|
A sidewalk. |
|
Traffic lights, stop signs, etc. |
|
A type of vehicle, including pedestrians. |
Member Details
- Vectorlike
Alias for types which can be interpreted as positions in Scenic.
This includes instances of
PointandObject, and pairs of numbers.
- class VehicleType(value)[source]
Bases:
EnumA type of vehicle, including pedestrians. Used to classify lanes.
- class ManeuverType(value)[source]
Bases:
EnumA type of
Maneuver, e.g., going straight or turning left.- STRAIGHT = 1
Straight, including one lane merging into another.
- LEFT_TURN = 2
Left turn.
- RIGHT_TURN = 3
Right turn.
- U_TURN = 4
U-turn.
- class Maneuver[source]
A maneuver which can be taken upon reaching the end of a lane.
- Parameters:
type (ManeuverType)
startLane (Lane)
endLane (Lane)
connectingLane (Lane | None)
intersection (Intersection | None)
- type: ManeuverType
type of maneuver (straight, left turn, etc.)
- connectingLane: Lane | None
connecting lane from the start to the end lane, if any (
Nonefor lane mergers)
- intersection: Intersection | None
intersection where the maneuver takes place, if any (
Nonefor lane mergers)
- class NetworkElement[source]
Bases:
PolygonalRegionAbstract class for part of a road network.
Includes roads, lane groups, lanes, sidewalks, pedestrian crossings, and intersections.
This is a subclass of
Region, so you can do things likeCar in laneorCar on roadiflaneandroadare elements, as well as computing distances to an element, etc.- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
- uid: str
Unique identifier; from underlying format, if possible. (In OpenDRIVE, for example, ids are not necessarily unique, so we invent our own.)
- vehicleTypes: FrozenSet[VehicleType]
Which types of vehicles (car, bicycle, etc.) can be here.
- nominalDirectionsAt(point)[source]
Get nominal traffic direction(s) at a point in this element.
There must be at least one such direction. If there are multiple, we pick one arbitrarily to be the orientation of the element as a
Region. (SoObject in elementwill align by default to that orientation.)- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
- class LinearElement[source]
Bases:
NetworkElementA part of a road network with (mostly) linear 1- or 2-way flow.
Includes roads, lane groups, lanes, sidewalks, and pedestrian crossings, but not intersections.
LinearElements have a direction, namely from the first point on their centerline to the last point. This is called ‘forward’, even for 2-way roads. The ‘left’ and ‘right’ edges are interpreted with respect to this direction.
The left/right edges are oriented along the direction of traffic near them; so for 2-way roads they will point opposite directions.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
- flowFrom(point, distance, steps=None, stepSize=5)[source]
Advance a point along this element by a given distance.
Equivalent to
follow element.orientation from point for distance, but possibly more accurate. The default implementation uses the forward Euler approximation with a step size of 5 meters; subclasses may ignore the steps and stepSize parameters if they can compute the flow exactly.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`) – point to start from.
distance (float) – distance to travel.
steps (int | None) – number of steps to take, or
Noneto compute the number of steps based on the distance (defaultNone).stepSize (float) – length used to compute how many steps to take, if steps is not specified (default 5 meters).
- Return type:
- class Road[source]
Bases:
LinearElementA road consisting of one or more lanes.
Lanes are grouped into 1 or 2 instances of
LaneGroup:forwardLanes: the lanes going the same direction as the road
backwardLanes: the lanes going the opposite direction
One of these may be None if there are no lanes in that direction.
Because of splits and mergers, the Lanes of a
Roaddo not necessarily start or end at the same point as theRoad. Such intermediate branching points cause theRoadto be partitioned into multiple road sections, within which the configuration of lanes is fixed.- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
forwardLanes (LaneGroup | None)
backwardLanes (LaneGroup | None)
sections (Tuple[RoadSection])
crossings (Tuple[PedestrianCrossing])
sidewalkRegion (PolygonalRegion)
- lanes: Tuple[Lane]
All lanes of this road, in either direction.
The order of the lanes is arbitrary. To access lanes in order according to their geometry, use
LaneGroup.lanes.
- laneGroups: Tuple[LaneGroup]
All LaneGroups of this road, with
forwardLanesbeing first if it exists.
- sections: Tuple[RoadSection]
All sections of this road, ordered from start to end.
- crossings: Tuple[PedestrianCrossing]
All crosswalks of this road, ordered from start to end.
- sidewalks: Tuple[Sidewalk]
All sidewalks of this road, with the one adjacent to
forwardLanesbeing first.
- sidewalkRegion: PolygonalRegion
Possibly-empty region consisting of all sidewalks of this road.
- sectionAt(point, reject=False)[source]
Get the
RoadSectionpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
RoadSection | None
- laneSectionAt(point, reject=False)[source]
Get the
LaneSectionpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneSection | None
- laneAt(point, reject=False)[source]
Get the
Lanepassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Lane | None
- laneGroupAt(point, reject=False)[source]
Get the
LaneGrouppassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneGroup | None
- crossingAt(point, reject=False)[source]
Get the
PedestrianCrossingpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
PedestrianCrossing | None
- class LaneGroup[source]
Bases:
LinearElementA group of parallel lanes with the same type and direction.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
road (Road)
curb (PolylineRegion)
sidewalk (Union[Sidewalk, None])
bikeLane (Union[Lane, None])
shoulder (Union[Shoulder, None])
opposite (Union[LaneGroup, None])
- curb: PolylineRegion
Region representing the associated curb, which is not necessarily adjacent if there are parking lanes or some other kind of shoulder.
- class Lane[source]
Bases:
LinearElementA lane for cars, bicycles, or other vehicles.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
group (LaneGroup)
road (Road)
sections (Tuple[LaneSection])
- sectionAt(point, reject=False)[source]
Get the LaneSection passing through a given point.
- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneSection | None
- class RoadSection[source]
Bases:
LinearElementPart of a road with a fixed number of lanes.
A RoadSection has a fixed number of lanes: when a lane begins or ends, we move to a new section (which will be the successor of the current one).
- Parameters:
polygon (Union[Polygon, MultiPolygon])
orientation (Optional[VectorField])
name (str)
uid (str)
id (Optional[str])
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (Union[float, None])
tags (FrozenSet[str])
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
road (Road)
lanes (Tuple[LaneSection])
forwardLanes (Tuple[LaneSection])
backwardLanes (Tuple[LaneSection])
lanesByOpenDriveID (Dict[LaneSection])
- laneAt(point, reject=False)[source]
Get the lane section passing through a given point.
- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneSection | None
- class LaneSection[source]
Bases:
LinearElementPart of a lane in a single
RoadSection.Since the lane configuration in a
RoadSectionis fixed, aLaneSectioncan have at most one adjacent lane to left or right. These are accessible using thelaneToLeftandlaneToRightproperties, which for convenience reject the simulation if the desired lane does not exist. If rejection is not desired (for example if you want to handle the case where there is no lane to the left yourself), you can use the_laneToLeftand_laneToRightproperties instead.- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
lane (Lane)
group (LaneGroup)
road (Road)
openDriveID (int)
isForward (bool)
adjacentLanes (Tuple[LaneSection])
laneToLeft (Union[LaneSection, None])
laneToRight (Union[LaneSection, None])
fasterLane (Union[LaneSection, None])
slowerLane (Union[LaneSection, None])
- adjacentLanes: Tuple[LaneSection]
Adjacent lanes of the same type, if any.
- _laneToLeft: LaneSection | None
Adjacent lane of same type to the left, if any.
- _laneToRight: LaneSection | None
Adjacent lane of same type to the right, if any.
- _fasterLane: LaneSection | None
Faster adjacent lane of same type, if any. Could be to left or right depending on the country.
- _slowerLane: LaneSection | None
Slower adjacent lane of same type, if any.
- property laneToLeft: LaneSection
The adjacent lane of the same type to the left; rejects if there is none.
- property laneToRight: LaneSection
The adjacent lane of the same type to the right; rejects if there is none.
- property fasterLane: LaneSection
The faster adjacent lane of the same type; rejects if there is none.
- property slowerLane: LaneSection
The slower adjacent lane of the same type; rejects if there is none.
- shiftedBy(offset)[source]
Find the lane a given number of lanes over from this lane.
- Parameters:
offset (int)
- Return type:
LaneSection | None
- class Sidewalk[source]
Bases:
LinearElementA sidewalk.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
road (Road)
crossings (Tuple[PedestrianCrossing])
- class PedestrianCrossing[source]
Bases:
LinearElementA pedestrian crossing (crosswalk).
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
parent (Road | Intersection)
startSidewalk (Sidewalk)
endSidewalk (Sidewalk)
- class Shoulder[source]
Bases:
LinearElementA shoulder of a road, including parking lanes by default.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
centerline (PolylineRegion)
leftEdge (PolylineRegion)
rightEdge (PolylineRegion)
successor (Union[NetworkElement, None])
predecessor (Union[NetworkElement, None])
road (Road)
- class Intersection[source]
Bases:
NetworkElementAn intersection where multiple roads meet.
- Parameters:
polygon (Polygon | MultiPolygon)
orientation (VectorField | None)
name (str)
uid (str)
id (str | None)
network (Network)
vehicleTypes (FrozenSet[VehicleType])
speedLimit (float | None)
crossings (Tuple[PedestrianCrossing])
- class Signal(*, uid=None, openDriveID, country, type)[source]
Traffic lights, stop signs, etc.
Warning
Signal parsing is a work in progress and the API is likely to change in the future.
- class Network[source]
A road network.
Networks are composed of roads, intersections, sidewalks, etc., which are all instances of
NetworkElement.Road networks can be loaded from standard formats using
Network.fromFile.- Parameters:
elements (Dict[str, NetworkElement])
roads (Tuple[Road])
connectingRoads (Tuple[Road])
allRoads (Tuple[Road])
laneGroups (Tuple[LaneGroup])
lanes (Tuple[Lane])
intersections (Tuple[Intersection])
crossings (Tuple[PedestrianCrossing])
sidewalks (Tuple[Sidewalk])
shoulders (Tuple[Shoulder])
roadSections (Tuple[RoadSection])
laneSections (Tuple[LaneSection])
driveOnLeft (bool)
tolerance (float)
drivableRegion (PolygonalRegion)
walkableRegion (PolygonalRegion)
roadRegion (PolygonalRegion)
laneRegion (PolygonalRegion)
intersectionRegion (PolygonalRegion)
crossingRegion (PolygonalRegion)
sidewalkRegion (PolygonalRegion)
curbRegion (PolylineRegion)
shoulderRegion (PolygonalRegion)
roadDirection (VectorField)
- elements: Dict[str, NetworkElement]
All network elements, indexed by unique ID.
- intersections: Tuple[Intersection]
All intersections in the network.
- crossings: Tuple[PedestrianCrossing]
All pedestrian crossings in the network.
- roadSections: Tuple[RoadSection]
All sections of ordinary roads in the network.
- laneSections: Tuple[LaneSection]
All sections of lanes in the network.
- roadDirection: VectorField
Traffic flow vector field aggregated over all roads (0 elsewhere).
- pickledExt = '.snet'
File extension for cached versions of processed networks.
- exception DigestMismatchError[source]
Bases:
ExceptionException raised when loading a cached map not matching the original file.
- classmethod fromFile(path, useCache=True, writeCache=True, **kwargs)[source]
Create a
Networkfrom a map file.This function calls an appropriate parsing routine based on the extension of the given file. Supported map formats are:
OpenDRIVE (
.xodr):Network.fromOpenDrive
See the functions listed above for format-specific options to this function. If no file extension is given in path, this function searches for any file with the given name in one of the formats above (in order).
- Parameters:
path – A string or other path-like object giving a path to a file. If no file extension is included, we search for any file type we know how to parse.
useCache (bool) – Whether to use a cached version of the map, if one exists and matches the given map file (default true; note that if the map file changes, the cached version will still not be used).
writeCache (bool) – Whether to save a cached version of the processed map after parsing has finished (default true).
kwargs – Additional keyword arguments specific to particular map formats.
- Raises:
FileNotFoundError – no readable map was found at the given path.
ValueError – the given map is of an unknown format.
- classmethod fromOpenDrive(path, ref_points=20, tolerance=0.05, fill_gaps=True, fill_intersections=True, elide_short_roads=False)[source]
Create a
Networkfrom an OpenDRIVE file.- Parameters:
path – Path to the file, as in
Network.fromFile.ref_points (int) – Number of points to discretize continuous reference lines into.
tolerance (float) – Tolerance for merging nearby geometries.
fill_gaps (bool) – Whether to attempt to fill gaps between adjacent lanes.
fill_intersections (bool) – Whether to attempt to fill gaps inside intersections.
elide_short_roads (bool) – Whether to attempt to fix geometry artifacts by eliding roads with length less than tolerance.
- findPointIn(point, elems, reject)[source]
Find the first of the given elements containing the point.
Elements which actually contain the point have priority; if none contain the point, then we search again allowing an error of up to tolerance. If there are still no matches, we return None, unless reject is true, in which case we reject the current sample.
- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
elems (Sequence[NetworkElement])
- Return type:
NetworkElement | None
- elementAt(point, reject=False)[source]
Get the highest-level
NetworkElementat a given point, if any.If the point lies in an element, return it. Otherwise, if the point lies within
self.toleranceof an element, return the first match using this priority order: Intersection → Road → Shoulder → Sidewalk. If nothing matches, returnNone(or reject ifreject=True).- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
NetworkElement | None
- roadAt(point, reject=False)[source]
Get the
Roadpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Road | None
- laneAt(point, reject=False)[source]
Get the
Lanepassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Lane | None
- laneSectionAt(point, reject=False)[source]
Get the
LaneSectionpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneSection | None
- laneGroupAt(point, reject=False)[source]
Get the
LaneGrouppassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
LaneGroup | None
- crossingAt(point, reject=False)[source]
Get the
PedestrianCrossingpassing through a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
PedestrianCrossing | None
- intersectionAt(point, reject=False)[source]
Get the
Intersectionat a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Intersection | None
- sidewalkAt(point, reject=False)[source]
Get the
Sidewalkat a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Sidewalk | None
- shoulderAt(point, reject=False)[source]
Get the
Shoulderat a given point.- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
Shoulder | None
- nominalDirectionsAt(point, reject=False)[source]
Get the nominal traffic direction(s) at a given point, if any.
There can be more than one such direction in an intersection, for example: a car at a given point could be going straight, turning left, etc.
- Parameters:
point (`scenic.domains.driving.roads.Vectorlike`)
- Return type:
- show(labelIncomingLanes=False, showCurbArrows=False)[source]
Render a schematic of the road network for debugging.
If you call this function directly, you’ll need to subsequently call
matplotlib.pyplot.showto actually display the diagram.