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
from os.path import join
from pathlib import Path
import numpy as np
from polaris.utils.file_utils import read_file
from polaris.utils.testing.temp_model import TempModel
from SVTrip.svtrip import SVTrip
from SVTrip.tpms.tpms import TPMs
Create an SVTrip class object and initialize with relevant parameters
svtrip = SVTrip()
svtrip.parameters.execution.n_workers = 16
svtrip.parameters.execution.jobs_per_thread = 15
Define where to store the outputs and create the folder
model_dir = TempModel("Grid")
iteration_dir = model_dir / "Grid_iteration_1"
output_dir = iteration_dir / f"sv_trip_output"
output_dir.mkdir()
(output_dir / f"based_on_{iteration_dir.name}").touch()
svtrip.parameters.output.export_folder = output_dir
Load demand and supply files from POLARIS
svtrip.load_trips_from_polaris(model_dir / "Grid-Demand.sqlite", model_dir / "Grid-Supply.sqlite")
/venv-py312/lib/python3.12/site-packages/SVTrip/trips/polaris_reader.py:66: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
trips.sort_values(by=["tripID", "segmentID"], inplace=True)
Set a random seed for the stochastic speed profile generation
np.random.seed(123)
svtrip.run()

[ INFO] 07:32:03: Running multi-threaded code
[ INFO] 07:32:03: 2,927/35,329 unique trips/segments found
[ INFO] 07:32:03: Building data structures
[ INFO] 07:32:03: Data divided in 226 jobs with 13 trips each
[ INFO] 07:32:03: Process is being setup to run on 16 separate threads
[ INFO] 07:32:03: Starting data processing
[ INFO] 07:33:42: Starting consolidating of smart workflow outputs
[ INFO] 07:33:42: Looking for /tmp/polaris_studio_testing/2025-09-24_07-32-02--8120/Grid_iteration_1/sv_trip_output/svtrip_output_*.h5 files
[ INFO] 07:33:42: Found 16 such files
Converting H5 -> Matlab: 0%| | 0/16 [00:00<?, ?it/s]
Converting H5 -> Matlab: 6%|▋ | 1/16 [00:01<00:17, 1.16s/it]
Converting H5 -> Matlab: 69%|██████▉ | 11/16 [00:01<00:00, 8.74it/s]
Converting H5 -> Matlab: 100%|██████████| 16/16 [00:01<00:00, 9.96it/s]
[ INFO] 07:33:46:
[ INFO] 07:33:46: =========================================================
[ INFO] 07:33:46: Finished multiprocessing, consolidating logs generated by
[ INFO] 07:33:46: subprocessing threads into main thread log file
[ INFO] 07:33:46:
[ INFO] 07:33:46: =========================================================
[ INFO] 07:33:46:
[ INFO] 07:33:46: Total run time: 0:01:43.210086
[ INFO] 07:33:46: Process finished
Total running time of the script: (1 minutes 44.843 seconds)