County-to-county trip matrices#

A common resource for a quick initial analysis of a model result is to look into county-to-county trip matrices, as that can shed light on the general validity of the demand model and help detect bigger issues with the model run.

from pathlib import Path

from polaris.analyze.trip_metrics import TripMetrics

Creating county-to-county matrices#

%% sphinx_gallery_thumbnail_path = ‘../../examples/result_analysis/county_to_county.png’

Let’s work with the Austin model

project_dir = Path("/tmp/Austin")
last_iter = TripMetrics(project_dir / "Austin-Supply.sqlite", project_dir / "Austin-Demand.sqlite")

We can get the trip matrix for the last iteration from the trip table

matrix_trips = last_iter.trip_matrix(from_start_time=0, to_start_time=24 * 3600, aggregation="county")

# And let's see what modes we have:
matrix_trips.names

Or we can make specify the particular modes we are interested in

modes = ["SOV", "TAXI"]
matrix_vehicles = last_iter.trip_matrix(from_start_time=0, to_start_time=24 * 3600, modes=modes, aggregation="county")

# And let's see what vehicle types we have:
matrix_vehicles.matrices
['SOV', 'TAXI']

Let’s look at some trips by the largest to smallest flow?#

Trip matrices sorted by largest amount of SOV trips

matrix_trips.to_df().sort_values("SOV_tot", ascending=False)
from_id to_id SOV_ab SOV_ba SOV_tot BUS_ab BUS_ba BUS_tot RAIL_ab RAIL_ba RAIL_tot TAXI_ab TAXI_ba TAXI_tot TNC_AND_RIDE_ab TNC_AND_RIDE_ba TNC_AND_RIDE_tot MD_TRUCK_ab MD_TRUCK_ba MD_TRUCK_tot HD_TRUCK_ab HD_TRUCK_ba HD_TRUCK_tot
12 48453 48491 227712.0 226048.0 453760.0 1420.0 1444.0 2864.0 64.0 64.0 128.0 4248.0 3220.0 7468.0 3280.0 4496.0 7776.0 19776.0 19436.0 39212.0 18956.0 19972.0 38928.0
10 48209 48453 88296.0 88236.0 176532.0 0.0 0.0 0.0 0.0 0.0 0.0 940.0 1300.0 2240.0 1516.0 664.0 2180.0 4588.0 4696.0 9284.0 12364.0 12440.0 24804.0
2 48021 48453 19460.0 19052.0 38512.0 8.0 4.0 12.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 4.0 1752.0 1704.0 3456.0 1800.0 1680.0 3480.0
7 48055 48209 11568.0 11684.0 23252.0 0.0 0.0 0.0 0.0 0.0 0.0 216.0 248.0 464.0 0.0 0.0 0.0 480.0 452.0 932.0 584.0 616.0 1200.0
6 48053 48491 8424.0 8624.0 17048.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 252.0 280.0 532.0
11 48209 48491 6292.0 6172.0 12464.0 0.0 0.0 0.0 0.0 0.0 0.0 12.0 4.0 16.0 0.0 0.0 0.0 76.0 120.0 196.0 60.0 72.0 132.0
8 48055 48453 5712.0 5760.0 11472.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 4.0 8.0 0.0 0.0 0.0 408.0 308.0 716.0 932.0 924.0 1856.0
5 48053 48453 5444.0 4912.0 10356.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 208.0 200.0 408.0
0 48021 48055 3884.0 3996.0 7880.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 32.0 72.0 104.0 52.0 40.0 92.0
3 48021 48491 2632.0 2624.0 5256.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 124.0 120.0 244.0 136.0 116.0 252.0
9 48055 48491 984.0 972.0 1956.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 0.0 4.0 0.0 0.0 0.0
1 48021 48209 852.0 1020.0 1872.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 40.0 36.0 76.0 48.0 40.0 88.0
4 48053 48209 172.0 192.0 364.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0


Vehicle matrices sorted by largest amount of HD_TRUCK trips

(matrix_trips.to_df()).sort_values("HD_TRUCK_tot", ascending=False)
from_id to_id SOV_ab SOV_ba SOV_tot BUS_ab BUS_ba BUS_tot RAIL_ab RAIL_ba RAIL_tot TAXI_ab TAXI_ba TAXI_tot TNC_AND_RIDE_ab TNC_AND_RIDE_ba TNC_AND_RIDE_tot MD_TRUCK_ab MD_TRUCK_ba MD_TRUCK_tot HD_TRUCK_ab HD_TRUCK_ba HD_TRUCK_tot
12 48453 48491 227712.0 226048.0 453760.0 1420.0 1444.0 2864.0 64.0 64.0 128.0 4248.0 3220.0 7468.0 3280.0 4496.0 7776.0 19776.0 19436.0 39212.0 18956.0 19972.0 38928.0
10 48209 48453 88296.0 88236.0 176532.0 0.0 0.0 0.0 0.0 0.0 0.0 940.0 1300.0 2240.0 1516.0 664.0 2180.0 4588.0 4696.0 9284.0 12364.0 12440.0 24804.0
2 48021 48453 19460.0 19052.0 38512.0 8.0 4.0 12.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 4.0 1752.0 1704.0 3456.0 1800.0 1680.0 3480.0
8 48055 48453 5712.0 5760.0 11472.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 4.0 8.0 0.0 0.0 0.0 408.0 308.0 716.0 932.0 924.0 1856.0
7 48055 48209 11568.0 11684.0 23252.0 0.0 0.0 0.0 0.0 0.0 0.0 216.0 248.0 464.0 0.0 0.0 0.0 480.0 452.0 932.0 584.0 616.0 1200.0
6 48053 48491 8424.0 8624.0 17048.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 252.0 280.0 532.0
5 48053 48453 5444.0 4912.0 10356.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 208.0 200.0 408.0
3 48021 48491 2632.0 2624.0 5256.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 124.0 120.0 244.0 136.0 116.0 252.0
11 48209 48491 6292.0 6172.0 12464.0 0.0 0.0 0.0 0.0 0.0 0.0 12.0 4.0 16.0 0.0 0.0 0.0 76.0 120.0 196.0 60.0 72.0 132.0
0 48021 48055 3884.0 3996.0 7880.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 32.0 72.0 104.0 52.0 40.0 92.0
1 48021 48209 852.0 1020.0 1872.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 40.0 36.0 76.0 48.0 40.0 88.0
4 48053 48209 172.0 192.0 364.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
9 48055 48491 984.0 972.0 1956.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4.0 0.0 4.0 0.0 0.0 0.0


Total running time of the script: (0 minutes 40.973 seconds)

Gallery generated by Sphinx-Gallery