This repository contains scripts and methods to convert a FCD (Floating Car Data) simulation output from SUMO to a TrajDataFrame
able to be used in scikit-mobility package.
External packages required are pandas and scikit-mobility (see installation guide). SUMO is required to perform the simulations.
- Get SUMO Network from OpenStreetMap
Since a TrajDataFrame
requires geographical coordinates of vehicle traces (latitude and longitude), we start building a network in SUMO from OSM with the built-in importer (see this tutorial). Once imported, the network should be up and running in your SUMO-gui interface.
- Build SUMO config file (.cfg)
We have to run the simulation through command line to get the Floating Car Data outputs (FCD). SUMO provides a .cfg file complete with all the information needed to run a simulation within the selected area and the time period. The minimum requirements of a SUMO configuration file are the network (.net.xml) and demand (.rou.xml) files:
<configuration>
<input>
<net-file value="<project name>.net.xml"/>
<route-files value="<project name>.rou.xml"/>
</input>
</configuration>
If you imported the network through OSM directly into SUMO, you should already find a .cfg file in the imported project folder. This is ready to be parsed by the SUMOtoTraj.py
script. For further configuration options please take a look at this page.
The script workflow takes the following steps:
- Run a SUMO simulation according to .cfg file
- Convert FCD .xml file to a FCD .csv file
- Convert the .csv file into a DataFrame and
TrajDataFrame
Just put the script into your working directory (or point it to the path of the script) and run:
$ python SUMOtoTraj.py project_name outputfile_name vehicle_sample
where:
- project_name is the name of the .cfg file
- outputfile_name is the name of the FCD output file generated by SUMO
- vehicle_sample (float) is the desired set of vehicles which generate fcd output (0 to 1, all vehicles)
The script returns:
- a outputfile_name.xml FCD file
- a outputfile_name.csv FCD file
- a
TrajDataFrame
You may find some examples of running the script and working with a TrajDataFrame
in the notebook page