Redistributing fleets based on new control totals

Redistributing fleets based on new control totals#

When the user has data on the expected joint distribution of the fleet across multiple categories, including Vehicle class, power train, ful and its vintage, as well as the distribution of the existing fleet, it is possible to use the Vehicle Redistribution procedure to run an Iterative-Proportional fitting over the original distribution to match targets, including the total fleet for each census tract in the modeled area.

sphinx_gallery_thumbnail_path = ‘../../examples/data_preparation/car_fleet.png’ Imports

import os
from os.path import join
from pathlib import Path
from tempfile import gettempdir

from polaris.prepare.vehicle_distribution_updater.vehicle_distribution_updater import RedistributeVehicles

All our files need to be inside the same folder (pth, below)

pth = Path(os.getcwd()).resolve(True).parent.parent.parent / "tests" / "data" / "prepare" / "vehicle_redistribution"

rv = RedistributeVehicles(
    model_dir=pth,
    veh_file="vehicle_distribution_chicago.txt",
    target_file="target_2040_low.csv",
    veh_codes_file="polaris_vehicle_codes.csv",
    zone_weights="veh_by_zone_chicago.csv",
    fleet_mode=False,
)

Processing and saving results#

The convergence threshold can be as low as required, as it is nearly guaranteed to converge

rv.process(conv_threshold=0.001, max_iterations=50)

# Two convergence scatter plots are also saved with the outputs for a quick sanity check
rv.save_results(join(gettempdir(), "veh_distr.csv"))
  • Proportions for vehicle types
  • Zone totals
Iteration 1: 0.0s , error 0.01668
Iteration 2: 0.0s , error 0.00136
Iteration 3: 0.0s , error 0.00011
Total processing time: 0.1s

Looking at the outputs#

import pandas as pd

df = pd.read_csv(join(gettempdir(), "veh_distr.csv"))
df.head()
TRACT POLARIS_ID VEHICLE_CLASS FUEL POWERTRAIN VINTAGE PROPORTION
0 17007010100 1034 CAR_COMPACT Gas ISG 1 0.013509
1 17007010100 1035 CAR_COMPACT Gas ISG 2 0.014122
2 17007010100 1042 CAR_COMPACT Gas PHEV 0 0.000844
3 17007010100 1043 CAR_COMPACT Gas PHEV 1 0.000844
4 17007010100 1044 CAR_COMPACT Gas PHEV 2 0.000885


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

Gallery generated by Sphinx-Gallery