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.

Imports

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

import pandas as pd

from polaris.prepare.vehicle_distribution_updater.vehicle_distribution_updater import RedistributeVehicles

Input data

Let’s take a look at the input data

pth = Path(os.getcwd()).resolve(True).parent / "data" / "vehicle_redistribution"
  • Vehicle file

Note that this file is TAB separated

pd.read_csv(pth / "vehicle_distribution_chicago.txt", delimiter="\t").head()
TRACT POLARIS_ID VEHICLE_CLASS FUEL POWERTRAIN VINTAGE PROPORTION
0 17007010100 1000 CAR_COMPACT Elec BEV 0 0.003972
1 17007010100 1009 CAR_COMPACT Diesel Conventional 0 0.000000
2 17007010100 1010 CAR_COMPACT Diesel Conventional 1 0.000000
3 17007010100 1011 CAR_COMPACT Diesel Conventional 2 0.000000
4 17007010100 1012 CAR_COMPACT Gas Conventional 0 0.006155


  • Target file

pd.read_csv(pth / "target_2040_low.csv").head()
VEHICLE_CLASS POWERTRAIN FUEL VINTAGE PROPORTION
0 CAR_COMPACT Conventional Gas 0 0.01755
1 CAR_COMPACT Conventional Gas 1 0.01750
2 CAR_COMPACT Conventional Gas 2 0.01830
3 CAR_COMPACT Conventional Diesel 0 0.00000
4 CAR_COMPACT Conventional Diesel 1 0.00000


  • Vehicle codes

pd.read_csv(pth / "polaris_vehicle_codes.csv").head()
POLARIS_ID VEHICLE_CLASS POWERTRAIN FUEL AUTOMATION CONNECTIVITY VINTAGE
0 0 DEFAULT BEV Elec NaN No 0
1 1 DEFAULT BEV Elec NaN No 1
2 2 DEFAULT BEV Elec NaN No 2
3 3 DEFAULT BEV_short Elec NaN No 0
4 4 DEFAULT BEV_short Elec NaN No 1


  • Zone weights

pd.read_csv(pth / "veh_by_zone_chicago.csv").head()
TRACT veh_count
0 17007010100 1353
1 17007010200 991
2 17007010300 1015
3 17007010400 1303
4 17007010500 2183


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

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.332 seconds)

Gallery generated by Sphinx-Gallery