Skip to main content

City-scale car traffic and parking analysis tool

Project description

Bevpo is a city-scale car traffic and parking analysis tool. It utilizes a Hidden Markov Model to translate changes in travel time between different zones of a city throughout multiple time steps into probabilities of driving or not, as well as choosing a destination if driving. Given the joint distribution from these two multivariate probability distributions, bevpo then samples a vehicle fleet of arbitrary size. One key strength of bevpo is that it is able to model at arbitrary granularities in time and space, which are eventually given by the data provided to bevpo.

Installation:

pip install bevpo

Docker:

For using bevpo within an Ubuntu docker container

docker run -it aryandoustarsam/bevpo

For using bevpo with Jupyter notebook inside a docker container

docker run -it -p 3333:1111 -v ~/path_to_data/data:/data aryandoustarsam/bevpo
[inside running container]: jupyter notebook --ip 0.0.0.0 --port 1111 --no-browser --allow-root
[in local machine browser]: localhost:3333 
[in local machine browser, type token shown in terminal]

Usage guide:

At the core of bevpo stands the class bevpo.TrafficSystem. It bundles all properties and methods of the traffic system modeled with bevpo. Bellow is a list of all

Parameters
city_zone_coordinates (required):
n_zones x 3 matrix
A pandas.DataFrame containing the columns 'zone_id', 'zone_lat' and 'zone_long' indicating the respective geographic coordinates of each city zone polygon centroid.
od_mean_travel_time_list (required):
list of n_data_t x 3 matrices
List of pandas.DataFrames containing the columns 'source_id', 'dest_id' and 'mean_travel_time'. Each list element corresponds to measurements in one time stamp. List elements should appear in consecutive temporal order.
od_stddev_travel_time_list (=None default):
list of n_data_t x 3 matrices
List of pandas.DataFrames containing the columns 'source_id', 'dest_id' and 'stddev_travel_time'. Each list element corresponds to measurements in one time stamp. List elements should appear in consecutive temporal order.
od_distances (=None default):
n_zones x n_zones
Symmetric origin destination matrix with same zone IDs as columns and indices in pandas.DataFrame
charging_profile (=None default):
list of floats > 0
A charging profile for electric vehicles with one floating point entry per simulation time step. It hence has to have a length equal to len(od_mean_travel_time_list)
e_drive (=2 default):
float > 0
Exponential parameter describing the (exponential) functional relationship between changes in travel time in a particular city zone and the probability that a car will drive.
e_dest (=2 default):
float > 0
Exponential parameter describing the (expoential) functional relationship between changes in travel time from one particular city zone to all other zones and the probabiity of choosing any of these other zones as a destination for a trip.
p_min (=0.1 default):
float in [0, p_max)
The lower bound of probability distribution for p_drive.
p_max (=0.9 default):
float in (p_min, 1]
The upper bound of probability distribution for p_drive.
cars_per_zone (=100 default):
int > 0
The number of cars to be sampled for each city zone during traffic simulation.
Attributes
T:
int > 0
Number of simulation time steps which results to len(od_mean_travel_time_list)
number_zones:
int > 0
Number of city zones in od matrices which results to len(city_zone_coordinates)
datatensor_mean:
number_zones x number_zones x T
Sparse tensor that contains all provided OD values for mean travel time.
datatensor_stddev:
number_zones x number_zones x T
Sparse tensor that contains all provided OD values for standard deviation of travel time.
C:
int > 0
Size of vehicle fleet to be simulated, which results to number_zones * cars_per_zone
state_tensor:
C x T
Tensor for saving states of traffic system which consists of the location of each simulated vehicle
transition_tensor:
C x T x 4
Tensor for saving state transition of traffic system which consists of the driving, destination, travel time and travel distance of each simulated vehicle.
Methods
simulate_traffic(): Simulates the traffic system when called.
calc_od_distances(city_zone_coordinates): Called on initialization of class objects if od_distances=None. Calculates the beeline distance between origin destination zones of a city if no explicit matrix of such distances was past when initializing class object.
create_datatensors(): Called by simulate_traffic() method. Transforms the list of od matrices into a single datatensor. City zone indexing corresponds to respective index positions in city_zone_coordinates.index. Time step indexing corresponds to respective position of OD matrix in od_mean_travel_time_list. If od_stddev_travel_time_list is available, the same is done for this list too.
save_tfs_results(path_to_results=None): Saves the resulting plots and numeric values unter path_to_results when called. If no path is passed, a directory called bevpo_results will be created within current working directory, where results are stored.
Results
driving_map:
number_zones x T
Multivariate distribution of driving activity among all modeled city zones and sampled time steps. Distributions sum up to 1 across all time step and cityzones.
parking_map:
number_zones x T
Multivariate distribution of parking cars among all modeled city zones and sampled time steps. Distributions sum up to 1 across all time step and city zones.
charging_map:
number_zones x T
(Optional). Only created if parameter charging_profile is provided. Multivariate distribution of charging cars among all modeled city zones and sampled time steps. Distribution sums up to 1 for all city zones and time steps.
avg_driving_times:
array of length T+1
Average driving durations of all sampled trips. The first entry corresponds to the average over all time steps. The following entries correspond to the average over each simulated time step.
avg_driving_distances:
array of length T+1
Average driving distance of all sampled trips. The first entry corresponds to the average over all time steps. The following entries correspond to the average over each simulated time step.
driving_share_lifetime:
%
The average share of the lifetime of a car in which it drives.
parking_share_lifetime:
%
The average share of the lifetime of a car in which it is parked.
circadian_rhythm:
array of length T
The circadian rhythm, that is the percentual traffic activity, throughout all simulated time steps.
distr_distances_per_t:
T x 10
A multivariate distribution of travelled distances for each time steps, categorized into 10 bins.
distr_durations_per_t:
T x 10
A multivariate distribution of travelled durations for each time steps, categorized into 10 bins.
distr_distances_total:
array of length 10
The total distribution of travelled distances categorized into 10 bins.
distr_durations_total:
array of length 10
The total distribution of travelled durations categorized into 10 bins.
distr_bins_km:
array of length 10
The distance category of each bin in km unit.
distr_bins_s:
array of length 10
The duration category of each bin in s unit.

