code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def endless_mission( start_pose: Pose, ) -> NavigationMission: """Generate an endless mission.""" return NavigationMission( start=Start(start_pose.as_position2d(), start_pose.heading), goal=EndlessGoal(), entry_tactic=None, )
Generate an endless mission.
endless_mission
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def random_endless_mission( road_map: RoadMap, min_range_along_lane: float = 0.3, max_range_along_lane: float = 0.9, ) -> NavigationMission: """A mission that starts from a random location and continues indefinitely.""" assert min_range_along_lane > 0 # Need to start further than beginning of lane assert max_range_along_lane < 1 # Cannot start past end of lane assert min_range_along_lane < max_range_along_lane # Min must be less than max road = road_map.random_route(1).roads[0] n_lane = random.choice(road.lanes) # XXX: The ends of the road are not as useful as starting mission locations. offset = random.random() * min_range_along_lane + ( max_range_along_lane - min_range_along_lane ) offset *= n_lane.length coord = n_lane.from_lane_coord(RefLinePoint(offset)) target_pose = n_lane.center_pose_at_point(coord) return NavigationMission.endless_mission(start_pose=target_pose)
A mission that starts from a random location and continues indefinitely.
random_endless_mission
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def is_complete(self, vehicle_state, distance_travelled: float) -> bool: """If the mission has been completed.""" return ( self.goal.is_reached(vehicle_state) and distance_travelled > self.route_length * self.num_laps )
If the mission has been completed.
is_complete
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def empty(cls: Type[PlanFrame]): """Creates an empty plan frame.""" return cls(road_ids=[], mission=None)
Creates an empty plan frame.
empty
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def route(self) -> Optional[RoadMap.Route]: """The route that this plan calls for.""" return self._route
The route that this plan calls for.
route
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def mission(self) -> Optional[NavigationMission]: """The mission this plan is meant to fulfill.""" # XXX: This currently can be `None` return self._mission
The mission this plan is meant to fulfill.
mission
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def road_map(self) -> RoadMap: """The road map this plan is relative to.""" return self._road_map
The road map this plan is relative to.
road_map
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def create_route( self, mission: NavigationMission, start_lane_radius: Optional[float] = None, end_lane_radius: Optional[float] = None, ): """Generates a route that conforms to a mission. Args: mission (Mission): A mission the agent should follow. Defaults to endless if `None`. start_lane_radius (Optional[float]): Radius (meter) to find the nearest starting lane for the given mission. Defaults to a function of `_default_lane_width` of the underlying road_map. end_lane_radius (Optional[float]): Radius (meter) to find the nearest ending lane for the given mission. Defaults to a function of `_default_lane_width` of the underlying road_map. """ assert not self._route or not len( self._route.road_ids ), "Already called create_route()." self._mission = mission or NavigationMission.random_endless_mission( self._road_map ) if not self._mission.requires_route: self._route = self._road_map.empty_route() return assert isinstance(self._mission.goal, PositionalGoal) start_lanes = self._road_map.nearest_lanes( self._mission.start.point, include_junctions=True, radius=start_lane_radius, ) if not start_lanes: self._mission = NavigationMission.endless_mission(Pose.origin()) raise PlanningError("Starting lane not found. Route must start in a lane.") via_roads = [self._road_map.road_by_id(via) for via in self._mission.route_vias] end_lanes = self._road_map.nearest_lanes( self._mission.goal.position, include_junctions=False, radius=end_lane_radius, ) assert end_lanes is not None, "No end lane found. Route must end in a lane." # When an agent is in an intersection, the `nearest_lanes` method might # not return the correct road as the first choice. Hence, nearest # starting lanes are tried in sequence until a route is found or until # all nearby starting lane options are exhausted. for end_lane, _ in end_lanes: for start_lane, _ in start_lanes: self._route = self._road_map.generate_routes( start_lane, end_lane, via_roads, 1 )[0] if self._route.road_length > 0: break if self._route.road_length > 0: break if len(self._route.roads) == 0: self._mission = NavigationMission.endless_mission(Pose.origin()) start_road_ids = [start_lane.road.road_id for start_lane, _ in start_lanes] raise PlanningError( "Unable to find a route between start={} and end={}. If either of " "these are junctions (not well supported today) please switch to " "roads and ensure there is a > 0 offset into the road if it is " "after a junction.".format(start_road_ids, end_lane.road.road_id) ) return self._mission
Generates a route that conforms to a mission. Args: mission (Mission): A mission the agent should follow. Defaults to endless if `None`. start_lane_radius (Optional[float]): Radius (meter) to find the nearest starting lane for the given mission. Defaults to a function of `_default_lane_width` of the underlying road_map. end_lane_radius (Optional[float]): Radius (meter) to find the nearest ending lane for the given mission. Defaults to a function of `_default_lane_width` of the underlying road_map.
create_route
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def frame(self) -> PlanFrame: """Get the state of this plan.""" assert self._mission return PlanFrame( road_ids=self._route.road_ids if self._route else [], mission=self._mission )
Get the state of this plan.
frame
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def from_frame(cls, plan_frame: PlanFrame, road_map: RoadMap) -> "Plan": """Generate the plan from a frame.""" new_plan = cls(road_map=road_map, mission=plan_frame.mission, find_route=False) new_plan.route = road_map.route_from_road_ids(plan_frame.road_ids) return new_plan
Generate the plan from a frame.
from_frame
python
huawei-noah/SMARTS
smarts/core/plan.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/plan.py
MIT
def destroy(self): """Clean up the buffer resources.""" raise NotImplementedError
Clean up the buffer resources.
destroy
python
huawei-noah/SMARTS
smarts/core/agent_buffer.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/agent_buffer.py
MIT
def acquire_agent( self, retries: int = 3, timeout: Optional[float] = None ) -> BufferAgent: """Get an agent from the buffer.""" raise NotImplementedError
Get an agent from the buffer.
acquire_agent
python
huawei-noah/SMARTS
smarts/core/agent_buffer.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/agent_buffer.py
MIT
def name(self) -> str: """The name of the traffic history.""" return os.path.splitext(self._db.name)[0]
The name of the traffic history.
name
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def connect_for_multiple_queries(self): """Optional optimization to avoid the overhead of parsing the `sqlite` file header multiple times for clients that will be performing multiple queries. If used, then disconnect() should be called when finished.""" if not self._db_cnxn: self._db_cnxn = sqlite3.connect(self._db.path)
Optional optimization to avoid the overhead of parsing the `sqlite` file header multiple times for clients that will be performing multiple queries. If used, then disconnect() should be called when finished.
connect_for_multiple_queries
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def disconnect(self): """End connection with the history database.""" if self._db_cnxn: self._db_cnxn.close() self._db_cnxn = None
End connection with the history database.
disconnect
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def dataset_source(self) -> Optional[str]: """The known source of the history data""" query = "SELECT value FROM Spec where key='source_type'" return self._query_val(str, query)
The known source of the history data
dataset_source
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def lane_width(self) -> Optional[float]: """The general lane width in the history data""" query = "SELECT value FROM Spec where key='map_net.lane_width'" return self._query_val(float, query)
The general lane width in the history data
lane_width
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def target_speed(self) -> Optional[float]: """The general speed limit in the history data.""" query = "SELECT value FROM Spec where key='speed_limit_mps'" return self._query_val(float, query)
The general speed limit in the history data.
target_speed
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def all_vehicle_ids(self) -> Generator[int, None, None]: """Get the ids of all vehicles in the history data""" query = "SELECT id FROM Vehicle" return (row[0] for row in self._query_list(query))
Get the ids of all vehicles in the history data
all_vehicle_ids
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def ego_vehicle_id(self) -> Optional[int]: """The id of the ego's actor in the history data.""" query = "SELECT id FROM Vehicle WHERE is_ego_vehicle = 1" ego_id = self._query_val(int, query) return ego_id
The id of the ego's actor in the history data.
ego_vehicle_id
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_initial_time(self, vehicle_id: str) -> float: """Returns the initial time the specified vehicle is seen in the history data.""" query = "SELECT MIN(sim_time) FROM Trajectory WHERE vehicle_id = ?" return self._query_val(float, query, params=(vehicle_id,))
Returns the initial time the specified vehicle is seen in the history data.
vehicle_initial_time
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_final_exit_time(self, vehicle_id: str) -> float: """Returns the final time the specified vehicle is seen in the history data.""" query = "SELECT MAX(sim_time) FROM Trajectory WHERE vehicle_id = ?" return self._query_val(float, query, params=(vehicle_id,))
Returns the final time the specified vehicle is seen in the history data.
vehicle_final_exit_time
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_final_position(self, vehicle_id: str) -> Tuple[float, float]: """Returns the final (x,y) position for the specified vehicle in the history data.""" query = "SELECT position_x, position_y FROM Trajectory WHERE vehicle_id=? AND sim_time=(SELECT MAX(sim_time) FROM Trajectory WHERE vehicle_id=?)" return self._query_val( tuple, query, params=( vehicle_id, vehicle_id, ), )
Returns the final (x,y) position for the specified vehicle in the history data.
vehicle_final_position
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def decode_vehicle_type(self, vehicle_type: int) -> str: """Convert from the dataset type id to their config type. Options from NGSIM and INTERACTION currently include: 1=motorcycle, 2=auto, 3=truck, 4=pedestrian/bicycle This actually returns a ``vehicle_config_type``. """ if vehicle_type == 1: return "motorcycle" elif vehicle_type == 2: return "passenger" elif vehicle_type == 3: return "truck" elif vehicle_type == 4: return "pedestrian" else: self._log.warning( f"unsupported vehicle_type ({vehicle_type}) in history data." ) return "passenger"
Convert from the dataset type id to their config type. Options from NGSIM and INTERACTION currently include: 1=motorcycle, 2=auto, 3=truck, 4=pedestrian/bicycle This actually returns a ``vehicle_config_type``.
decode_vehicle_type
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_config_type(self, vehicle_id: str) -> str: """Find the configuration type of the specified vehicle.""" query = "SELECT type FROM Vehicle WHERE id = ?" veh_type = self._query_val(int, query, params=(vehicle_id,)) return self.decode_vehicle_type(veh_type)
Find the configuration type of the specified vehicle.
vehicle_config_type
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_dims(self, vehicle_id: str) -> Dimensions: """Get the vehicle dimensions of the specified vehicle.""" # do import here to break circular dependency chain from smarts.core.vehicle import VEHICLE_CONFIGS query = "SELECT length, width, height, type FROM Vehicle WHERE id = ?" length, width, height, veh_type = self._query_val( tuple, query, params=(vehicle_id,) ) return self._resolve_vehicle_dims(veh_type, length, width, height)
Get the vehicle dimensions of the specified vehicle.
vehicle_dims
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def first_seen_times(self) -> Generator[Tuple[int, float], None, None]: """Find the times each vehicle is first seen in the traffic history. XXX: For now, limit agent missions to just passenger cars (V.type = 2) """ query = """SELECT T.vehicle_id, MIN(T.sim_time) FROM Trajectory AS T INNER JOIN Vehicle AS V ON T.vehicle_id=V.id WHERE V.type = 2 GROUP BY vehicle_id""" return self._query_list(query)
Find the times each vehicle is first seen in the traffic history. XXX: For now, limit agent missions to just passenger cars (V.type = 2)
first_seen_times
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def last_seen_vehicle_time(self) -> Optional[float]: """Find the time the last vehicle exits the history.""" query = """SELECT MAX(T.sim_time) FROM Trajectory AS T INNER JOIN Vehicle AS V ON T.vehicle_id=V.id WHERE V.type = 2 ORDER BY T.sim_time DESC LIMIT 1""" return self._query_val(float, query)
Find the time the last vehicle exits the history.
last_seen_vehicle_time
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_pose_at_time( self, vehicle_id: str, sim_time: float ) -> Optional[Tuple[float, float, float, float]]: """Get the pose of the specified vehicle at the specified history time.""" query = """SELECT position_x, position_y, heading_rad, speed FROM Trajectory WHERE vehicle_id = ? and sim_time = ?""" return self._query_val(tuple, query, params=(int(vehicle_id), float(sim_time)))
Get the pose of the specified vehicle at the specified history time.
vehicle_pose_at_time
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_ids_active_between( self, start_time: float, end_time: float ) -> Generator[Tuple, None, None]: """Find the ids of all active vehicles between the given history times. XXX: For now, limited to just passenger cars (V.type = 2) XXX: This looks like the wrong level to filter out vehicles """ query = """SELECT DISTINCT T.vehicle_id FROM Trajectory AS T INNER JOIN Vehicle AS V ON T.vehicle_id=V.id WHERE ? <= T.sim_time AND T.sim_time <= ? AND V.type = 2""" return self._query_list(query, (start_time, end_time))
Find the ids of all active vehicles between the given history times. XXX: For now, limited to just passenger cars (V.type = 2) XXX: This looks like the wrong level to filter out vehicles
vehicle_ids_active_between
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def axle_start_position(self): """The start position of the vehicle from the axle.""" hhx, hhy = radians_to_vec(self.start_heading) * (0.5 * self.vehicle_length) return [self.start_position_x + hhx, self.start_position_y + hhy]
The start position of the vehicle from the axle.
axle_start_position
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def axle_end_position(self): """The start position of the vehicle from the axle.""" hhx, hhy = radians_to_vec(self.end_heading) * (0.5 * self.vehicle_length) return [self.end_position_x + hhx, self.end_position_y + hhy]
The start position of the vehicle from the axle.
axle_end_position
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def dimensions(self) -> Dimensions: """The known or estimated dimensions of this vehicle.""" return Dimensions( self.vehicle_length, self.vehicle_width, self.vehicle_height )
The known or estimated dimensions of this vehicle.
dimensions
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicles_active_between( self, start_time: float, end_time: float ) -> Generator[TrafficHistory.VehicleRow, None, None]: """Find all vehicles active between the given history times.""" query = """SELECT V.id, V.type, V.length, V.width, V.height, T.position_x, T.position_y, T.heading_rad, T.speed FROM Vehicle AS V INNER JOIN Trajectory AS T ON V.id = T.vehicle_id WHERE T.sim_time > ? AND T.sim_time <= ? ORDER BY T.sim_time DESC""" rows = self._query_list(query, (start_time, end_time)) return (TrafficHistory.VehicleRow(*row) for row in rows)
Find all vehicles active between the given history times.
vehicles_active_between
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def traffic_light_states_between( self, start_time: float, end_time: float ) -> Generator[TrafficHistory.TrafficLightRow, None, None]: """Find all traffic light states between the given history times.""" query = """SELECT sim_time, state, stop_point_x, stop_point_y, lane FROM TrafficLightState WHERE sim_time > ? AND sim_time <= ? ORDER BY sim_time ASC""" rows = self._query_list(query, (start_time, end_time)) return (TrafficHistory.TrafficLightRow(*row) for row in rows)
Find all traffic light states between the given history times.
traffic_light_states_between
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def _greatest_n_per_group_format( select, table, group_by, greatest_of_group, where=None, operation="MAX" ): """This solves the issue where you want to get the highest value of `greatest_of_group` in the group `groupby` for versions of sqlite3 that are lower than `3.7.11`. See: https://stackoverflow.com/questions/12608025/how-to-construct-a-sqlite-query-to-group-by-order e.g. Get a table of the highest speed(`greatest_of_group`) each vehicle(`group_by`) was operating at. > _greatest_n_per_group_format( > select="vehicle_speed, > vehicle_id", > table="Trajectory", > group_by="vehicle_id", > greatest_of_group="vehicle_speed", > ) """ where = f"{where} AND" if where else "" return f""" SELECT {select}, (SELECT COUNT({group_by}) AS count FROM {table} m2 WHERE m1.{group_by} = m2.{group_by}) FROM {table} m1 WHERE {greatest_of_group} = (SELECT {operation}({greatest_of_group}) FROM {table} m3 WHERE {where} m1.{group_by} = m3.{group_by}) GROUP BY {group_by} """
This solves the issue where you want to get the highest value of `greatest_of_group` in the group `groupby` for versions of sqlite3 that are lower than `3.7.11`. See: https://stackoverflow.com/questions/12608025/how-to-construct-a-sqlite-query-to-group-by-order e.g. Get a table of the highest speed(`greatest_of_group`) each vehicle(`group_by`) was operating at. > _greatest_n_per_group_format( > select="vehicle_speed, > vehicle_id", > table="Trajectory", > group_by="vehicle_id", > greatest_of_group="vehicle_speed", > )
_greatest_n_per_group_format
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_window_by_id( self, vehicle_id: str, ) -> Optional[TrafficHistory.TrafficHistoryVehicleWindow]: """Find the given vehicle by its id.""" query = """SELECT V.id, V.type, V.length, V.width, V.height, S.position_x, S.position_y, S.heading_rad, S.speed, D.avg_speed, S.sim_time, E.sim_time, E.position_x, E.position_y, E.heading_rad FROM Vehicle AS V INNER JOIN ( SELECT vehicle_id, AVG(speed) as "avg_speed" FROM Trajectory WHERE vehicle_id = ? ) AS D ON V.id = D.vehicle_id INNER JOIN ( SELECT vehicle_id, MIN(sim_time) as sim_time, speed, position_x, position_y, heading_rad FROM Trajectory WHERE vehicle_id = ? ) AS S ON V.id = S.vehicle_id INNER JOIN ( SELECT vehicle_id, MAX(sim_time) as sim_time, speed, position_x, position_y, heading_rad FROM Trajectory WHERE vehicle_id = ? ) AS E ON V.id = E.vehicle_id """ rows = self._query_list( query, tuple([vehicle_id] * 3), ) row = next(rows, None) if row is None: return None return self._window_from_row(row)
Find the given vehicle by its id.
vehicle_window_by_id
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_windows_in_range( self, exists_at_or_after: float, ends_before: float, minimum_vehicle_window: float, ) -> Generator[TrafficHistory.TrafficHistoryVehicleWindow, None, None]: """Find all vehicles active between the given history times.""" query = f"""SELECT V.id, V.type, V.length, V.width, V.height, S.position_x, S.position_y, S.heading_rad, S.speed, D.avg_speed, S.sim_time, E.sim_time, E.position_x, E.position_y, E.heading_rad FROM Vehicle AS V INNER JOIN ( SELECT vehicle_id, AVG(speed) as "avg_speed" FROM (SELECT vehicle_id, sim_time, speed from Trajectory WHERE sim_time >= ? AND sim_time < ?) GROUP BY vehicle_id ) AS D ON V.id = D.vehicle_id INNER JOIN ( {self._greatest_n_per_group_format( select='''vehicle_id, sim_time, speed, position_x, position_y, heading_rad''', table='Trajectory', group_by='vehicle_id', greatest_of_group='sim_time', where='sim_time >= ?', operation="MIN" )} ) AS S ON V.id = S.vehicle_id INNER JOIN ( {self._greatest_n_per_group_format( select='''vehicle_id, sim_time, speed, position_x, position_y, heading_rad''', table='Trajectory', group_by='vehicle_id', greatest_of_group='sim_time', where='sim_time < ?' )} ) AS E ON V.id = E.vehicle_id WHERE E.sim_time - S.sim_time >= ? GROUP BY V.id ORDER BY S.sim_time """ rows = self._query_list( query, ( exists_at_or_after, ends_before, exists_at_or_after, ends_before, minimum_vehicle_window, ), ) seen = set() seen_pos_x = set() rs = list() def _window_from_row_debug(row): nonlocal seen, seen_pos_x, rs r = self._window_from_row(row) assert r.vehicle_id not in seen assert r.end_time - r.start_time >= minimum_vehicle_window assert r.start_time >= exists_at_or_after assert r.end_time <= ends_before assert r.end_position_x not in seen_pos_x seen_pos_x.add(r.end_position_x) seen.add(r.vehicle_id) rs.append(r) return r return (_window_from_row_debug(row) for row in rows)
Find all vehicles active between the given history times.
vehicle_windows_in_range
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def vehicle_trajectory( self, vehicle_id: str ) -> Generator[TrafficHistory.TrajectoryRow, None, None]: """Get the trajectory of the specified vehicle""" query = """SELECT T.position_x, T.position_y, T.heading_rad, T.speed FROM Trajectory AS T WHERE T.vehicle_id = ?""" rows = self._query_list(query, (vehicle_id,)) return (TrafficHistory.TrajectoryRow(*row) for row in rows)
Get the trajectory of the specified vehicle
vehicle_trajectory
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def random_overlapping_sample( self, vehicle_start_times: Dict[str, float], k: int ) -> Set[str]: """Grab a sample containing a subset of specified vehicles and ensure overlapping time intervals across sample. Note: this may return a sample with less than k if we're unable to find k overlapping. """ # This is inefficient, but it's not that important choice = random.choice(list(vehicle_start_times.keys())) sample = {choice} sample_start_time = vehicle_start_times[choice] sample_end_time = self.vehicle_final_exit_time(choice) while len(sample) < k: choices = list(vehicle_start_times.keys()) if len(choices) <= len(sample): break choice = str(random.choice(choices)) sample_start_time = min(vehicle_start_times[choice], sample_start_time) sample_end_time = max(self.vehicle_final_exit_time(choice), sample_end_time) sample.add(choice) return sample
Grab a sample containing a subset of specified vehicles and ensure overlapping time intervals across sample. Note: this may return a sample with less than k if we're unable to find k overlapping.
random_overlapping_sample
python
huawei-noah/SMARTS
smarts/core/traffic_history.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/traffic_history.py
MIT
def apply_tire_forces(self, chassis, client, action): """Applies tire forces""" raise NotImplementedError
Applies tire forces
apply_tire_forces
python
huawei-noah/SMARTS
smarts/core/tire_models.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/tire_models.py
MIT
def build_tire_model(stiffness, tire_model_type, road_friction): """Generates the requested tire model.""" if tire_model_type == "LinearTireforce(wheel)": return LinearTireForces(stiffness, road_friction) elif tire_model_type == "LinearTireforce(contact)": return LinearTireForcesContact(stiffness, road_friction) elif tire_model_type == "NonlinearTireForces(wheel)": return NonlinearTireForces(stiffness, road_friction) elif tire_model_type == "NonlinearTireForces(contact)": return NonlinearTireForcesContact(stiffness, road_friction) else: raise Exception("Requested tire force model does not exist.")
Generates the requested tire model.
build_tire_model
python
huawei-noah/SMARTS
smarts/core/tire_models.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/tire_models.py
MIT
def apply_tire_forces(self, chassis, client, action): """Applies linear tire forces""" wheel_index = [2, 4, 5, 6] wheel_positions = [ np.array(client.getLinkState(chassis.bullet_id, wheel_idx)[0]) for wheel_idx in wheel_index ] # Final Bounds for forces at wheels for cases # that the rise and fall filters are used at wheels. bounds = [15e4, 15e4, 2e5, 2e5] forces, lat_forces, lon_forces = self._calculate_tire_forces( chassis, client, action ) for idx in range(len(wheel_index)): client.applyExternalForce( chassis.bullet_id, 0, np.clip(forces[idx], -bounds[idx], bounds[idx]), wheel_positions[idx], client.WORLD_FRAME, ) return (lat_forces, lon_forces)
Applies linear tire forces
apply_tire_forces
python
huawei-noah/SMARTS
smarts/core/tire_models.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/tire_models.py
MIT
def init_with_defaults( cls, length: float, width: float, height: float, defaults: Dimensions ) -> Dimensions: """Create with the given default values""" if not length or length == -1: length = defaults.length if not width or width == -1: width = defaults.width if not height or height == -1: height = defaults.height return cls(length, width, height)
Create with the given default values
init_with_defaults
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def copy_with_defaults(cls, dims: Dimensions, defaults: Dimensions) -> Dimensions: """Make a copy of the given dimensions with a default option.""" return cls.init_with_defaults(dims.length, dims.width, dims.height, defaults)
Make a copy of the given dimensions with a default option.
copy_with_defaults
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_lwh(self) -> Tuple[float, float, float]: """Convert to a tuple consisting of (length, width, height).""" return (self.length, self.width, self.height)
Convert to a tuple consisting of (length, width, height).
as_lwh
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def equal_if_defined(self, length: float, width: float, height: float) -> bool: """Test if dimensions are matching.""" return ( (not self.length or self.length == -1 or self.length == length) and (not self.width or self.width == -1 or self.width == width) and (not self.height or self.height == -1 or self.height == height) )
Test if dimensions are matching.
equal_if_defined
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_np_array(cls, np_array: np.ndarray) -> Point: """Factory for constructing a Point object from a numpy array.""" assert 2 <= len(np_array) <= 3 z = np_array[2] if len(np_array) > 2 else 0.0 return cls(float(np_array[0]), float(np_array[1]), float(z))
Factory for constructing a Point object from a numpy array.
from_np_array
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_np_array(self) -> np.ndarray: """Convert this Point to a read-only numpy array and cache the result.""" # Since this happens frequently and numpy array construction # involves memory allocation, we include this convenience method # with a cache of the result. # Note that before python3.8, @cached_property was not thread safe, # nor can it be used in a NamedTuple (which doesn't have a __dict__). # (Points can be used by multi-threaded client code, even when # SMARTS is still single-threaded, so we want to be safe here.) # So we use the private global _numpy_points as a cache instead. # Here we are relying on CPython's implementation of dict # to be thread-safe. cached = _numpy_points.get(self) if cached is not None: return cached npt = np.array((self.x, self.y, self.z)) # the array shouln't be changed independently of this Point object now... npt.setflags(write=False) _numpy_points[self] = npt return npt
Convert this Point to a read-only numpy array and cache the result.
as_np_array
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_shapely(self) -> SPoint: """Use with caution! Convert this point to a shapely point.""" # Shapely Point construction is expensive! # Note that before python3.8, @cached_property was not thread safe, # nor can it be used in a NamedTuple (which doesn't have a __dict__). # (Points can be used by multi-threaded client code, even when # SMARTS is still single-threaded, so we want to be safe here.) # So we use the private global _shapely_points as a cache instead. # Here we are relying on CPython's implementation of dict # to be thread-safe. cached = _shapely_points.get(self) if cached: return cached spt = SPoint((self.x, self.y, self.z)) _shapely_points[self] = spt return spt
Use with caution! Convert this point to a shapely point.
as_shapely
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def length(self): """The length of the box.""" return self.max_pt.x - self.min_pt.x
The length of the box.
length
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def width(self): """The width of the box.""" return self.max_pt.y - self.min_pt.y
The width of the box.
width
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def height(self): """The height of the box.""" return self.max_pt.z - self.min_pt.z
The height of the box.
height
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def center(self): """The center point of the box.""" return Point( x=(self.min_pt.x + self.max_pt.x) / 2, y=(self.min_pt.y + self.max_pt.y) / 2, z=(self.min_pt.z + self.max_pt.z) / 2, )
The center point of the box.
center
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_dimensions(self) -> Dimensions: """The box dimensions. This will lose offset information.""" return Dimensions(length=self.length, width=self.width, height=self.height)
The box dimensions. This will lose offset information.
as_dimensions
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def contains(self, pt: Point) -> bool: """Determines if the given point is within this bounding box. If any bounding box coordinates are None, it is considered unbounded on that dimension/axis. Args: pt (Point): The point to test against. Returns: True if pt is fully within the bounding box.""" return ( self.min_pt is None or (self.min_pt.x is None or self.min_pt.x < pt.x) and (self.min_pt.y is None or self.min_pt.y < pt.y) ) and ( self.max_pt is None or (self.max_pt.x is None or pt.x < self.max_pt.x) and (self.max_pt.y is None or pt.y < self.max_pt.y) )
Determines if the given point is within this bounding box. If any bounding box coordinates are None, it is considered unbounded on that dimension/axis. Args: pt (Point): The point to test against. Returns: True if pt is fully within the bounding box.
contains
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def __new__( self, x: Union[SupportsFloat, SupportsIndex, Ellipsis.__class__] = ... ) -> Heading: """A override to constrain heading to -pi to pi""" value = x if isinstance(value, (int, float)): value = value % (2 * math.pi) if value > math.pi: value -= 2 * math.pi if x in {..., None}: value = 0 return float.__new__(self, value)
A override to constrain heading to -pi to pi
__new__
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_bullet(cls, bullet_heading) -> Heading: """Bullet's space is in radians, 0 faces north, and turns counter-clockwise. """ h = Heading(bullet_heading) h._source = "bullet" return h
Bullet's space is in radians, 0 faces north, and turns counter-clockwise.
from_bullet
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_panda3d(cls, p3d_heading) -> Heading: """Panda3D's space is in degrees, 0 faces north, and turns counter-clockwise. """ h = Heading(math.radians(p3d_heading)) h._source = "p3d" return h
Panda3D's space is in degrees, 0 faces north, and turns counter-clockwise.
from_panda3d
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_sumo(cls, sumo_heading) -> Heading: """Sumo's space uses degrees, 0 faces north, and turns clockwise.""" heading = Heading.flip_clockwise(math.radians(sumo_heading)) h = Heading(heading) h._source = "sumo" return h
Sumo's space uses degrees, 0 faces north, and turns clockwise.
from_sumo
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def source(self) -> Optional[str]: """The source of this heading.""" return getattr(self, "_source", None)
The source of this heading.
source
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_panda3d(self) -> float: """Convert to Panda3D facing format.""" return math.degrees(self)
Convert to Panda3D facing format.
as_panda3d
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_bullet(self) -> Heading: """Convert to bullet physics facing format.""" return self
Convert to bullet physics facing format.
as_bullet
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_sumo(self) -> float: """Convert to SUMO facing format""" return math.degrees(Heading.flip_clockwise(self))
Convert to SUMO facing format
as_sumo
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def relative_to(self, other: Heading) -> Heading: """ Computes the relative heading w.r.t. the given heading >>> Heading(math.pi/4).relative_to(Heading(math.pi)) Heading(-2.356194490192345) """ assert isinstance(other, Heading) rel_heading = Heading(self - other) assert -math.pi <= rel_heading <= math.pi, f"{rel_heading}" return Heading(rel_heading)
Computes the relative heading w.r.t. the given heading >>> Heading(math.pi/4).relative_to(Heading(math.pi)) Heading(-2.356194490192345)
relative_to
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def direction_vector(self) -> np.ndarray: """Convert to a 2D directional vector that aligns with Cartesian Coordinate System""" return radians_to_vec(self)
Convert to a 2D directional vector that aligns with Cartesian Coordinate System
direction_vector
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def flip_clockwise(x): """Converts clockwise to counter-clockwise, and vice-versa.""" return (2 * math.pi - x) % (2 * math.pi)
Converts clockwise to counter-clockwise, and vice-versa.
flip_clockwise
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def reset_with(self, position, heading: Heading): """Resets the pose with the given position and heading values.""" if self.position.dtype is not np.dtype(np.float64): # The slice assignment below doesn't change self.position's dtype, # which can be a problem if it was initialized with ints and # now we are assigning it floats, so we just cast it... self.position = np.float64(self.position) self.position[:] = position if "point" in self.__dict__: # clear the cached_property del self.__dict__["point"] if "position_tuple" in self.__dict__: del self.__dict__["position_tuple"] if heading != self.heading_: self.orientation = fast_quaternion_from_angle(heading) self.heading_ = heading
Resets the pose with the given position and heading values.
reset_with
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def point(self) -> Point: """The positional value of this pose as a point.""" return Point.from_np_array(self.position)
The positional value of this pose as a point.
point
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def position_tuple(self) -> Tuple[Optional[float], ...]: """The position value of this pose as a tuple.""" return tuple(self.point)
The position value of this pose as a tuple.
position_tuple
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_front_bumper(cls, front_bumper_position, heading, length) -> Pose: """Convert from front bumper location to a Pose with center of vehicle. Args: front_bumper_position: The (x, y) position of the center front of the front bumper heading: The heading of the pose length: The length dimension of the object's physical bounds """ assert isinstance(front_bumper_position, np.ndarray) assert front_bumper_position.shape == (2,), f"{front_bumper_position.shape}" _orientation = fast_quaternion_from_angle(heading) lwh_offset = radians_to_vec(heading) * (0.5 * length) pos_2d = front_bumper_position - lwh_offset return cls( position=np.array([pos_2d[0], pos_2d[1], 0]), orientation=_orientation, heading_=heading, )
Convert from front bumper location to a Pose with center of vehicle. Args: front_bumper_position: The (x, y) position of the center front of the front bumper heading: The heading of the pose length: The length dimension of the object's physical bounds
from_front_bumper
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_center(cls, base_position: Collection[float], heading: Heading) -> Pose: """Convert from centered location Args: base_position: The center of the object's bounds heading: The heading of the object """ assert isinstance(heading, Heading) position = np.array([*base_position, 0][:3]) orientation = fast_quaternion_from_angle(heading) return cls( position=position, orientation=orientation, heading_=heading, )
Convert from centered location Args: base_position: The center of the object's bounds heading: The heading of the object
from_center
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def from_explicit_offset( cls, offset_from_center, base_position: np.ndarray, heading: Heading, local_heading: Heading, ) -> Pose: """Convert from an explicit offset Args: offset_from_center: The offset away from the center of the object's bounds heading: The heading of the pose base_position: The base position without offset local_heading: An additional orientation that re-faces the center offset """ assert isinstance(heading, Heading) assert isinstance(base_position, np.ndarray) orientation = fast_quaternion_from_angle(heading) oprime = heading + local_heading # Calculate rotation on xy-plane only, given that fast_quaternion_from_angle is also on xy-plane vprime = np.array( [ offset_from_center[0] * np.cos(oprime) - offset_from_center[1] * np.sin(oprime), offset_from_center[0] * np.sin(oprime) + offset_from_center[1] * np.cos(oprime), offset_from_center[2], ] ) position = base_position + vprime return cls(position=position, orientation=orientation, heading_=heading)
Convert from an explicit offset Args: offset_from_center: The offset away from the center of the object's bounds heading: The heading of the pose base_position: The base position without offset local_heading: An additional orientation that re-faces the center offset
from_explicit_offset
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_sumo(self, length, local_heading): """Convert to SUMO (position of front bumper, cw_heading) args: heading: The heading of the pose length: The length dimension of the object's physical bounds local_heading: An additional orientation that re-faces the length offset """ vprime = radians_to_vec(self.heading + local_heading) * 0.5 * length return ( np.array([self.position[0] + vprime[0], self.position[1] + vprime[1], 0]), self.heading.as_sumo, )
Convert to SUMO (position of front bumper, cw_heading) args: heading: The heading of the pose length: The length dimension of the object's physical bounds local_heading: An additional orientation that re-faces the length offset
as_sumo
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_bullet(self) -> Tuple[np.ndarray, np.ndarray]: """Convert to bullet origin (position of bullet origin, orientation quaternion""" return (self.position, self.orientation)
Convert to bullet origin (position of bullet origin, orientation quaternion
as_bullet
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def heading(self) -> Heading: """The heading value converted from orientation.""" # XXX: changing the orientation should invalidate this if self.heading_ is None: yaw = yaw_from_quaternion(self.orientation) self.heading_ = Heading(yaw) return self.heading_
The heading value converted from orientation.
heading
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_position2d(self) -> np.ndarray: """Convert to a 2d position array""" return self.position[:2]
Convert to a 2d position array
as_position2d
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def as_panda3d(self) -> Tuple[np.ndarray, float]: """Convert to panda3D (object bounds center position, heading)""" return (self.position, self.heading.as_panda3d)
Convert to panda3D (object bounds center position, heading)
as_panda3d
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def origin(cls) -> Pose: """Pose at the origin coordinate of smarts.""" return cls(np.repeat([0], 3), np.array([0, 0, 0, 1]))
Pose at the origin coordinate of smarts.
origin
python
huawei-noah/SMARTS
smarts/core/coordinates.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/coordinates.py
MIT
def source(self) -> str: """The road map resource source. Generally a file URI.""" raise NotImplementedError()
The road map resource source. Generally a file URI.
source
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def bounding_box(self) -> Optional[BoundingBox]: """The minimum bounding box that contains the map geometry. May return `None` to indicate the map is unbounded. """ raise NotImplementedError()
The minimum bounding box that contains the map geometry. May return `None` to indicate the map is unbounded.
bounding_box
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def has_overpasses(self) -> bool: """Whether the map has lanes with overlapping z-coordinates.""" return False
Whether the map has lanes with overlapping z-coordinates.
has_overpasses
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def scale_factor(self) -> float: """The ratio between 1 unit on the map and 1 meter.""" # map units per meter return 1.0
The ratio between 1 unit on the map and 1 meter.
scale_factor
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def dynamic_features(self) -> List[RoadMap.Feature]: """All dynamic features associated with this road map.""" return []
All dynamic features associated with this road map.
dynamic_features
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def map_spec(self): """The map spec that could be used to reconstruct the map.""" return getattr(self, "_map_spec", None)
The map spec that could be used to reconstruct the map.
map_spec
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def is_same_map(self, map_spec) -> bool: """Check if the MapSpec Object source points to the same RoadMap instance as the current""" raise NotImplementedError
Check if the MapSpec Object source points to the same RoadMap instance as the current
is_same_map
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def to_glb(self, glb_dir: str): """Build a `.glb` file for camera rendering and envision""" raise NotImplementedError()
Build a `.glb` file for camera rendering and envision
to_glb
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def surface_by_id(self, surface_id: str) -> Optional[RoadMap.Surface]: """Find a surface within the road map that has the given identifier.""" raise NotImplementedError()
Find a surface within the road map that has the given identifier.
surface_by_id
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def lane_by_id(self, lane_id: str) -> Optional[RoadMap.Lane]: """Find a lane in this road map that has the given identifier.""" raise NotImplementedError()
Find a lane in this road map that has the given identifier.
lane_by_id
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def road_by_id(self, road_id: str) -> Optional[RoadMap.Road]: """Find a road in this road map that has the given identifier.""" raise NotImplementedError()
Find a road in this road map that has the given identifier.
road_by_id
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def feature_by_id(self, feature_id: str) -> Optional[RoadMap.Feature]: """Find a feature in this road map that has the given identifier.""" raise NotImplementedError()
Find a feature in this road map that has the given identifier.
feature_by_id
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def dynamic_features_near( self, point: Point, radius: float ) -> List[Tuple[RoadMap.Feature, float]]: """Find features within radius meters of the given point.""" result = [] for feat in self.dynamic_features: dist = feat.min_dist_from(point) if dist <= radius: result.append((feat, dist)) return result
Find features within radius meters of the given point.
dynamic_features_near
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def nearest_surfaces( self, point: Point, radius: Optional[float] = None ) -> List[Tuple[RoadMap.Surface, float]]: """Find surfaces (lanes, roads, etc.) on this road map that are near the given point.""" raise NotImplementedError()
Find surfaces (lanes, roads, etc.) on this road map that are near the given point.
nearest_surfaces
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def nearest_lanes( self, point: Point, radius: Optional[float] = None, include_junctions=True ) -> List[Tuple[RoadMap.Lane, float]]: """Find lanes on this road map that are near the given point. Returns a list of tuples of lane and distance, sorted by distance.""" raise NotImplementedError()
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_lanes
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def nearest_lane( self, point: Point, radius: Optional[float] = None, include_junctions=True ) -> RoadMap.Lane: """Find the nearest lane on this road map to the given point.""" nearest_lanes = self.nearest_lanes(point, radius, include_junctions) return nearest_lanes[0][0] if nearest_lanes else None
Find the nearest lane on this road map to the given point.
nearest_lane
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def road_with_point( self, point: Point, *, lanes_to_search: Optional[Sequence["RoadMap.Lane"]] = None, ) -> Optional[RoadMap.Road]: """Find the road that contains the given point. Args: point: The point to check. 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.""" raise NotImplementedError()
Find the road that contains the given point. Args: point: The point to check. 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.
road_with_point
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def generate_routes( self, start: Union["RoadMap.Road", "RoadMap.Lane"], end: Union["RoadMap.Road", "RoadMap.Lane"], via: Optional[Sequence[RoadMap.Road]] = None, max_to_gen: int = 1, ) -> List[RoadMap.Route]: """Generates routes between two roads. Args: start: The beginning road or lane of the generated routes. end: The end road or lane of the generated routes. via: All edges that the generated routes must pass through. max_to_gen: The maximum number of routes to generate. Returns: A list of generated routes that satisfy the given restrictions. Routes will be returned in order of increasing length. """ if isinstance(start, RoadMap.Lane): start_lane = start start_road = start.road else: start_lane = None start_road = start if isinstance(end, RoadMap.Lane): end_lane = end end_road = end.road else: end_lane = None end_road = end return self._generate_routes( start_road=start_road, start_lane=start_lane, end_road=end_road, end_lane=end_lane, via=via, max_to_gen=max_to_gen, )
Generates routes between two roads. Args: start: The beginning road or lane of the generated routes. end: The end road or lane of the generated routes. via: All edges that the generated routes must pass through. max_to_gen: The maximum number of routes to generate. Returns: A list of generated routes that satisfy the given restrictions. Routes will be returned in order of increasing length.
generate_routes
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def random_route( self, max_route_len: int = 10, starting_road: Optional[RoadMap.Road] = None, only_drivable: bool = True, ) -> RoadMap.Route: """Generate a random route contained in this road map. :param max_route_len: The total number of roads in the route. :param starting_road: If specified, the route will start with this road. :param only_drivable: If True, will restrict the route to only drive-able roads; otherwise can incl. non-drivable roads (such as bike lanes) too. :return: A randomly generated route. """ raise NotImplementedError()
Generate a random route contained in this road map. :param max_route_len: The total number of roads in the route. :param starting_road: If specified, the route will start with this road. :param only_drivable: If True, will restrict the route to only drive-able roads; otherwise can incl. non-drivable roads (such as bike lanes) too. :return: A randomly generated route.
random_route
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def empty_route(self) -> RoadMap.Route: """Generate an empty route.""" raise NotImplementedError()
Generate an empty route.
empty_route
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT
def route_from_road_ids( self, road_ids: Sequence[str], resolve_intermediaries: bool = False ) -> RoadMap.Route: """Generate a route containing the specified roads. Args: road_ids (Sequence[str]): The road ids of the route. resolve_intermediaries (bool): If to fill in the gaps in the route. This may be needed to complete an incomplete route or fill in junctions roads. Returns: A route that satisfies the given road id restrictions. """ raise NotImplementedError()
Generate a route containing the specified roads. Args: road_ids (Sequence[str]): The road ids of the route. resolve_intermediaries (bool): If to fill in the gaps in the route. This may be needed to complete an incomplete route or fill in junctions roads. Returns: A route that satisfies the given road id restrictions.
route_from_road_ids
python
huawei-noah/SMARTS
smarts/core/road_map.py
https://github.com/huawei-noah/SMARTS/blob/master/smarts/core/road_map.py
MIT