Note
Go to the end to download the full example code.
Exporting trips to zonal matrices#
To support the Polaris demand to be assigned to networks using static traffic assignment available in commonly used modelling packages, Polaris-Studio has a convenient tool for exporting demand into a traditional demand matrix format
Exporting matrices#
sphinx_gallery_thumbnail_path = ‘../../examples/modelling_like_the_old_days/matrix.png’
from pathlib import Path
import pandas as pd
from polaris.analyze.activity_metrics import ActivityMetrics
from polaris.analyze.trip_metrics import TripMetrics
from polaris.runs.convergence.convergence_iteration import ConvergenceIteration
We get the demand matrices for two separate iterations#
project_dir = Path("/tmp/Bloomington")
iteration_3 = ConvergenceIteration.from_dir(project_dir / "Bloomington_iteration_3")
tm3 = TripMetrics(Path("/tmp/Bloomington/Bloomington-Supply.sqlite"), iteration_3.files.demand_db)
# Let's get the morning peak matrix
# Let's say that the peak time is from 6:45AM to 8:45AM, so we get trips starting during that time
mat3 = tm3.vehicle_trip_matrix(from_start_time=6.75 * 3600, to_start_time=8.75 * 3600)
iteration_4 = ConvergenceIteration.from_dir(project_dir / "Bloomington_iteration_4")
tm4 = TripMetrics(Path("/tmp/Bloomington/Bloomington-Supply.sqlite"), iteration_3.files.demand_db)
# Same for the 4th iteration
mat4 = tm4.vehicle_trip_matrix(from_start_time=6.75 * 3600, to_start_time=8.75 * 3600)
We can also look at matrices from PLANNED ACTIVITIES These matrices contain only trips by CAR
act_metr = ActivityMetrics(Path("/tmp/Bloomington/Bloomington-Supply.sqlite"), iteration_3.files.demand_db)
act_matr3 = act_metr.vehicle_trip_matrix(from_start_time=6.75 * 3600, to_start_time=8.75 * 3600)
We can export the matrices to OMX
mat3.export("/tmp/am_peak_iter3.omx")
mat4.export("/tmp/am_peak_iter4.omx")
Since we have the matrices in memory, we can compare the marginals for SOV trips at zone levels
# the names of matrices we have
print(mat4.names)
i3 = mat3.SOV_0.sum(axis=1)
i4 = mat4.SOV_0.sum(axis=1)
pd.DataFrame({"Iter 3": i3, "Iter 4": i4}).plot.scatter(x="Iter 3", y="Iter 4", title="Destinations")
i3 = mat3.SOV_0.sum(axis=0)
i4 = mat4.SOV_0.sum(axis=0)
pd.DataFrame({"Iter 3": i3, "Iter 4": i4}).plot.scatter(x="Iter 3", y="Iter 4", title="Origins")
['SOV_0', 'TAXI_9']
<Axes: title={'center': 'Origins'}, xlabel='Iter 3', ylabel='Iter 4'>
Total running time of the script: (0 minutes 1.641 seconds)