Examples:

Simulating traffic for the city of London for weekdays in the first quarter of the year 2015 from exemplar Uber Movement travel time data, using only the minimum required information to pass to model.

import bevpo.datasets.prep_ubermovement as prep_data
import bevpo.trafficsystem as trafficsystem


### 1. Prepare Uber Data

# provide paths to Uber Movement data
path_to_rawdata = *insert path to Uber Movement .csv file here*
path_to_json_data = *insert path to Uber Movement .json file here*

# create city zone data from json file
city_zone_coordinates = (
    prep_data.create_city_zone_coordinates(path_to_json_data)
)

# create list of OD matrices from csv file
(
    od_mean_travel_time_list,
    od_std_travel_time_list
) = prep_data.create_od_matrix_lists(path_to_rawdata)


### 2. Simulate traffic 

# create object of class TrafficSystem and pass minimum required data
tfs = trafficsystem.TrafficSystem(
    city_zone_coordinates,
    od_mean_travel_time_list
)

# simulate traffic
tfs.simulate_traffic()

# save results
tfs.save_tfs_results()

Simulating traffic for the city of Bogota for weekends in the fourth quarter of the year 2020 from exemplar Uber Movement travel time data, using more than the minimum required information to pass to model, and customized parameters.

import bevpo.datasets.prep_ubermovement as prep_data
import bevpo.trafficsystem as trafficsystem


### 1. Prepare Uber Data

# provide paths to Uber Movement data
path_to_rawdata = *insert path to Uber Movement .csv file here*
path_to_json_data = *insert path to Uber Movement .json file here*
path_to_results = *insert path to desired results folder here*

# create city zone data from json file
city_zone_coordinates = (
    prep_data.create_city_zone_coordinates(path_to_json_data)
)

# create list of OD matrices from csv file
(
    od_mean_travel_time_list,
    od_std_travel_time_list
) = prep_data.create_od_matrix_lists(path_to_rawdata)


### 2. Simulate traffic 

# create object of class TrafficSystem and decleare custom parameters
tfs = bevpo.trafficsystem.TrafficSystem(
    city_zone_coordinates,
    od_mean_travel_time_list,
    od_std_travel_time_list,
    e_drive=0.5,
    e_dest=2.3,
    p_min=0.085,
    p_max=0.81
)

# simulate traffic
tfs.simulate_traffic()

# save results
tfs.save_tfs_results(path_to_results)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bevpo-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

bevpo-0.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file bevpo-0.1.0.tar.gz.

File metadata

  • Download URL: bevpo-0.1.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for bevpo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6213d0bb870ff2836342e894a31f1acefd18fc918d254977b1e1c4de26752109
MD5 7fa883eb0d0584874b0cf07443ba441a
BLAKE2b-256 ca68038aa903a998d82b1076df8c9f1f63b9928fb0a96b256b795f64730fd5df

See more details on using hashes here.

File details

Details for the file bevpo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bevpo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.2

File hashes

Hashes for bevpo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce22921177b8d0eb09f07ac7caa642b0762eeda4d22ea42f11a03a5889509af1
MD5 3af5b85b284cbceba6193e9cc50a46f2
BLAKE2b-256 de812aac313bd54f00f8cc150b8dfca47d7b2ca45b9b6b5aff5ceba9dfea534c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page