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
2025-09-03 21:38:20 UTC+0000 - Upgrading Freight database at location /tmp/polaris_studio_testing/2025-09-03_21-38-20--7087/Grid-Freight.sqlite
2025-09-03 21:38:20 UTC+0000 - Upgrading Demand database at location /tmp/polaris_studio_testing/2025-09-03_21-38-20--7087/Grid-Demand.sqlite
2025-09-03 21:38:20 UTC+0000 - Upgrading Supply database at location /tmp/polaris_studio_testing/2025-09-03_21-38-20--7087/Grid-Supply.sqlite
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] 21:38:21: Running multi-threaded code
[ INFO] 21:38:21: 1,929/24,375 unique trips/segments found
[ INFO] 21:38:21: Building data structures
[ INFO] 21:38:21: Data divided in 215 jobs with 9 trips each
[ INFO] 21:38:21: Process is being setup to run on 16 separate threads
[ INFO] 21:38:21: Starting data processing
2025-09-03 21:38:21 UTC+0000 - Processed 0.0% (0/215)
2025-09-03 21:38:36 UTC+0000 - Processed 1.9% (4/215)
2025-09-03 21:38:37 UTC+0000 - Processed 7.0% (15/215)
2025-09-03 21:38:38 UTC+0000 - Processed 7.0% (15/215)
2025-09-03 21:38:39 UTC+0000 - Processed 7.4% (16/215)
2025-09-03 21:38:40 UTC+0000 - Processed 7.4% (16/215)
2025-09-03 21:38:41 UTC+0000 - Processed 7.4% (16/215)
2025-09-03 21:38:42 UTC+0000 - Processed 8.8% (19/215)
2025-09-03 21:38:43 UTC+0000 - Processed 13.0% (28/215)
2025-09-03 21:38:44 UTC+0000 - Processed 14.9% (32/215)
2025-09-03 21:38:45 UTC+0000 - Processed 14.9% (32/215)
2025-09-03 21:38:46 UTC+0000 - Processed 14.9% (32/215)
2025-09-03 21:38:47 UTC+0000 - Processed 15.3% (33/215)
2025-09-03 21:38:48 UTC+0000 - Processed 17.2% (37/215)
2025-09-03 21:38:49 UTC+0000 - Processed 21.9% (47/215)
2025-09-03 21:38:50 UTC+0000 - Processed 22.3% (48/215)
2025-09-03 21:38:52 UTC+0000 - Processed 22.3% (48/215)
2025-09-03 21:38:53 UTC+0000 - Processed 22.8% (49/215)
2025-09-03 21:38:54 UTC+0000 - Processed 25.6% (55/215)
2025-09-03 21:38:55 UTC+0000 - Processed 28.8% (62/215)
2025-09-03 21:38:56 UTC+0000 - Processed 28.8% (62/215)
2025-09-03 21:38:57 UTC+0000 - Processed 29.8% (64/215)
2025-09-03 21:38:58 UTC+0000 - Processed 29.8% (64/215)
2025-09-03 21:38:59 UTC+0000 - Processed 31.2% (67/215)
2025-09-03 21:39:00 UTC+0000 - Processed 36.3% (78/215)
2025-09-03 21:39:01 UTC+0000 - Processed 36.3% (78/215)
2025-09-03 21:39:02 UTC+0000 - Processed 37.2% (80/215)
2025-09-03 21:39:03 UTC+0000 - Processed 37.2% (80/215)
2025-09-03 21:39:04 UTC+0000 - Processed 38.1% (82/215)
2025-09-03 21:39:05 UTC+0000 - Processed 43.7% (94/215)
2025-09-03 21:39:06 UTC+0000 - Processed 44.2% (95/215)
2025-09-03 21:39:07 UTC+0000 - Processed 44.7% (96/215)
2025-09-03 21:39:08 UTC+0000 - Processed 44.7% (96/215)
2025-09-03 21:39:09 UTC+0000 - Processed 47.0% (101/215)
2025-09-03 21:39:10 UTC+0000 - Processed 50.2% (108/215)
2025-09-03 21:39:11 UTC+0000 - Processed 51.6% (111/215)
2025-09-03 21:39:12 UTC+0000 - Processed 52.1% (112/215)
2025-09-03 21:39:13 UTC+0000 - Processed 52.1% (112/215)
2025-09-03 21:39:14 UTC+0000 - Processed 56.3% (121/215)
2025-09-03 21:39:15 UTC+0000 - Processed 59.1% (127/215)
2025-09-03 21:39:16 UTC+0000 - Processed 59.1% (127/215)
2025-09-03 21:39:17 UTC+0000 - Processed 59.5% (128/215)
2025-09-03 21:39:18 UTC+0000 - Processed 60.5% (130/215)
2025-09-03 21:39:19 UTC+0000 - Processed 64.2% (138/215)
2025-09-03 21:39:20 UTC+0000 - Processed 65.6% (141/215)
2025-09-03 21:39:21 UTC+0000 - Processed 66.5% (143/215)
2025-09-03 21:39:22 UTC+0000 - Processed 66.5% (143/215)
2025-09-03 21:39:23 UTC+0000 - Processed 67.0% (144/215)
2025-09-03 21:39:24 UTC+0000 - Processed 70.7% (152/215)
2025-09-03 21:39:25 UTC+0000 - Processed 72.6% (156/215)
2025-09-03 21:39:26 UTC+0000 - Processed 74.0% (159/215)
2025-09-03 21:39:27 UTC+0000 - Processed 74.4% (160/215)
2025-09-03 21:39:28 UTC+0000 - Processed 75.3% (162/215)
2025-09-03 21:39:29 UTC+0000 - Processed 78.1% (168/215)
2025-09-03 21:39:30 UTC+0000 - Processed 81.4% (175/215)
2025-09-03 21:39:31 UTC+0000 - Processed 81.4% (175/215)
2025-09-03 21:39:32 UTC+0000 - Processed 81.9% (176/215)
2025-09-03 21:39:33 UTC+0000 - Processed 82.8% (178/215)
2025-09-03 21:39:34 UTC+0000 - Processed 85.1% (183/215)
2025-09-03 21:39:35 UTC+0000 - Processed 86.5% (186/215)
2025-09-03 21:39:36 UTC+0000 - Processed 88.8% (191/215)
2025-09-03 21:39:37 UTC+0000 - Processed 89.8% (193/215)
2025-09-03 21:39:38 UTC+0000 - Processed 92.6% (199/215)
2025-09-03 21:39:39 UTC+0000 - Processed 94.0% (202/215)
2025-09-03 21:39:40 UTC+0000 - Processed 96.7% (208/215)
2025-09-03 21:39:41 UTC+0000 - Processed 99.5% (214/215)
[ INFO] 21:39:42: Starting consolidating of smart workflow outputs
[ INFO] 21:39:42: Looking for /tmp/polaris_studio_testing/2025-09-03_21-38-20--7087/Grid_iteration_1/sv_trip_output/svtrip_output_*.h5 files
[ INFO] 21:39:42: Found 16 such files
Converting H5 -> Matlab: 0%| | 0/16 [00:00<?, ?it/s]
Converting H5 -> Matlab: 6%|▋ | 1/16 [00:01<00:16, 1.11s/it]
Converting H5 -> Matlab: 38%|███▊ | 6/16 [00:01<00:01, 5.03it/s]
Converting H5 -> Matlab: 100%|██████████| 16/16 [00:01<00:00, 10.57it/s]
[ INFO] 21:39:45:
[ INFO] 21:39:45: =========================================================
[ INFO] 21:39:45: Finished multiprocessing, consolidating logs generated by
[ INFO] 21:39:45: subprocessing threads into main thread log file
[ INFO] 21:39:45:
[ INFO] 21:39:45: =========================================================
[ INFO] 21:39:45:
[ INFO] 21:39:45: Total run time: 0:01:24.030421
[ INFO] 21:39:45: Process finished
Total running time of the script: (1 minutes 27.238 seconds)