symupy.utils package¶
Subpackages¶
Submodules¶
symupy.utils.configurator module¶
This module contains a Configurator
object.
The configurator is an object that stores parameters that can be
relevant to make the evolution of a simulation. The objective is to
introduce flexibility when configuring the the simulator platform
and the runtime execution possibilities offered by exposed functions
from the c library of SymuFlow
- class symupy.utils.configurator.Configurator(**kwargs)[source]¶
Bases:
object
Configurator class for containing specific simulator parameters .. rubric:: Example
To use the
Simulator
declare in a string thepath
to the simulator>>> path = "path/to/libSymuyVia.dylib" >>> simulator = Configurator(library_path = path)
- Parameters
library_path (str) – Absolute path towards the simulator library
bufferSize (int) – Size of the buffer for message for data received from simulator
write_xml (bool) – Flag to turn on writting the XML output
trace_flow (bool) – Flag to determine tracing or not the flow / trajectories
total_steps (int) – Define the number of iterations of a simulation
step_launch_mode (str) – Determine to way to launch the
RunStepEx
. Optionslite
/full
- Returns
Configurator object with simulation parameters
- Return type
- buffer_string: ctypes.c_char = <ctypes.c_char_Array_1000000 object>¶
- library_path: str = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/symupy/conda/stable/lib/libSymuFlow.so')¶
- step_launch_mode: str = 'lite'¶
- total_steps: int = 0¶
- trace_flow: bool = False¶
- write_xml: ctypes.c_bool = c_bool(False)¶
symupy.utils.constants module¶
This module contains a constants and default parameters.
These parameters can be accessed at any time by whatever of the modules.
Example
To use the Constants
import the module as:
>>> import symupy.utils.constants as ct
>>> ct.BUFFER_STRING # access the buffer size
Variable |
Description |
|
Buffer size |
|
Default OS X library path |
|
Default Linux library path |
|
Vehicle trajectory data |
|
Trajectory data types |
|
Time format |
|
Format aggretations |
|
XML Simulation information |
|
XML Export information |
|
XML Traffic information |
|
XML Network information |
|
XML Scenario information |
|
Vehicle type information |
|
Vehicle acceleration boundaries |
symupy.utils.exceptions module¶
This module contains a set of exceptions and handlers for such exceptions.
Example
To use the Exceptions
import the module as:
>>> from symupy.utils.exceptions import SymupyLoadLibraryError
>>> from ctypes import cdll
>>> try:
... path = 'path/to/library'
... lib = cdll.LoadLibrary(path)
... except OSError:
... raise SymupyLoadLibraryError("Library not found",path)
- exception symupy.utils.exceptions.SymupyDriveVehicleError(error_message: str, target_dir: str = '')[source]¶
Bases:
symupy.utils.exceptions.SymupyError
Vehicle Drive Error exception handler, created for handling situations at runtime when the vehicles cannot be created within the network
- Returns
Vehicle Creation Error
- Return type
- exception symupy.utils.exceptions.SymupyError(error_message: str = '', *args)[source]¶
Bases:
Exception
General error exception, it can be raised at whatever moment, the class its intends to create a base class that intends to tag error situations dected by this module.
- Returns
General
SymupyError
exception handler- Return type
- property extra_args¶
suppelmentary arguments
- property get_message¶
message info
- exception symupy.utils.exceptions.SymupyFileLoadError(error_message: str, target_dir: str = '')[source]¶
Bases:
symupy.utils.exceptions.SymupyError
File Load Error exception handler, created for handling file situations in particular scenario situations
- Returns
File Load Error
- Return type
- exception symupy.utils.exceptions.SymupyLoadLibraryError(error_message: str, target_dir: str = '')[source]¶
Bases:
symupy.utils.exceptions.SymupyError
Load Library Error exception handler, created for handling library situations in particular when it is not possible to link the library and python
- Returns
Library Load Error
- Return type
- exception symupy.utils.exceptions.SymupyVehicleCreationError(error_message: str, target_dir: str = '')[source]¶
Bases:
symupy.utils.exceptions.SymupyError
Vehicle Creation Error exception handler, created for handling situations at runtime when the vehicles cannot be created within the network
- Returns
Vehicle Creation Error
- Return type
- class symupy.utils.exceptions.SymupyWarning(warning_message: str)[source]¶
Bases:
object
General warning exception, it can be raised at whatever moment, the class its intends to create a base class that intends to tag situations dected by this module.
- param Exception
General
SymupyWarning
exception handler- type Exception
SymupyWarning
symupy.utils.parser module¶
Stream Parser¶
This module handles the Simulation response converting it into proper formats for querying data afterwards.
The parser object converts a request from the simulator into the correct format for the
- class symupy.utils.parser.SimulatorRequest(**kwargs)[source]¶
Bases:
symupy.runtime.logic.publisher.Publisher
- property current_nbveh: int¶
- property current_time: float¶
- property data_query¶
Direct parsing from the string buffer
- Returns
Simulator data parsed from XML
- Return type
simdata (OrderedDict)
- filter_vehicle_property(property: str, *args)[source]¶
Filter out a property for a subset of vehicles
- Parameters
property (str) – one of the following options abscissa, acceleration, distance, elevation, lane, link, ordinate, speed, vehid, vehtype,
vehids (int) – separate the
vehid
via commas to get the corresponding property
- get_vehicle_data() tuple [source]¶
Extracts vehicles information from simulators response
- Returns
list of dictionaries containing vehicle data with correct formatting
- Return type
t_veh_data (list)
- get_vehicle_in_link() dict [source]¶
Get a map of vehicle ids and their correspnding link.
- Returns
zone - ids of vehicles
- Return type
map (dict)
- get_vehicle_properties(vehid: int) dict [source]¶
Return all properties for a given vehicle id
- Returns
Dictionary with all vehicle properties
- Return type
vehdata (dict)
- get_vehicles_property(property_key: str) tuple [source]¶
Extracts a specific property and returns a tuple containing this property for all vehicles in the buffer string
- Parameters
property_key (str) – one of the following options abscissa, acceleration, distance, elevation, lane, link, ordinate, speed, vehid, vehtype,
- Returns
tuple with corresponding values e.g (0,1), (0,),(None,)
- Return type
values (tuple)
- is_vehicle_driven(vehid: int) bool [source]¶
Returns true if the vehicle state is exposed to a driven state
- Parameters
vehid (str) – vehicle id
- Returns
True if veh is driven
- Return type
driven (bool)
- is_vehicle_in_link(veh: int, link: str) bool [source]¶
Returns true if a vehicle is in a link at current state
- Parameters
vehid (int) – vehicle id
link (str) – link name
- Returns
True if veh is in link
- Return type
present (bool)
- is_vehicle_in_network(vehid: int, *args) bool [source]¶
True if veh id is in the network at current state, for multiple arguments. True if all veh ids are in the network.
- Parameters
vehid (int) – Integer of vehicle id, comma separated if testing for multiple
- Returns
True if vehicle is in the network otherwise false.
- Return type
present (bool)
- property query¶
String response from the simulator
- vehicle_downstream_of(vehid: int) tuple [source]¶
Get ids of vehicles downstream to vehid
- Parameters
vehid (str) – vehicle id
- Returns
vehicles downstream of vehicle id
- Return type
vehid (tuple)
symupy.utils.screen module¶
Screen log¶
This module serves as a printer for main class messages like log, warnings, errors, check messages.
- symupy.utils.screen.log_in_terminal(message: str, *args, **kwargs) None [source]¶
This function logs in the terminal a message with a specific color
- Parameters
message (str) – Message to log on the console
foreground (str) – Foreground color see click.style for options
- symupy.utils.screen.log_success(message, *args, **kwargs) None [source]¶
Logs a success message in green
symupy.utils.time module¶
- class symupy.utils.time.Date(date)[source]¶
Bases:
object
Short summary.
- Parameters
date (type) – Description of parameter date.
- hours¶
Description of attribute hours.
- Type
type
- minutes¶
Description of attribute minutes.
- Type
type
- seconds¶
Description of attribute seconds.
- Type
type
- _total_sec¶
Description of attribute _total_sec.
- Type
type
- _significant_digit¶
Description of attribute _significant_digit.
- Type
type
- _date¶
Description of attribute _date.
- Type
type
symupy.utils.tools module¶
This module contains a series of decorators in order to add logging functionalities to some of the class methods. The decorators are regularly purposed for logging, printing, neutering funcitons. etc.
- symupy.utils.tools.conditional(cond: bool, warning: str = '') Callable [source]¶
Disables the execution of the decorated method/function
- Parameters
cond (bool) – Flag to execute
warning (str, optional) – Warning to login. Defaults to “”.
- Returns
Wrapped method
- Return type
Callable
- symupy.utils.tools.logger_func(orig_func: Callable)[source]¶
Logs execution of a function/method and arguments into a file called with the function name
- Parameters
orig_func (Callable) – A function/method to be logged
- Returns
Wrapped method after log
- Return type
(Callable)
- symupy.utils.tools.printer_time(orig_func: Callable) Callable [source]¶
Prints in terminal the current time step of a simulation.
- Parameters
orig_func (Callable) – Connector class containing the simulationstep status via an attribute. Decorated method is run_step
- Returns
Wrapped step execution
- Return type
Callable
symupy.utils.xmlgenerator module¶
This module computes/modifies data for XML creation for the simulator
- class symupy.utils.xmlgenerator.XMLGenerator(path_xsd: str = '')[source]¶
Bases:
object
A class to handle XML generator for SymuFlow
- namespace = 'noNamespaceSchemaLocation'¶
- nsmap = {'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}¶
- xmlns = 'http://www.w3.org/2001/XMLSchema-instance'¶
- symupy.utils.xmlgenerator.create_DCT_EXPORT_INFO(trace_rout: bool = False, trajectories: bool = True, csv: bool = True) dict [source]¶
Computes dictionary DCT_SCENARIO_INFO for XML file
- Parameters
trace_rout (bool) – trace routes True/False
trajectories (bool) – export trajectories True/False
csv (bool) – export trajectories in csv
- Returns
dictionary with metadata for xml creation
- Return type
dict
- symupy.utils.xmlgenerator.create_DCT_NETWORK_INFO(networkid: str) dict [source]¶
Computes dictionary DCT_NETWORK_INFO for XML file
- Parameters
networkid (str) – network identifier
- Returns
dict
- Return type
[type]
- symupy.utils.xmlgenerator.create_DCT_SCENARIO_INFO(scnid: str, dirout: str, prefout: str, dct_sim: dict, dct_traffic: dict, dct_network: dict) dict [source]¶
Computes dictionary DCT_SCENARIO_INFO for XML file
- Parameters
scnid (str) – Scenario identifier
dirout (str) – Output directory
prefout (str) – Prefix
dct_sim (dict) – DCT_SIMULATION_INFO
dct_traffic (dict) – DCT_TRAFIC_INFO
dct_network (dict) – DCT_NETWORK_INFO
- Returns
dictionary with metadata for xml creation
- Return type
dict
- symupy.utils.xmlgenerator.create_DCT_SIMULATION_INFO(title: str, simid: str, timestep: float, time_start: str, time_end: str, date: str, seed: int, cfl: str, flow: str, decel: bool) dict [source]¶
Computes dictionary DCT_SIMULATION_INFO header for XML file
- Parameters
title (str) – Simulation title
simid (str) – Simulation ID
timestep (float) – time step (seconds)
time_start (str) – start time H%:%M:%S
time_end (str) – start time H%:%M:%S
date (str) – simulation date Y%-%m-%d
seed (int) – random seed
cfl (str) – car following law
flow (str) – flow behaviour
decel (bool) – deceleration procedure activation
- Returns
dictionary with metadata for xml creation
- Return type
dict
- symupy.utils.xmlgenerator.create_DCT_TRAFIC_INFO(trafid: str, bounded_acc: bool = True, relaxation: float = 4, ghost_lanechange: bool = False) dict [source]¶
Computes dictionary DCT_TRAFIC_INFO for XML file
- Parameters
trafid (str) – traffic identifier
bounded_acc (bool) – bounds acceleration True/False
relaxation (float) – relaxation coefficient lane change
ghost_lanechange (bool) – keep lane change ghost True/False
- Returns
dictionary with metadata for xml creation
- Return type
dict
- symupy.utils.xmlgenerator.fix_values(element: lxml.etree.ElementTree, dct_values: dict) lxml.etree.ElementTree [source]¶
Fix a set of values within a dictionary as attributes of an XML subelement
- Parameters
element (ET.ElementTree) – XML tree element
dct_values (dict) – attributes to fix
- Returns
Tranformed XML tree element
- Return type
ET.ElementTree
Module contents¶
Expose specific functions for accessbility