Note
Go to the end to download the full example code.
Create speed profiles from POLARIS trajectories#
In this example, we show how to post-process POLARIS outputs to obtain speed profiles from SVTrip which can be used as an input into Autonomie Express
Note: This is not needed if using Autonomie AI
SVTrip is a post-processing tool designed to take these vehicle trajectories (link-level data) and generate second-by-second speed profiles.
SVTrip supports two primary input methods: - CSV Trajectory File Input: A pre-processed .csv trajectory file - old versions of POLARIS / polaris-studio create these files - POLARIS Inputs (Supply, Demand, Result H5): Trip data is stored in POLARIS Demand databases, whereas trajectories associated with those trips are available in the Result H5. All files are needed to process the final input to SVTrip
More details can be found at: https://vms.taps.anl.gov/tools/svtrip/
Imports#
import logging
import numpy as np
from SVTrip.svtrip import SVTrip
from SVTrip.tpms.tpms import TPMs
from polaris import Polaris
from polaris.utils.testing.temp_model import TempModel
Define where to store the outputs and create the folder
model_dir = TempModel("Grid")
pol = Polaris.from_dir(model_dir)
output_dir = model_dir / f"sv_trip_output"
output_dir.mkdir()
Create an SVTrip class object and initialize with relevant parameters
svtrip = SVTrip(pol.demand_file, pol.supply_file, pol.result_h5_file, logging_level=logging.DEBUG)
svtrip.parameters.execution.n_workers = 5 # SVTrip scales very well, but Windows has a limit of 60 threads
svtrip.parameters.execution.jobs_per_thread = 15
svtrip.parameters.output.export_folder = output_dir
Load demand and supply files from POLARIS
svtrip._load_data_from_polaris() # loads trips and trajectories from POLARIS outputs
SVTrip is very resource intensive, so we will limit the number of vehicles to process Let’s only process the first 9 trips for this example, otherwise it takes too long to run Remember to remove this line if you want to do a full run from your POLARIS outputs
svtrip.isolate_trips(range(1, 10))
Set a random seed for the stochastic speed profile generation
np.random.seed(123)
svtrip.run()
[ INFO] 11:11:06: Running multi-threaded code
[ INFO] 11:11:06: 9 unique trips
[ INFO] 11:11:06: Building data structures
[ INFO] 11:11:06: Data divided in 9 jobs with 1 trips each
[ INFO] 11:11:06: Process is being setup to run on 5 separate threads
[ INFO] 11:11:06: Starting data processing
[ INFO] 11:11:13: Starting consolidating of smart workflow outputs
[ INFO] 11:11:13: Looking for /tmp/polaris_studio_testing/2025-12-01_11-10-41--956800c079d4/sv_trip_output/svtrip_output_*.h5 files
[ INFO] 11:11:13: Found 2 such files
Converting H5 -> Matlab: 0%| | 0/2 [00:00<?, ?it/s]
Converting H5 -> Matlab: 50%|█████ | 1/2 [00:00<00:00, 1.48it/s]
Converting H5 -> Matlab: 100%|██████████| 2/2 [00:00<00:00, 2.95it/s]
[ INFO] 11:11:14:
[ INFO] 11:11:14: =========================================================
[ INFO] 11:11:14: Finished multiprocessing, consolidating logs generated by
[ INFO] 11:11:14: subprocessing threads into main thread log file
[ INFO] 11:11:14:
[ INFO] 11:11:14: =========================================================
[ INFO] 11:11:14:
[ INFO] 11:11:14: Total run time: 0:00:07.937631
[ INFO] 11:11:14: Process finished
Total running time of the script: (0 minutes 34.361 seconds)


