From 0a3854051289f6747cc7e238a9ed8906e589c70a Mon Sep 17 00:00:00 2001 From: ychtw Date: Fri, 5 Nov 2021 01:07:55 -0400 Subject: [PATCH 1/4] add maz-stop walk time estimation method --- lasso/mtc.py | 331 +++++++++++++++++++++++++++++++++++++++++++- lasso/parameters.py | 4 + 2 files changed, 334 insertions(+), 1 deletion(-) diff --git a/lasso/mtc.py b/lasso/mtc.py index abdf978..0aa95b7 100644 --- a/lasso/mtc.py +++ b/lasso/mtc.py @@ -13,6 +13,8 @@ from sklearn.cluster import KMeans from pyproj import CRS from shapely.geometry import Point, LineString +import osmnx as ox +import networkx as nx from .parameters import Parameters from .logger import WranglerLogger @@ -2821,4 +2823,331 @@ def _calculate_node_county(x): "Finished Calculating node county variable: {}".format(network_variable) ) - return roadway_network \ No newline at end of file + return roadway_network + + +def get_period_mode_trn_stops(transit_network: CubeTransit = None) -> pd.DataFrame: + + # get transit line properties: line name, time period, and mode + trn_line_properties = pd.DataFrame( + { + "name": [k.replace('"', "") for k in transit_network.line_properties.keys()], + "time_period": [ + k.replace('"', "").split("_")[2] for k in transit_network.line_properties.keys() + ], + "mode": [ + v["USERA2"].replace('"', "") for v in transit_network.line_properties.values() + ], + } + ) + + # get transit stops' node ids + trn_line_stops = pd.DataFrame() + for line in transit_network.shapes.keys(): + line_nodes = transit_network.shapes[line] + line_nodes = line_nodes[line_nodes["stop"] == True] # keep only stop nodes + line_stops = pd.DataFrame( + {"name": line.replace('"', ""), "stop": line_nodes["node_id"].to_list()} + ) + trn_line_stops = pd.concat([trn_line_stops, line_stops]) + + # add transit line properties to trn_line_stops + trn_line_stops = pd.merge(trn_line_stops, trn_line_properties, how="left", on="name") + + # keep only the unique pair of time_period - mode - stop + period_mode_trn_stops = trn_line_stops[["time_period", "mode", "stop"]].drop_duplicates() + + return period_mode_trn_stops + + +def estimate_maz_walk_time( + roadway_network: ModelRoadwayNetwork = None, + transit_network: CubeTransit = None, + stop_demand: pd.DataFrame = None, + direction: str = "access", # "access" or "egress" + parameters=None, # for getting taz-maz lookup +) -> pd.DataFrame: + + # specify direction-specific variables + if direction == "access": + dir_col_maz = "from_maz" + dir_col_taz = "from_taz" + dir_col_stop = "to_stop" + dir_col_node = "A" # for filtering directional maz connectors + dir_col_stop_demand = "boardings" # for stop demand % in corresponding taz + else: + dir_col_maz = "to_maz" + dir_col_taz = "to_taz" + dir_col_stop = "from_stop" + dir_col_node = "B" + dir_col_stop_demand = "alightings" + + # project to a coordinate system that use ft as base unit + print("reproject roadway network") + links = roadway_network.links_df.copy().to_crs(epsg=2230) + nodes = roadway_network.nodes_df.copy().to_crs(epsg=2230) + + ############################################################### + ## Part 1: for each maz, find transit stops within 1.5 miles ## + ############################################################### + # Create 1.5 miles (7920 foot) buffer for each maz + print("create 1.5 miles buffer for maz nodes") + maz_nodes = nodes[ + (nodes["model_node_id"] < 900000) + & (nodes["model_node_id"] % 100000 < 90000) + & (nodes["model_node_id"] % 100000 >= 10000) + ].reset_index(drop=True) + buffer_geom = maz_nodes["geometry"].buffer(7920) + maz_buffer = gpd.GeoDataFrame( + maz_nodes[["model_node_id"]].rename(columns={"model_node_id": "maz"}), + geometry=buffer_geom, + crs=maz_nodes.crs, + ) + print(f"# of maz: {len(maz_buffer)}") + + # get transit stop node ids from transit_network, and add geometry from nodes + period_mode_trn_stops = get_period_mode_trn_stops(transit_network) + period_mode_trn_stops = gpd.GeoDataFrame( + pd.merge( + period_mode_trn_stops, + nodes[["model_node_id", "geometry"]], + how="left", + left_on="stop", + right_on="model_node_id", + ).drop(columns="model_node_id") + ) + + # spatial join to find transit stops in each maz + print("spatial join maz buffer and transit stop nodes") + print(f"# of transit stops: {len(period_mode_trn_stops)}") + maz_trn_stops = ( + gpd.sjoin(period_mode_trn_stops, maz_buffer, how="inner", op="intersects") + .drop(columns=["index_right", "geometry"]) + .rename(columns={"maz": dir_col_maz, "stop": dir_col_stop}) + .reset_index(drop=True) + ) + + ####################################################### + ## Part 2: find shortest path between maz-stop pairs ## + ####################################################### + # walk accessibility should be the same across time periods + # (select unique maz-stop pairs to reduce runtime) + maz_stop_pairs = ( + maz_trn_stops[[dir_col_maz, dir_col_stop]].drop_duplicates().reset_index(drop=True) + ) + print(f"unique maz-stop pairs: {len(maz_stop_pairs)}") + + # create walk network, exclude connectors (note: TAZ connectors are already with WALK_ACCESS = 0) + print("create walk network") + walk_net = links[ + (links["walk_access"] == 1) & (links["cntype"] != "MAZ") & (links["cntype"] != "TAP") + ].reset_index(drop=True) + + # add one-direction of MAZ connectors to the walk network + # (based on direction argument specified by the user) + maz_connectors = links[ + (links["cntype"] == "MAZ") + & (links[dir_col_node] < 900000) + & (links[dir_col_node] % 100000 < 90000) + & (links[dir_col_node] % 100000 >= 10000) + ].reset_index(drop=True) + walk_net = pd.concat([walk_net, maz_connectors]).reset_index(drop=True) + + # format walk_net dataframe + walk_net["u"] = walk_net["A"] + walk_net["v"] = walk_net["B"] + walk_net["key"] = walk_net.index + 1 + walk_net = walk_net[["u", "v", "key", "A", "B", "distance", "geometry"]] + + # create walk nodes + walk_nodes = nodes[nodes["walk_access"] == 1] + walk_nodes["x"] = walk_nodes["geometry"].x + walk_nodes["y"] = walk_nodes["geometry"].y + walk_nodes = walk_nodes[["model_node_id", "x", "y", "geometry"]] + + # build walk network graph + walk_graph = ox.graph_from_gdfs(walk_nodes, walk_net) + + print("build shortest path between maz and stop") + shortest_paths = {dir_col_maz: [], dir_col_stop: [], "distance": [], "path": []} + shortest_paths_fail = {dir_col_maz: [], dir_col_stop: []} + + print(f"# of paths to be processed: {len(maz_stop_pairs)}") + print("build shortest paths ...") + for i in range(len(maz_stop_pairs)): + if i % 5000 == 0: + print(f"processing path #: {i + 1}") + # get two trip ends + maz_end = maz_stop_pairs.loc[i, dir_col_maz] + stop_end = maz_stop_pairs.loc[i, dir_col_stop] + + try: + if direction == "access": + path_dist = nx.shortest_path_length( + walk_graph, maz_end, stop_end, weight="distance" + ) + path = nx.shortest_path(walk_graph, maz_end, stop_end, weight="distance") + else: + path_dist = nx.shortest_path_length( + walk_graph, stop_end, maz_end, weight="distance" + ) + path = nx.shortest_path(walk_graph, stop_end, maz_end, weight="distance") + shortest_paths[dir_col_maz].append(maz_end) + shortest_paths[dir_col_stop].append(stop_end) + shortest_paths["distance"].append(path_dist) + shortest_paths["path"].append(str(path)) + except: + shortest_paths_fail[dir_col_maz].append(maz_end) + shortest_paths_fail[dir_col_stop].append(stop_end) + + # convert shortest path results from dict to df + shortest_paths = pd.DataFrame.from_dict(shortest_paths) + shortest_paths_fail = pd.DataFrame.from_dict(shortest_paths_fail) + + # remove maz-stop pairs that exceed 1.5 miles walk distance + shortest_paths = shortest_paths[shortest_paths["distance"] <= 1.5].reset_index(drop=True) + + # calculate shortest walk time in minute (assume walk speed = 3 mph) + shortest_paths["walk_min"] = (shortest_paths["distance"] / 3) * 60 + + # calculate impedance and time-to-impedance ratio + def _calculate_impedance(x): + # 1 * a + 5 * b + 10 * c + 20 * d + a = min(x.walk_min, 5) + b = min(x.walk_min - 5, 5) + c = min(x.walk_min - 10, 10) + d = x.walk_min - 15 + if x.walk_min >= 15: + return a + 5 * b + 10 * c + 20 * d + elif x.walk_min >= 10: + return a + 5 * b + 10 * c + elif x.walk_min >= 5: + return a + 5 * b + else: + return a + shortest_paths["impedance"] = shortest_paths.apply(lambda x: _calculate_impedance(x), axis=1) + shortest_paths["time_impedance_ratio"] = ( + shortest_paths["walk_min"] / shortest_paths["impedance"] + ) + + # add taz info + maz_taz_lookup = pd.read_csv(parameters.taz_maz_crosswalk_file) + maz_taz_lookup = maz_taz_lookup[["MAZ_ORIGINAL", "TAZ_ORIGINAL"]].rename( + columns={"MAZ_ORIGINAL": dir_col_maz, "TAZ_ORIGINAL": dir_col_taz} + ) + shortest_paths = pd.merge(shortest_paths, maz_taz_lookup, how="left", on=dir_col_maz) + shortest_paths[dir_col_taz] = shortest_paths[dir_col_taz].astype(int) + + # add shortest path info back to maz_trn_stops + maz_trn_stops = pd.merge( + maz_trn_stops, shortest_paths, how="left", on=[dir_col_maz, dir_col_stop] + ) + # some records will have null distance because those with > 1.5 walk distance was removed from shortest path + maz_trn_stops = maz_trn_stops[~maz_trn_stops["distance"].isnull()].reset_index(drop=True) + + # expand maz_trn_stops to have records by skim set + # (note: maz_trn_stops already have time period & mode info) + maz_trn_stops_set1 = maz_trn_stops[maz_trn_stops["mode"] == "Local bus"].copy() + maz_trn_stops_set1["skim_set"] = 1 + maz_trn_stops_set2 = maz_trn_stops[maz_trn_stops["mode"] != "Local bus"].copy() + maz_trn_stops_set2["skim_set"] = 2 + maz_trn_stops_set3 = maz_trn_stops.copy() + maz_trn_stops_set3["skim_set"] = 3 + maz_trn_stops_all_sets = pd.concat( + [maz_trn_stops_set1, maz_trn_stops_set2, maz_trn_stops_set3] + ).reset_index(drop=True) + + # initialize df that keep results from all skim sets & time periods + result_maz_trn_stops = pd.DataFrame() + + for skim_set in [1, 2, 3]: + for time_period in ["EA", "AM", "MD", "PM", "EV"]: + print(f"process skim set {skim_set}, time period: {time_period}") + + # select maz_trn_stop for the given skim set & time period + maz_trn_stop_set_per = maz_trn_stops_all_sets[ + (maz_trn_stops_all_sets["skim_set"] == skim_set) + & (maz_trn_stops_all_sets["time_period"] == time_period) + ].copy() + + # select stop boardings/alightings volumes for the given skim set & time period + stop_demand = stop_demand.rename(columns={"stop": dir_col_stop}) + if skim_set == 1: + stop_demand_set_per = stop_demand[ + (stop_demand["mode"] == "local") & (stop_demand["time_period"] == time_period) + ] + elif skim_set == 2: + stop_demand_set_per = stop_demand[ + (stop_demand["mode"] == "premium") & (stop_demand["time_period"] == time_period) + ] + else: + stop_demand_set_per = stop_demand[stop_demand["time_period"] == time_period] + stop_demand_set_per = stop_demand_set_per.drop(columns=["mode", "time_period"]) + + # add stop demand to maz_trn_stop_set_per + maz_trn_stop_set_per = pd.merge( + maz_trn_stop_set_per, stop_demand_set_per, how="left", on=dir_col_stop + ) + # remove records w/o stop demand + maz_trn_stop_set_per = maz_trn_stop_set_per[ + ~maz_trn_stop_set_per[dir_col_stop_demand].isnull() + ] + + # calculate total boarding / alighting demand for each taz + taz_demand = ( + maz_trn_stop_set_per[[dir_col_stop, dir_col_taz, dir_col_stop_demand]] + .drop_duplicates() + .groupby([dir_col_taz])[dir_col_stop_demand] + .agg("sum") + .reset_index(name=f"taz_total_{dir_col_stop_demand}") + ) + + # add taz demand to maz_trn_stop_set_per + maz_trn_stop_set_per = pd.merge( + maz_trn_stop_set_per, taz_demand, how="left", on=dir_col_taz + ) + + # calculate bording/alighting share at each stop within its corresponding taz + maz_trn_stop_set_per["stop_taz_demand_share"] = ( + maz_trn_stop_set_per[dir_col_stop_demand] + / maz_trn_stop_set_per[f"taz_total_{dir_col_stop_demand}"] + ) + + maz_trn_stop_set_per["stop_walk_time_weight"] = ( + maz_trn_stop_set_per["stop_taz_demand_share"] + * maz_trn_stop_set_per["time_impedance_ratio"] + ) + + # calculate maz-level sum of "stop_walk_time_weight" + maz_weight_sum = ( + maz_trn_stop_set_per[[dir_col_maz, "stop_walk_time_weight"]] + .groupby([dir_col_maz])["stop_walk_time_weight"] + .agg("sum") + .reset_index(name="maz_weight_sum") + ) + maz_trn_stop_set_per = pd.merge( + maz_trn_stop_set_per, maz_weight_sum, how="left", on=dir_col_maz + ) + + maz_trn_stop_set_per["stop_weight"] = ( + maz_trn_stop_set_per["stop_walk_time_weight"] + / maz_trn_stop_set_per["maz_weight_sum"] + ) + maz_trn_stop_set_per["weighted_walk_min"] = ( + maz_trn_stop_set_per["stop_weight"] * maz_trn_stop_set_per["walk_min"] + ) + + result_maz_trn_stops = pd.concat([result_maz_trn_stops, maz_trn_stop_set_per]) + + # aggregate to maz level to get estimated maz walk access time + est_maz_walk_time = ( + result_maz_trn_stops.groupby(["skim_set", "time_period", dir_col_maz])["weighted_walk_min"] + .agg("sum") + .reset_index(name=f"est_maz_walk_{direction}_min") + ) + est_maz_walk_time[f"est_maz_walk_{direction}_min"] = est_maz_walk_time[ + f"est_maz_walk_{direction}_min" + ].round(3) + + # optional return df: result_maz_trn_stops, shortest_paths_fail + return est_maz_walk_time diff --git a/lasso/parameters.py b/lasso/parameters.py index 5c348cc..1ba0fb2 100644 --- a/lasso/parameters.py +++ b/lasso/parameters.py @@ -916,3 +916,7 @@ def __init__(self, **kwargs): ] self.__dict__.update(kwargs) + + self.taz_maz_crosswalk_file = os.path.join( + self.data_file_location, "lookups", "maz_data_withDensity.csv" + ) From 3d304ff847b78f0caaf3796f87be9436a07dc937 Mon Sep 17 00:00:00 2001 From: ychtw Date: Mon, 15 Nov 2021 17:26:45 -0500 Subject: [PATCH 2/4] add taz connectors estimation method --- lasso/mtc.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lasso/mtc.py b/lasso/mtc.py index 0aa95b7..3f72c90 100644 --- a/lasso/mtc.py +++ b/lasso/mtc.py @@ -3151,3 +3151,82 @@ def _calculate_impedance(x): # optional return df: result_maz_trn_stops, shortest_paths_fail return est_maz_walk_time + + +def estimate_transit_taz_connectors( + maz_stop_walk_time: pd.DataFrame = None, + direction: str = "access", + trn_trip_list: pd.DataFrame = None, + parameters=None, +): + # specify direction-specific variables + if direction == "access": + dir_col_maz = "from_maz" + dir_col_taz = "from_taz" + dir_col_stop = "to_stop" + else: + dir_col_maz = "to_maz" + dir_col_taz = "to_taz" + dir_col_stop = "from_stop" + + # calculate maz-scale transit demand + maz_demand = ( + trn_trip_list.groupby(["skim_set", "time_period", dir_col_maz]) + .size() + .reset_index(name="maz_demand") + ) + + # add taz info to maz_demand + maz_taz_lookup = pd.read_csv(parameters.taz_maz_crosswalk_file) + maz_demand = ( + pd.merge( + maz_demand, + maz_taz_lookup[["MAZ_ORIGINAL", "TAZ_ORIGINAL"]], + how="left", + left_on=dir_col_maz, + right_on="MAZ_ORIGINAL", + ) + .drop(columns=["MAZ_ORIGINAL"]) + .rename(columns={"TAZ_ORIGINAL": dir_col_taz}) + ) + + # join maz-stop walk access/egress time data to maz_demand + walk_time_with_demand = pd.merge( + maz_stop_walk_time, + maz_demand, + how="left", + on=["skim_set", "time_period", dir_col_maz], + ) + + walk_time_with_demand = walk_time_with_demand[~walk_time_with_demand["maz_demand"].isnull()] + walk_time_with_demand[dir_col_taz] = walk_time_with_demand[dir_col_taz].astype(int) + + # calculate sum of maz demand by stop by taz + taz_stop_demand = ( + walk_time_with_demand.groupby(["skim_set", "time_period", dir_col_taz, dir_col_stop])[ + "maz_demand" + ] + .agg("sum") + .reset_index(name="taz_stop_demand") + ) + walk_time_with_demand = pd.merge( + walk_time_with_demand, + taz_stop_demand, + how="left", + on=["skim_set", "time_period", dir_col_taz, dir_col_stop], + ) + + walk_time_with_demand["demand_weighted_walk_min"] = ( + walk_time_with_demand["walk_min"] * walk_time_with_demand["maz_demand"] + ) / walk_time_with_demand["taz_stop_demand"] + + # aggregate to taz-stop level to get the final estimated taz-stop walk access/egress time + est_taz_connectors = ( + walk_time_with_demand.groupby(["skim_set", "time_period", dir_col_taz, dir_col_stop])[ + "demand_weighted_walk_min" + ] + .agg("sum") + .reset_index(name="est_walk_min") + ) + + return est_taz_connectors From 967cb5dde29e83bc85d2accf9c75920c691d83f4 Mon Sep 17 00:00:00 2001 From: ychtw Date: Tue, 15 Feb 2022 21:13:54 -0500 Subject: [PATCH 3/4] keep stops with zero demand in estimate_maz_walk_time calculation --- lasso/mtc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lasso/mtc.py b/lasso/mtc.py index 3f72c90..087e22d 100644 --- a/lasso/mtc.py +++ b/lasso/mtc.py @@ -3088,10 +3088,10 @@ def _calculate_impedance(x): maz_trn_stop_set_per = pd.merge( maz_trn_stop_set_per, stop_demand_set_per, how="left", on=dir_col_stop ) - # remove records w/o stop demand - maz_trn_stop_set_per = maz_trn_stop_set_per[ - ~maz_trn_stop_set_per[dir_col_stop_demand].isnull() - ] + # fill stop with zero demand with 1 (so that all stop remain in the record) + maz_trn_stop_set_per[dir_col_stop_demand] = maz_trn_stop_set_per[ + dir_col_stop_demand + ].fillna(1.0) # calculate total boarding / alighting demand for each taz taz_demand = ( From 9976a68dd15c2409a162e4e42e39dcf3b111a82b Mon Sep 17 00:00:00 2001 From: ychtw Date: Tue, 22 Feb 2022 21:58:29 -0500 Subject: [PATCH 4/4] add tap analysis comparison scripts --- notebooks/create-comparison-assng-db.ipynb | 1432 +++++++ notebooks/create-comparison-skim-db.ipynb | 4230 ++++++++++++++++++++ 2 files changed, 5662 insertions(+) create mode 100644 notebooks/create-comparison-assng-db.ipynb create mode 100644 notebooks/create-comparison-skim-db.ipynb diff --git a/notebooks/create-comparison-assng-db.ipynb b/notebooks/create-comparison-assng-db.ipynb new file mode 100644 index 0000000..6f18a1e --- /dev/null +++ b/notebooks/create-comparison-assng-db.ipynb @@ -0,0 +1,1432 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
route_idroute_nameroute_shortnameroute_longnameusera1usera2modemode_namemode_longnameoperatoroperator_namedirection
015_1_EA_d0_s1ACENaNCECommuter rail133Commuter RailACE5ACE0
115_1_AM_d0_s1ACENaNCECommuter rail133Commuter RailACE5ACE0
215_1_PM_d1_s2ACENaNCECommuter rail133Commuter RailACE5ACE1
313130_131_EA_d1_s359GSan Francisco - El CerritoAC TransitExpress bus84Express BusAC Transit Transbay30AC Transit1
413130_131_AM_d1_s359GSan Francisco - El CerritoAC TransitExpress bus84Express BusAC Transit Transbay30AC Transit1
\n", + "
" + ], + "text/plain": [ + " route_id route_name route_shortname route_longname \\\n", + "0 1 5_1_EA_d0_s1 ACE NaN \n", + "1 1 5_1_AM_d0_s1 ACE NaN \n", + "2 1 5_1_PM_d1_s2 ACE NaN \n", + "3 131 30_131_EA_d1_s359 G San Francisco - El Cerrito \n", + "4 131 30_131_AM_d1_s359 G San Francisco - El Cerrito \n", + "\n", + " usera1 usera2 mode mode_name mode_longname \\\n", + "0 CE Commuter rail 133 Commuter Rail ACE \n", + "1 CE Commuter rail 133 Commuter Rail ACE \n", + "2 CE Commuter rail 133 Commuter Rail ACE \n", + "3 AC Transit Express bus 84 Express Bus AC Transit Transbay \n", + "4 AC Transit Express bus 84 Express Bus AC Transit Transbay \n", + "\n", + " operator operator_name direction \n", + "0 5 ACE 0 \n", + "1 5 ACE 0 \n", + "2 5 ACE 1 \n", + "3 30 AC Transit 1 \n", + "4 30 AC Transit 1 " + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data_path = \"../data\"\n", + "trn_route_name_lookup = pd.read_csv(f\"{data_path}/trn_route_name_lookup_ver12.csv\")\n", + "trn_route_name_lookup = trn_route_name_lookup.drop(columns=[\"route\"])\n", + "trn_route_name_lookup.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### create summary for routes (except BART and Caltrain)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def create_non_rail_summary(approach, period):\n", + " assignment_file = f\"{data_path}/{approach}/assignment/boardings_by_line_{period.lower()}.csv\"\n", + " if approach == \"tap_approach\":\n", + " asgn_result = pd.read_csv(assignment_file)\n", + " else:\n", + " asgn_result = pd.read_csv(assignment_file, sep=\"\\t\")\n", + "\n", + " asgn_result = asgn_result.rename(columns={\"line_name\": \"route_name\"}).drop(columns=[\"mode\"])\n", + " asgn_result = pd.merge(asgn_result, trn_route_name_lookup, how=\"left\", on=\"route_name\")\n", + "\n", + " # remove records with operator 17 (Caltrain) & 26 (BART)\n", + " asgn_result = asgn_result[(asgn_result[\"operator\"] != 17) & (asgn_result[\"operator\"] != 26)]\n", + "\n", + " # organize to final format\n", + " asgn_result = asgn_result.rename(columns={\"operator\": \"operator_id\", \"operator_name\": \"operator\", \"total_boardings\": \"boardings\"})\n", + " asgn_result[\"source\"] = approach\n", + " asgn_result[\"period\"] = period\n", + " asgn_result = asgn_result[[\"source\", \"period\", \"operator_id\", \"operator\", \"route_id\", \"route_shortname\", \"route_longname\", \"boardings\"]]\n", + "\n", + " return asgn_result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "non_rail_summary = pd.DataFrame()\n", + "\n", + "for approach in [\"tap_approach\", \"taz_approach\"]:\n", + " for period in [\"EA\", \"AM\", \"MD\", \"PM\", \"EV\"]:\n", + " non_rail_period_approach_summary = create_non_rail_summary(approach, period)\n", + " non_rail_summary = pd.concat([non_rail_summary, non_rail_period_approach_summary])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nameboardings
0tap_approachEA10Emery Go-Round198HollisNaN0.0
1tap_approachEA10Emery Go-Round201Shellmound/PowellNaN25.2
2tap_approachEA12Vallejo Transit4811NaN0.0
3tap_approachEA12Vallejo Transit4811NaN0.0
4tap_approachEA12Vallejo Transit4822NaN0.0
\n", + "
" + ], + "text/plain": [ + " source period operator_id operator route_id \\\n", + "0 tap_approach EA 10 Emery Go-Round 198 \n", + "1 tap_approach EA 10 Emery Go-Round 201 \n", + "2 tap_approach EA 12 Vallejo Transit 481 \n", + "3 tap_approach EA 12 Vallejo Transit 481 \n", + "4 tap_approach EA 12 Vallejo Transit 482 \n", + "\n", + " route stop_name boardings \n", + "0 Hollis NaN 0.0 \n", + "1 Shellmound/Powell NaN 25.2 \n", + "2 1 NaN 0.0 \n", + "3 1 NaN 0.0 \n", + "4 2 NaN 0.0 " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# reformat\n", + "non_rail_summary = non_rail_summary.reset_index(drop=True)\n", + "non_rail_summary.loc[non_rail_summary[\"route_shortname\"].isnull(), \"route\"] = non_rail_summary[\"route_longname\"]\n", + "non_rail_summary.loc[non_rail_summary[\"route_longname\"].isnull(), \"route\"] = non_rail_summary[\"route_shortname\"]\n", + "non_rail_summary.loc[(~non_rail_summary[\"route_shortname\"].isnull()) & (~non_rail_summary[\"route_longname\"].isnull()), \"route\"] = non_rail_summary[\"route_shortname\"].astype(str) + \"_\" + non_rail_summary[\"route_longname\"].astype(str)\n", + "non_rail_summary[\"stop_name\"] = np.nan\n", + "non_rail_summary = non_rail_summary[[\"source\", \"period\", \"operator_id\", \"operator\", \"route_id\", \"route\", \"stop_name\", \"boardings\"]]\n", + "non_rail_summary.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### create summary for BART and Caltrain" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
model_node_idstop_name
01027608Embarcadero
11027609Montgomery St.
21027610Powell St.
31027611Civic Center/UN Plaza
4102761216th St. Mission
\n", + "
" + ], + "text/plain": [ + " model_node_id stop_name\n", + "0 1027608 Embarcadero\n", + "1 1027609 Montgomery St.\n", + "2 1027610 Powell St.\n", + "3 1027611 Civic Center/UN Plaza\n", + "4 1027612 16th St. Mission" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bart_nodes = pd.read_csv(f\"{data_path}/bart_nodes_with_name.csv\")\n", + "bart_nodes = bart_nodes.rename(columns={\"N\": \"model_node_id\", \"stop_nm\": \"stop_name\"})\n", + "bart_nodes = bart_nodes[[\"model_node_id\", \"stop_name\"]]\n", + "bart_nodes.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def create_rail_summary(approach, operator, period):\n", + " if operator == \"Caltrain\":\n", + " operator_id = 17\n", + " elif operator == \"BART\":\n", + " operator_id = 26\n", + " \n", + " route_id_name = {\n", + " \"route_id\": [154, 155, 156, 157, 158, 159, 193, 194, 195],\n", + " \"route\": [\n", + " \"Pittsburg/Bay Point - SFIA/Millbrae\",\n", + " \"Fremont - Richmond\",\n", + " \"Fremont - Daly City\",\n", + " \"Richmond - Daly City/Millbrae\",\n", + " \"Dublin/Pleasanton - Daly City\",\n", + " \"Coliseum - Oakland Int'l Airport\",\n", + " \"Bullet\",\n", + " \"Limited\",\n", + " \"Local\",\n", + " ]}\n", + " route_id_name_df = pd.DataFrame.from_dict(route_id_name)\n", + "\n", + " if approach == \"tap_approach\":\n", + " node_asgn_result = pd.read_csv(f\"{data_path}/{approach}/assignment/boardings_by_node_{period.lower()}.csv\", sep=\"\\t\")\n", + " elif approach == \"taz_approach\":\n", + " node_asgn_result = pd.read_csv(f\"{data_path}/{approach}/assignment/boardings_by_segment_{period.lower()}.csv\", sep=\"\\t\")\n", + " node_asgn_result = node_asgn_result[node_asgn_result[\"is_i_node_stop\"] == 1]\n", + " node_asgn_result = node_asgn_result.rename(columns={\"line_name\": \"route_name\"})\n", + " node_asgn_result = pd.merge(node_asgn_result, trn_route_name_lookup, how=\"left\", on=\"route_name\")\n", + " node_asgn_result = node_asgn_result.rename(columns={\"operator\": \"operator_id\", \"operator_name\": \"operator\"})\n", + " node_asgn_result = node_asgn_result[node_asgn_result[\"operator_id\"] == operator_id]\n", + "\n", + " node_asgn_result = pd.merge(node_asgn_result, route_id_name_df, how=\"left\", on=\"route_id\")\n", + "\n", + " node_asgn_result[\"source\"] = approach\n", + " node_asgn_result[\"period\"] = period\n", + "\n", + " node_asgn_result = node_asgn_result[[\"source\", \"period\", \"operator_id\", \"operator\", \"route_id\", \"route\", \"stop_name\", \"boardings\"]]\n", + " node_asgn_result = node_asgn_result.groupby([\"source\", \"period\", \"operator_id\", \"operator\", \"route_id\", \"route\", \"stop_name\"])[\"boardings\"].agg(\"sum\").reset_index(name=\"boardings\")\n", + " \n", + " return node_asgn_result" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nameboardings
0tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae12th St. Oakland City Center56.188333
1tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae16th St. Mission54.182210
2tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae19th St. Oakland61.335000
3tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae24th St. Mission45.117010
4tap_approachEA26BART154Pittsburg/Bay Point - SFIA/MillbraeBalboa Park74.661820
\n", + "
" + ], + "text/plain": [ + " source period operator_id operator route_id \\\n", + "0 tap_approach EA 26 BART 154 \n", + "1 tap_approach EA 26 BART 154 \n", + "2 tap_approach EA 26 BART 154 \n", + "3 tap_approach EA 26 BART 154 \n", + "4 tap_approach EA 26 BART 154 \n", + "\n", + " route stop_name \\\n", + "0 Pittsburg/Bay Point - SFIA/Millbrae 12th St. Oakland City Center \n", + "1 Pittsburg/Bay Point - SFIA/Millbrae 16th St. Mission \n", + "2 Pittsburg/Bay Point - SFIA/Millbrae 19th St. Oakland \n", + "3 Pittsburg/Bay Point - SFIA/Millbrae 24th St. Mission \n", + "4 Pittsburg/Bay Point - SFIA/Millbrae Balboa Park \n", + "\n", + " boardings \n", + "0 56.188333 \n", + "1 54.182210 \n", + "2 61.335000 \n", + "3 45.117010 \n", + "4 74.661820 " + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bart_summary = pd.DataFrame()\n", + "\n", + "for approach in [\"tap_approach\", \"taz_approach\"]:\n", + " for period in [\"EA\", \"AM\", \"MD\", \"PM\", \"EV\"]:\n", + " bart_period_approach_summary = create_rail_summary(approach, \"BART\", period)\n", + " bart_summary = pd.concat([bart_summary, bart_period_approach_summary])\n", + "\n", + "bart_summary.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nameboardings
0tap_approachEA17Caltrain193BulletHillsdale Caltrain0.00
1tap_approachEA17Caltrain193BulletMillbrae Caltrain0.00
2tap_approachEA17Caltrain193BulletMt View Caltrain2.99
3tap_approachEA17Caltrain193BulletPalo Alto Caltrain0.00
4tap_approachEA17Caltrain193BulletSan Francisco Caltrain0.00
\n", + "
" + ], + "text/plain": [ + " source period operator_id operator route_id route \\\n", + "0 tap_approach EA 17 Caltrain 193 Bullet \n", + "1 tap_approach EA 17 Caltrain 193 Bullet \n", + "2 tap_approach EA 17 Caltrain 193 Bullet \n", + "3 tap_approach EA 17 Caltrain 193 Bullet \n", + "4 tap_approach EA 17 Caltrain 193 Bullet \n", + "\n", + " stop_name boardings \n", + "0 Hillsdale Caltrain 0.00 \n", + "1 Millbrae Caltrain 0.00 \n", + "2 Mt View Caltrain 2.99 \n", + "3 Palo Alto Caltrain 0.00 \n", + "4 San Francisco Caltrain 0.00 " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "caltrain_summary = pd.DataFrame()\n", + "\n", + "for approach in [\"tap_approach\", \"taz_approach\"]:\n", + " for period in [\"EA\", \"AM\", \"MD\", \"PM\", \"EV\"]:\n", + " caltrain_period_approach_summary = create_rail_summary(approach, \"Caltrain\", period)\n", + " caltrain_summary = pd.concat([caltrain_summary, caltrain_period_approach_summary])\n", + "\n", + "caltrain_summary.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nameboardings
0tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae12th St. Oakland City Center56.188333
1tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae16th St. Mission54.182210
2tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae19th St. Oakland61.335000
3tap_approachEA26BART154Pittsburg/Bay Point - SFIA/Millbrae24th St. Mission45.117010
4tap_approachEA26BART154Pittsburg/Bay Point - SFIA/MillbraeBalboa Park74.661820
\n", + "
" + ], + "text/plain": [ + " source period operator_id operator route_id \\\n", + "0 tap_approach EA 26 BART 154 \n", + "1 tap_approach EA 26 BART 154 \n", + "2 tap_approach EA 26 BART 154 \n", + "3 tap_approach EA 26 BART 154 \n", + "4 tap_approach EA 26 BART 154 \n", + "\n", + " route stop_name \\\n", + "0 Pittsburg/Bay Point - SFIA/Millbrae 12th St. Oakland City Center \n", + "1 Pittsburg/Bay Point - SFIA/Millbrae 16th St. Mission \n", + "2 Pittsburg/Bay Point - SFIA/Millbrae 19th St. Oakland \n", + "3 Pittsburg/Bay Point - SFIA/Millbrae 24th St. Mission \n", + "4 Pittsburg/Bay Point - SFIA/Millbrae Balboa Park \n", + "\n", + " boardings \n", + "0 56.188333 \n", + "1 54.182210 \n", + "2 61.335000 \n", + "3 45.117010 \n", + "4 74.661820 " + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result_long = pd.concat([bart_summary, caltrain_summary, non_rail_summary])\n", + "result_long.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "result_long.to_csv(\"../../outputs/assignment/boarding_comparison_v6.csv\", index=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## reshape result from long to wide format" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nametap_boardingstaz_boardings
0AM26BART154Pittsburg/Bay Point - SFIA/Millbrae12th St. Oakland City Center1200.9943810.6908
1AM26BART154Pittsburg/Bay Point - SFIA/Millbrae16th St. Mission582.8108392.6731
2AM26BART154Pittsburg/Bay Point - SFIA/Millbrae19th St. Oakland1065.1420238.4674
3AM26BART154Pittsburg/Bay Point - SFIA/Millbrae24th St. Mission1190.6400701.2632
4AM26BART154Pittsburg/Bay Point - SFIA/MillbraeBalboa Park1301.0640609.8207
\n", + "
" + ], + "text/plain": [ + "source period operator_id operator route_id \\\n", + "0 AM 26 BART 154 \n", + "1 AM 26 BART 154 \n", + "2 AM 26 BART 154 \n", + "3 AM 26 BART 154 \n", + "4 AM 26 BART 154 \n", + "\n", + "source route stop_name \\\n", + "0 Pittsburg/Bay Point - SFIA/Millbrae 12th St. Oakland City Center \n", + "1 Pittsburg/Bay Point - SFIA/Millbrae 16th St. Mission \n", + "2 Pittsburg/Bay Point - SFIA/Millbrae 19th St. Oakland \n", + "3 Pittsburg/Bay Point - SFIA/Millbrae 24th St. Mission \n", + "4 Pittsburg/Bay Point - SFIA/Millbrae Balboa Park \n", + "\n", + "source tap_boardings taz_boardings \n", + "0 1200.9943 810.6908 \n", + "1 582.8108 392.6731 \n", + "2 1065.1420 238.4674 \n", + "3 1190.6400 701.2632 \n", + "4 1301.0640 609.8207 " + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result_wide_bart = pd.pivot_table(bart_summary, values=\"boardings\", \n", + " index=[\"period\", \"operator_id\", \"operator\", \"route_id\", \"route\", \"stop_name\"],\n", + " columns=[\"source\"],\n", + " aggfunc=\"sum\").reset_index().rename(columns={\"tap_approach\": \"tap_boardings\",\n", + " \"taz_approach\": \"taz_boardings\"})\n", + "result_wide_bart.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nametap_boardingstaz_boardings
0AM17Caltrain193Bullet22nd St Caltrain282.52500756.62500
1AM17Caltrain193BulletHillsdale Caltrain18.50638721.96240
2AM17Caltrain193BulletMenlo Park Caltrain18.7166753.86667
3AM17Caltrain193BulletMillbrae Caltrain258.64738714.91720
4AM17Caltrain193BulletMt View Caltrain400.91035278.11073
\n", + "
" + ], + "text/plain": [ + "source period operator_id operator route_id route stop_name \\\n", + "0 AM 17 Caltrain 193 Bullet 22nd St Caltrain \n", + "1 AM 17 Caltrain 193 Bullet Hillsdale Caltrain \n", + "2 AM 17 Caltrain 193 Bullet Menlo Park Caltrain \n", + "3 AM 17 Caltrain 193 Bullet Millbrae Caltrain \n", + "4 AM 17 Caltrain 193 Bullet Mt View Caltrain \n", + "\n", + "source tap_boardings taz_boardings \n", + "0 282.52500 756.62500 \n", + "1 18.50638 721.96240 \n", + "2 18.71667 53.86667 \n", + "3 258.64738 714.91720 \n", + "4 400.91035 278.11073 " + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result_wide_caltrain = pd.pivot_table(caltrain_summary, values=\"boardings\", \n", + " index=[\"period\", \"operator_id\", \"operator\", \"route_id\", \"route\", \"stop_name\"],\n", + " columns=[\"source\"],\n", + " aggfunc=\"sum\").reset_index().rename(columns={\"tap_approach\": \"tap_boardings\",\n", + " \"taz_approach\": \"taz_boardings\"})\n", + "result_wide_caltrain.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutetap_boardingstaz_boardings
0AM1Santa Rosa CityBus4649_9 Sebastopol Rd157.335504.650000
1AM1Santa Rosa CityBus46510_10 Coddingtown30.251694.227143
2AM1Santa Rosa CityBus46611_11 Fulton Rd63.960001.253333
3AM1Santa Rosa CityBus46712_12 Roseland85.729680.485161
4AM1Santa Rosa CityBus46814_14 County Center170.6618018.825340
\n", + "
" + ], + "text/plain": [ + "source period operator_id operator route_id route \\\n", + "0 AM 1 Santa Rosa CityBus 464 9_9 Sebastopol Rd \n", + "1 AM 1 Santa Rosa CityBus 465 10_10 Coddingtown \n", + "2 AM 1 Santa Rosa CityBus 466 11_11 Fulton Rd \n", + "3 AM 1 Santa Rosa CityBus 467 12_12 Roseland \n", + "4 AM 1 Santa Rosa CityBus 468 14_14 County Center \n", + "\n", + "source tap_boardings taz_boardings \n", + "0 157.33550 4.650000 \n", + "1 30.25169 4.227143 \n", + "2 63.96000 1.253333 \n", + "3 85.72968 0.485161 \n", + "4 170.66180 18.825340 " + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result_wide_nonrail = pd.pivot_table(non_rail_summary, values=\"boardings\", \n", + " index=[\"period\", \"operator_id\", \"operator\", \"route_id\", \"route\"],\n", + " columns=[\"source\"],\n", + " aggfunc=\"sum\").reset_index().rename(columns={\"tap_approach\": \"tap_boardings\",\n", + " \"taz_approach\": \"taz_boardings\"})\n", + "result_wide_nonrail.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sourceperiodoperator_idoperatorroute_idroutestop_nametap_boardingstaz_boardings
0AM26BART154Pittsburg/Bay Point - SFIA/Millbrae12th St. Oakland City Center1200.9943810.6908
1AM26BART154Pittsburg/Bay Point - SFIA/Millbrae16th St. Mission582.8108392.6731
2AM26BART154Pittsburg/Bay Point - SFIA/Millbrae19th St. Oakland1065.1420238.4674
3AM26BART154Pittsburg/Bay Point - SFIA/Millbrae24th St. Mission1190.6400701.2632
4AM26BART154Pittsburg/Bay Point - SFIA/MillbraeBalboa Park1301.0640609.8207
\n", + "
" + ], + "text/plain": [ + "source period operator_id operator route_id \\\n", + "0 AM 26 BART 154 \n", + "1 AM 26 BART 154 \n", + "2 AM 26 BART 154 \n", + "3 AM 26 BART 154 \n", + "4 AM 26 BART 154 \n", + "\n", + "source route stop_name \\\n", + "0 Pittsburg/Bay Point - SFIA/Millbrae 12th St. Oakland City Center \n", + "1 Pittsburg/Bay Point - SFIA/Millbrae 16th St. Mission \n", + "2 Pittsburg/Bay Point - SFIA/Millbrae 19th St. Oakland \n", + "3 Pittsburg/Bay Point - SFIA/Millbrae 24th St. Mission \n", + "4 Pittsburg/Bay Point - SFIA/Millbrae Balboa Park \n", + "\n", + "source tap_boardings taz_boardings \n", + "0 1200.9943 810.6908 \n", + "1 582.8108 392.6731 \n", + "2 1065.1420 238.4674 \n", + "3 1190.6400 701.2632 \n", + "4 1301.0640 609.8207 " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result_wide = pd.concat([result_wide_bart, result_wide_caltrain, result_wide_nonrail])\n", + "result_wide.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "result_wide.to_csv(\"../../outputs/assignment/boarding_comparison_v6_wide.csv\", index=False)" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "084a36dba6f23ac7a1f7ee017571da24a8de9c2d24087bcf43b216ef24ac300c" + }, + "kernelspec": { + "display_name": "Python 3.7.10 64-bit ('mtc_lasso': conda)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/create-comparison-skim-db.ipynb b/notebooks/create-comparison-skim-db.ipynb new file mode 100644 index 0000000..fa33985 --- /dev/null +++ b/notebooks/create-comparison-skim-db.ipynb @@ -0,0 +1,4230 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import openmatrix as omx\n", + "import geopandas as gpd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
taprenum_tap
0900011
1900022
2900033
3900044
4900055
\n", + "
" + ], + "text/plain": [ + " tap renum_tap\n", + "0 90001 1\n", + "1 90002 2\n", + "2 90003 3\n", + "3 90004 4\n", + "4 90005 5" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data_path = \"../data\"\n", + "zone_seq = pd.read_csv(f\"{data_path}/mtc_final_network_zone_seq_ver12.csv\")\n", + "tap_seq = zone_seq[zone_seq[\"TAPSEQ\"] > 0].drop(columns=[\"TAZSEQ\", \"MAZSEQ\", \"EXTSEQ\"]).rename(columns={\"N\": \"tap\", \"TAPSEQ\": \"renum_tap\"}).reset_index(drop=True)\n", + "tap_seq.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
mazlonlat
010001-122.44107637.750066
110002-122.43893437.750197
210003-122.43627037.756793
310004-122.43704937.753528
410005-122.43395937.755725
\n", + "
" + ], + "text/plain": [ + " maz lon lat\n", + "0 10001 -122.441076 37.750066\n", + "1 10002 -122.438934 37.750197\n", + "2 10003 -122.436270 37.756793\n", + "3 10004 -122.437049 37.753528\n", + "4 10005 -122.433959 37.755725" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "maz_nodes = gpd.read_file(f\"{data_path}/maz_nodes.gpkg\")\n", + "maz_nodes = maz_nodes.to_crs(4326)\n", + "maz_nodes[\"X\"] = maz_nodes[\"geometry\"].apply(lambda p: p.x)\n", + "maz_nodes[\"Y\"] = maz_nodes[\"geometry\"].apply(lambda p: p.y)\n", + "maz_nodes = maz_nodes[[\"N\", \"X\", \"Y\"]].rename(columns={\"N\": \"maz\", \"X\": \"lon\", \"Y\": \"lat\"})\n", + "maz_nodes.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create skim db for TAP approach\n", + "#### import reformatted on-board survey record for the TAP approach" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_time
011420___AC Transit___2018413852414639EA14900584903090.0570.190
111423___AC Transit___2018424701414651EA14900404904620.0540.088
211425___AC Transit___2018418818424101EA14900744900160.0920.021
311730___AC Transit___2018322305329001EA13905703903270.2530.319
411732___AC Transit___2018310894329001EA13906593906050.0520.042
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o tap_d \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 490309 \n", + "1 11423___AC Transit___2018 424701 414651 EA 1 490040 490462 \n", + "2 11425___AC Transit___2018 418818 424101 EA 1 490074 490016 \n", + "3 11730___AC Transit___2018 322305 329001 EA 1 390570 390327 \n", + "4 11732___AC Transit___2018 310894 329001 EA 1 390659 390605 \n", + "\n", + " access_time egress_time \n", + "0 0.057 0.190 \n", + "1 0.054 0.088 \n", + "2 0.092 0.021 \n", + "3 0.253 0.319 \n", + "4 0.052 0.042 " + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tap_base = pd.read_csv(f\"{data_path}/tap_approach/tap_approach_base_table.csv\")\n", + "tap_base.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_time
011420___AC Transit___2018413852414639EA14900584903093.4211.40
111423___AC Transit___2018424701414651EA14900404904623.245.28
211425___AC Transit___2018418818424101EA14900744900165.521.26
311730___AC Transit___2018322305329001EA139057039032715.1819.14
411732___AC Transit___2018310894329001EA13906593906053.122.52
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o tap_d \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 490309 \n", + "1 11423___AC Transit___2018 424701 414651 EA 1 490040 490462 \n", + "2 11425___AC Transit___2018 418818 424101 EA 1 490074 490016 \n", + "3 11730___AC Transit___2018 322305 329001 EA 1 390570 390327 \n", + "4 11732___AC Transit___2018 310894 329001 EA 1 390659 390605 \n", + "\n", + " access_time egress_time \n", + "0 3.42 11.40 \n", + "1 3.24 5.28 \n", + "2 5.52 1.26 \n", + "3 15.18 19.14 \n", + "4 3.12 2.52 " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# change access & egress time unit from hours to minutes\n", + "tap_base[\"access_time\"] = tap_base[\"access_time\"] * 60\n", + "tap_base[\"egress_time\"] = tap_base[\"egress_time\"] * 60\n", + "tap_base.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_timerenum_tap_orenum_tap_d
011420___AC Transit___2018413852414639EA14900584903093.4211.4039464197
111423___AC Transit___2018424701414651EA14900404904623.245.2839284350
211425___AC Transit___2018418818424101EA14900744900165.521.2639623904
311730___AC Transit___2018322305329001EA139057039032715.1819.1430342791
411732___AC Transit___2018310894329001EA13906593906053.122.5231233069
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o tap_d \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 490309 \n", + "1 11423___AC Transit___2018 424701 414651 EA 1 490040 490462 \n", + "2 11425___AC Transit___2018 418818 424101 EA 1 490074 490016 \n", + "3 11730___AC Transit___2018 322305 329001 EA 1 390570 390327 \n", + "4 11732___AC Transit___2018 310894 329001 EA 1 390659 390605 \n", + "\n", + " access_time egress_time renum_tap_o renum_tap_d \n", + "0 3.42 11.40 3946 4197 \n", + "1 3.24 5.28 3928 4350 \n", + "2 5.52 1.26 3962 3904 \n", + "3 15.18 19.14 3034 2791 \n", + "4 3.12 2.52 3123 3069 " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# add renumbered tap num\n", + "tap_base = pd.merge(tap_base, tap_seq, how=\"left\", left_on=\"tap_o\", right_on=\"tap\").drop(columns=[\"tap\"]).rename(columns={\"renum_tap\": \"renum_tap_o\"})\n", + "tap_base = pd.merge(tap_base, tap_seq, how=\"left\", left_on=\"tap_d\", right_on=\"tap\").drop(columns=[\"tap\"]).rename(columns={\"renum_tap\": \"renum_tap_d\"})\n", + "tap_base.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### add corresponding tap-to-tap skim value from omx matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "tap_skim_ea = omx.open_file(f\"{data_path}/tap_approach/skims/transit_skims_ea.omx\")\n", + "tap_skim_am = omx.open_file(f\"{data_path}/tap_approach/skims/transit_skims_am.omx\")\n", + "tap_skim_md = omx.open_file(f\"{data_path}/tap_approach/skims/transit_skims_md.omx\")\n", + "tap_skim_pm = omx.open_file(f\"{data_path}/tap_approach/skims/transit_skims_pm.omx\")\n", + "tap_skim_ev = omx.open_file(f\"{data_path}/tap_approach/skims/transit_skims_ev.omx\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- table name starts with `_BUS` is skim set 1\n", + "- table name starts with `_PREM` is skim set 2\n", + "- table name starts with `_ALLPEN` is skim set 3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def get_tap_skim_value(period, skim_set, tap_o, tap_d):\n", + " # initialize result dictionary\n", + " table_names = [\"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\",]\n", + " result = {}\n", + "\n", + " # select which omx skim file to use\n", + " if period == \"EA\":\n", + " per_skim = tap_skim_ea\n", + " elif period == \"AM\":\n", + " per_skim = tap_skim_am\n", + " elif period == \"MD\":\n", + " per_skim = tap_skim_md\n", + " elif period == \"PM\":\n", + " per_skim = tap_skim_pm\n", + " elif period == \"EV\":\n", + " per_skim = tap_skim_ev\n", + " \n", + " # set string for filtering appropriate skim table based on skim_set argument\n", + " if skim_set == 1:\n", + " skim_set_str = \"BUS\"\n", + " elif skim_set == 2:\n", + " skim_set_str = \"PREM\"\n", + " elif skim_set == 3:\n", + " skim_set_str = \"ALLPEN\"\n", + "\n", + " # populate result dictionary\n", + " for table in table_names:\n", + " result[table] = per_skim[f\"{period.lower()}_{skim_set_str}_{table}\"][tap_o - 1, tap_d - 1] # -1 because matrix starts from index 0\n", + " \n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def add_tap_to_tap_skim_values(base_table):\n", + "\n", + " skim_value_list = []\n", + " for i in range(len(base_table)):\n", + " period = base_table.loc[i, \"period\"]\n", + " skim_set = base_table.loc[i, \"skim_set\"]\n", + " tap_o = base_table.loc[i, \"renum_tap_o\"]\n", + " tap_d = base_table.loc[i, \"renum_tap_d\"]\n", + " \n", + " skim_value_list.append(get_tap_skim_value(period, skim_set, tap_o, tap_d))\n", + "\n", + " skim_values = pd.DataFrame(skim_value_list)\n", + "\n", + " return pd.concat([base_table, skim_values], axis = 1)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "85209\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_timerenum_tap_o...HRIVTTLBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALK
011420___AC Transit___2018413852414639EA14900584903093.4211.403946...0.00.0000000.00.00.00000045.016.5715013.030.015.911501
111423___AC Transit___2018424701414651EA14900404904623.245.283928...0.011.9701700.00.011.97017030.010.8058392.015.010.145839
211425___AC Transit___2018418818424101EA14900744900165.521.263962...0.010.7337580.00.010.73375830.02.3043141.015.01.644314
311730___AC Transit___2018322305329001EA139057039032715.1819.143034...0.018.9256900.00.018.92569015.00.4000000.00.00.000000
411732___AC Transit___2018310894329001EA13906593906053.122.523123...0.02.6975660.00.02.69756615.00.4000000.00.00.000000
\n", + "

5 rows × 29 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o tap_d \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 490309 \n", + "1 11423___AC Transit___2018 424701 414651 EA 1 490040 490462 \n", + "2 11425___AC Transit___2018 418818 424101 EA 1 490074 490016 \n", + "3 11730___AC Transit___2018 322305 329001 EA 1 390570 390327 \n", + "4 11732___AC Transit___2018 310894 329001 EA 1 390659 390605 \n", + "\n", + " access_time egress_time renum_tap_o ... HRIVTT LBIVTT LINKREL \\\n", + "0 3.42 11.40 3946 ... 0.0 0.000000 0.0 \n", + "1 3.24 5.28 3928 ... 0.0 11.970170 0.0 \n", + "2 5.52 1.26 3962 ... 0.0 10.733758 0.0 \n", + "3 15.18 19.14 3034 ... 0.0 18.925690 0.0 \n", + "4 3.12 2.52 3123 ... 0.0 2.697566 0.0 \n", + "\n", + " LRIVTT TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK \n", + "0 0.0 0.000000 45.0 16.571501 3.0 30.0 15.911501 \n", + "1 0.0 11.970170 30.0 10.805839 2.0 15.0 10.145839 \n", + "2 0.0 10.733758 30.0 2.304314 1.0 15.0 1.644314 \n", + "3 0.0 18.925690 15.0 0.400000 0.0 0.0 0.000000 \n", + "4 0.0 2.697566 15.0 0.400000 0.0 0.0 0.000000 \n", + "\n", + "[5 rows x 29 columns]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tap_approach_db = add_tap_to_tap_skim_values(tap_base)\n", + "print(len(tap_approach_db))\n", + "tap_approach_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_timerenum_tap_o...LBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIME
011420___AC Transit___2018413852414639EA14900584903093.4211.403946...0.0000000.00.00.00000045.016.5715013.030.015.91150175.731501
111423___AC Transit___2018424701414651EA14900404904623.245.283928...11.9701700.00.011.97017030.010.8058392.015.010.14583960.636009
211425___AC Transit___2018418818424101EA14900744900165.521.263962...10.7337580.00.010.73375830.02.3043141.015.01.64431449.158072
311730___AC Transit___2018322305329001EA139057039032715.1819.143034...18.9256900.00.018.92569015.00.4000000.00.00.00000068.245690
411732___AC Transit___2018310894329001EA13906593906053.122.523123...2.6975660.00.02.69756615.00.4000000.00.00.00000023.337566
\n", + "

5 rows × 30 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o tap_d \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 490309 \n", + "1 11423___AC Transit___2018 424701 414651 EA 1 490040 490462 \n", + "2 11425___AC Transit___2018 418818 424101 EA 1 490074 490016 \n", + "3 11730___AC Transit___2018 322305 329001 EA 1 390570 390327 \n", + "4 11732___AC Transit___2018 310894 329001 EA 1 390659 390605 \n", + "\n", + " access_time egress_time renum_tap_o ... LBIVTT LINKREL LRIVTT \\\n", + "0 3.42 11.40 3946 ... 0.000000 0.0 0.0 \n", + "1 3.24 5.28 3928 ... 11.970170 0.0 0.0 \n", + "2 5.52 1.26 3962 ... 10.733758 0.0 0.0 \n", + "3 15.18 19.14 3034 ... 18.925690 0.0 0.0 \n", + "4 3.12 2.52 3123 ... 2.697566 0.0 0.0 \n", + "\n", + " TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK TOTAL_TIME \n", + "0 0.000000 45.0 16.571501 3.0 30.0 15.911501 75.731501 \n", + "1 11.970170 30.0 10.805839 2.0 15.0 10.145839 60.636009 \n", + "2 10.733758 30.0 2.304314 1.0 15.0 1.644314 49.158072 \n", + "3 18.925690 15.0 0.400000 0.0 0.0 0.000000 68.245690 \n", + "4 2.697566 15.0 0.400000 0.0 0.0 0.000000 23.337566 \n", + "\n", + "[5 rows x 30 columns]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# add total time column\n", + "tap_approach_db[\"TOTAL_TIME\"] = tap_approach_db[\"access_time\"] + tap_approach_db[\"egress_time\"] + tap_approach_db[\"TOTALIVTT\"] + tap_approach_db[\"TOTALWAIT\"] + tap_approach_db[\"XFERWALK\"]\n", + "tap_approach_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dperiodskim_settap_otap_daccess_timeegress_timerenum_tap_o...LBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIME
011420___AC Transit___2018413852414639EA1490058490309NaNNaN3946...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
663295___AC Transit___2018310449311366EA1391021390524NaNNaN3485...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
137671___LAVTA___2018312402317158EA1390242390959NaNNaN2706...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
2201326___SF Muni___20171732313034EA19027990151NaNNaN279...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
4132012___SF Muni___201711850714635EA119019290108NaNNaN768...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
\n", + "

5 rows × 30 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d period skim_set tap_o \\\n", + "0 11420___AC Transit___2018 413852 414639 EA 1 490058 \n", + "66 3295___AC Transit___2018 310449 311366 EA 1 391021 \n", + "137 671___LAVTA___2018 312402 317158 EA 1 390242 \n", + "220 1326___SF Muni___2017 17323 13034 EA 1 90279 \n", + "413 2012___SF Muni___2017 118507 14635 EA 1 190192 \n", + "\n", + " tap_d access_time egress_time renum_tap_o ... LBIVTT LINKREL \\\n", + "0 490309 NaN NaN 3946 ... NaN NaN \n", + "66 390524 NaN NaN 3485 ... NaN NaN \n", + "137 390959 NaN NaN 2706 ... NaN NaN \n", + "220 90151 NaN NaN 279 ... NaN NaN \n", + "413 90108 NaN NaN 768 ... NaN NaN \n", + "\n", + " LRIVTT TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK \\\n", + "0 NaN 0.0 NaN NaN NaN NaN NaN \n", + "66 NaN 0.0 NaN NaN NaN NaN NaN \n", + "137 NaN 0.0 NaN NaN NaN NaN NaN \n", + "220 NaN 0.0 NaN NaN NaN NaN NaN \n", + "413 NaN 0.0 NaN NaN NaN NaN NaN \n", + "\n", + " TOTAL_TIME \n", + "0 NaN \n", + "66 NaN \n", + "137 NaN \n", + "220 NaN \n", + "413 NaN \n", + "\n", + "[5 rows x 30 columns]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# if TOTALIVTT == 0, set TOTAL_TIME = \"NA\"\n", + "# for walk-only paths, set all skim values to null\n", + "for column_name in [\"access_time\", \"egress_time\", \"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\", \"TOTAL_TIME\"]:\n", + " tap_approach_db.loc[tap_approach_db[\"TOTALIVTT\"] == 0, column_name] = np.nan\n", + "temp = tap_approach_db[tap_approach_db[\"TOTALIVTT\"] == 0]\n", + "temp.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### add perceived time info\n", + "- Settings for TAP run:\n", + " - initial_wait_perception_factor = 1.5\n", + " - transfer_wait_perception_factor = 3.0\n", + " - walk_perception_factor = 2.0\n", + " - in_vehicle_perception_factor = 1.0\n", + " - initial_boarding_penalty = 10\n", + " - transfer_boarding_penalty = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "TAP_INITIAL_WAIT_PERCEPTION_FACTOR = 1.5\n", + "TAP_TRANSFER_WAIT_PERCEPTION_FACTOR = 3.0\n", + "TAP_WALK_PERCEPTION_FACTOR = 2.0\n", + "TAP_IN_VEHICLE_PERCEPTION_FACTOR = 1.0\n", + "TAP_INITIAL_BOARDING_PENALTY = 10\n", + "TAP_TRANSFER_BOARDING_PENALTY = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "# add perception total time\n", + "tap_approach_db[\"TOTAL_PERCEIVED_TIME\"] = TAP_INITIAL_WAIT_PERCEPTION_FACTOR * tap_approach_db[\"FIRSTWAIT\"] + TAP_TRANSFER_WAIT_PERCEPTION_FACTOR * tap_approach_db[\"XFERWAIT\"] + TAP_WALK_PERCEPTION_FACTOR * (tap_approach_db[\"access_time\"] + tap_approach_db[\"egress_time\"] + tap_approach_db[\"XFERWALK\"]) + TAP_IN_VEHICLE_PERCEPTION_FACTOR * tap_approach_db[\"TOTALIVTT\"] + TAP_INITIAL_BOARDING_PENALTY + TAP_TRANSFER_BOARDING_PENALTY * tap_approach_db[\"XFERS\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_settap_o...LINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIMETOTAL_PERCEIVED_TIME
011420___AC Transit___2018413852414639-122.29976737.904587-122.31976337.979455EA1490058...NaNNaN0.000000NaNNaNNaNNaNNaNNaNNaN
111423___AC Transit___2018424701414651-122.32670237.921951-122.32178937.986542EA1490040...0.00.011.97017030.010.8058392.015.010.14583960.636009146.801847
211425___AC Transit___2018418818424101-122.36267737.937884-122.32884337.990794EA1490074...0.00.010.73375830.02.3043141.015.01.64431449.158072115.082385
311730___AC Transit___2018322305329001-122.11142037.698752-122.23093037.798295EA1390570...0.00.018.92569015.00.4000000.00.00.00000068.245690120.065690
411732___AC Transit___2018310894329001-122.23028637.788432-122.23093037.798295EA1390659...0.00.02.69756615.00.4000000.00.00.00000023.33756646.477566
\n", + "

5 rows × 35 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d maz_o_lon maz_o_lat \\\n", + "0 11420___AC Transit___2018 413852 414639 -122.299767 37.904587 \n", + "1 11423___AC Transit___2018 424701 414651 -122.326702 37.921951 \n", + "2 11425___AC Transit___2018 418818 424101 -122.362677 37.937884 \n", + "3 11730___AC Transit___2018 322305 329001 -122.111420 37.698752 \n", + "4 11732___AC Transit___2018 310894 329001 -122.230286 37.788432 \n", + "\n", + " maz_d_lon maz_d_lat period skim_set tap_o ... LINKREL LRIVTT \\\n", + "0 -122.319763 37.979455 EA 1 490058 ... NaN NaN \n", + "1 -122.321789 37.986542 EA 1 490040 ... 0.0 0.0 \n", + "2 -122.328843 37.990794 EA 1 490074 ... 0.0 0.0 \n", + "3 -122.230930 37.798295 EA 1 390570 ... 0.0 0.0 \n", + "4 -122.230930 37.798295 EA 1 390659 ... 0.0 0.0 \n", + "\n", + " TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK TOTAL_TIME \\\n", + "0 0.000000 NaN NaN NaN NaN NaN NaN \n", + "1 11.970170 30.0 10.805839 2.0 15.0 10.145839 60.636009 \n", + "2 10.733758 30.0 2.304314 1.0 15.0 1.644314 49.158072 \n", + "3 18.925690 15.0 0.400000 0.0 0.0 0.000000 68.245690 \n", + "4 2.697566 15.0 0.400000 0.0 0.0 0.000000 23.337566 \n", + "\n", + " TOTAL_PERCEIVED_TIME \n", + "0 NaN \n", + "1 146.801847 \n", + "2 115.082385 \n", + "3 120.065690 \n", + "4 46.477566 \n", + "\n", + "[5 rows x 35 columns]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "## add maz coordinates\n", + "tap_approach_db = pd.merge(tap_approach_db, maz_nodes, how=\"left\", left_on=\"maz_o\", right_on=\"maz\")\n", + "tap_approach_db = tap_approach_db.rename(columns={\"lon\": \"maz_o_lon\", \"lat\": \"maz_o_lat\"}).drop(columns=\"maz\")\n", + "tap_approach_db = pd.merge(tap_approach_db, maz_nodes, how=\"left\", left_on=\"maz_d\", right_on=\"maz\")\n", + "tap_approach_db = tap_approach_db.rename(columns={\"lon\": \"maz_d_lon\", \"lat\": \"maz_d_lat\"}).drop(columns=\"maz\")\n", + "tap_approach_db = tap_approach_db[['unique_ID', 'maz_o', 'maz_d', 'maz_o_lon',\n", + " 'maz_o_lat', 'maz_d_lon', 'maz_d_lat', 'period', 'skim_set', 'tap_o', 'tap_d',\n", + " 'access_time', 'egress_time', 'renum_tap_o', 'renum_tap_d', 'CAPPEN',\n", + " 'CRIVTT', 'CROWD', 'EAWT', 'EBIVTT', 'FARE', 'FIRSTWAIT', 'FRIVTT',\n", + " 'HRIVTT', 'LBIVTT', 'LINKREL', 'LRIVTT', 'TOTALIVTT', 'TOTALWAIT',\n", + " 'TOTALWALK', 'XFERS', 'XFERWAIT', 'XFERWALK', 'TOTAL_TIME', 'TOTAL_PERCEIVED_TIME']]\n", + "tap_approach_db.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create skim db for TAZ approach\n", + "#### import TAZ lookups" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
maztaz
01000156
11000256
21000310
31000453
41000548
\n", + "
" + ], + "text/plain": [ + " maz taz\n", + "0 10001 56\n", + "1 10002 56\n", + "2 10003 10\n", + "3 10004 53\n", + "4 10005 48" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cube_taz_lookup = pd.read_csv(f\"{data_path}/maz_data_withDensity.csv\")\n", + "cube_taz_lookup = cube_taz_lookup[[\"MAZ_ORIGINAL\", \"TAZ_ORIGINAL\"]].rename(columns={\"MAZ_ORIGINAL\": \"maz\", \"TAZ_ORIGINAL\": \"taz\"})\n", + "cube_taz_lookup.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
emme_tazcube_taz
011
122
233
344
455
\n", + "
" + ], + "text/plain": [ + " emme_taz cube_taz\n", + "0 1 1\n", + "1 2 2\n", + "2 3 3\n", + "3 4 4\n", + "4 5 5" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "emme_taz_lookup = pd.read_csv(f\"{data_path}/taz_approach/emme_taz_transit_network_node_id_crosswalk.csv\").rename(columns={\"emme_node_id\": \"emme_taz\", \"model_node_id\": \"cube_taz\"})\n", + "emme_taz_lookup.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### import reformatted on-board survey record for the TAZ approach" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dperiodskim_set
01___AC Transit___2018404362011514425106PM3
110___AC Transit___201823452878316876324992AM1
2100___AC Transit___201829712138318567318470PM1
31000___AC Transit___201823122137327175325899AM1
410000___AC Transit___201820772481323825318288MD1
\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d period skim_set\n", + "0 1___AC Transit___2018 404 3620 11514 425106 PM 3\n", + "1 10___AC Transit___2018 2345 2878 316876 324992 AM 1\n", + "2 100___AC Transit___2018 2971 2138 318567 318470 PM 1\n", + "3 1000___AC Transit___2018 2312 2137 327175 325899 AM 1\n", + "4 10000___AC Transit___2018 2077 2481 323825 318288 MD 1" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "taz_base = pd.read_csv(f\"{data_path}/taz_approach/taz_approach_base_table.csv\").drop(columns=[\"taz_o\", \"taz_d\"])\n", + "taz_base = pd.merge(taz_base, cube_taz_lookup, how=\"left\", left_on=\"maz_o\", right_on=\"maz\").drop(columns=\"maz\").rename(columns={\"taz\": \"cube_taz_o\"})\n", + "taz_base = pd.merge(taz_base, cube_taz_lookup, how=\"left\", left_on=\"maz_d\", right_on=\"maz\").drop(columns=\"maz\").rename(columns={\"taz\": \"cube_taz_d\"})\n", + "taz_base = pd.merge(taz_base, emme_taz_lookup, how=\"left\", left_on=\"cube_taz_o\", right_on=\"cube_taz\").drop(columns=\"cube_taz\").rename(columns={\"emme_taz\": \"emme_taz_o\"})\n", + "taz_base = pd.merge(taz_base, emme_taz_lookup, how=\"left\", left_on=\"cube_taz_d\", right_on=\"cube_taz\").drop(columns=\"cube_taz\").rename(columns={\"emme_taz\": \"emme_taz_d\"})\n", + "taz_base = taz_base[[\"unique_ID\", \"emme_taz_o\", \"emme_taz_d\", \"maz_o\", \"maz_d\", \"period\", \"skim_set\"]].rename(columns={\"emme_taz_o\": \"taz_o\", \"emme_taz_d\": \"taz_d\"})\n", + "taz_base.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### add estimated (1) walk access time for maz_o (2) walk egress time for maz_d" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
skim_setperiodmaz_oaccess_time
01AM100015.319
11AM100025.387
21AM100037.442
31AM100045.349
41AM100056.454
\n", + "
" + ], + "text/plain": [ + " skim_set period maz_o access_time\n", + "0 1 AM 10001 5.319\n", + "1 1 AM 10002 5.387\n", + "2 1 AM 10003 7.442\n", + "3 1 AM 10004 5.349\n", + "4 1 AM 10005 6.454" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "est_maz_walk_access_time = pd.read_csv(f\"{data_path}/taz_approach/estimated_maz_access_walk_time.csv\")\n", + "est_maz_walk_access_time = est_maz_walk_access_time.rename(columns={\"time_period\": \"period\", \"from_maz\": \"maz_o\", \"est_maz_walk_access_min\": \"access_time\"})\n", + "est_maz_walk_access_time.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
skim_setperiodmaz_degress_time
01AM100015.878
11AM100026.346
21AM100036.819
31AM100045.268
41AM100055.868
\n", + "
" + ], + "text/plain": [ + " skim_set period maz_d egress_time\n", + "0 1 AM 10001 5.878\n", + "1 1 AM 10002 6.346\n", + "2 1 AM 10003 6.819\n", + "3 1 AM 10004 5.268\n", + "4 1 AM 10005 5.868" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "est_maz_walk_egress_time = pd.read_csv(f\"{data_path}/taz_approach/estimated_maz_egress_walk_time.csv\")\n", + "est_maz_walk_egress_time = est_maz_walk_egress_time.rename(columns={\"time_period\": \"period\", \"to_maz\": \"maz_d\", \"est_maz_walk_egress_min\": \"egress_time\"})\n", + "est_maz_walk_egress_time.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dperiodskim_setaccess_timeegress_time
01___AC Transit___2018404362011514425106PM37.7195.306
110___AC Transit___201823452878316876324992AM16.1813.450
2100___AC Transit___201829712138318567318470PM12.9917.930
31000___AC Transit___201823122137327175325899AM12.2936.646
410000___AC Transit___201820772481323825318288MD19.9025.191
\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d period skim_set \\\n", + "0 1___AC Transit___2018 404 3620 11514 425106 PM 3 \n", + "1 10___AC Transit___2018 2345 2878 316876 324992 AM 1 \n", + "2 100___AC Transit___2018 2971 2138 318567 318470 PM 1 \n", + "3 1000___AC Transit___2018 2312 2137 327175 325899 AM 1 \n", + "4 10000___AC Transit___2018 2077 2481 323825 318288 MD 1 \n", + "\n", + " access_time egress_time \n", + "0 7.719 5.306 \n", + "1 6.181 3.450 \n", + "2 2.991 7.930 \n", + "3 2.293 6.646 \n", + "4 9.902 5.191 " + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "taz_base = pd.merge(taz_base, est_maz_walk_access_time, how=\"left\", on=[\"period\", \"skim_set\", \"maz_o\"])\n", + "taz_base = pd.merge(taz_base, est_maz_walk_egress_time, how=\"left\", on=[\"period\", \"skim_set\", \"maz_d\"])\n", + "taz_base.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### add corresponding taz-to-taz skim value from omx matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "taz_skim_ea = omx.open_file(f\"{data_path}/taz_approach/skims/transit_skims_ea.omx\")\n", + "taz_skim_am = omx.open_file(f\"{data_path}/taz_approach/skims/transit_skims_am.omx\")\n", + "taz_skim_md = omx.open_file(f\"{data_path}/taz_approach/skims/transit_skims_md.omx\")\n", + "taz_skim_pm = omx.open_file(f\"{data_path}/taz_approach/skims/transit_skims_pm.omx\")\n", + "taz_skim_ev = omx.open_file(f\"{data_path}/taz_approach/skims/transit_skims_ev.omx\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "def get_taz_skim_value(period, skim_set, taz_o, taz_d):\n", + " # initialize result dictionary\n", + " table_names = [\"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\",]\n", + " result = {}\n", + "\n", + " # select which omx skim file to use\n", + " if period == \"EA\":\n", + " per_skim = taz_skim_ea\n", + " elif period == \"AM\":\n", + " per_skim = taz_skim_am\n", + " elif period == \"MD\":\n", + " per_skim = taz_skim_md\n", + " elif period == \"PM\":\n", + " per_skim = taz_skim_pm\n", + " elif period == \"EV\":\n", + " per_skim = taz_skim_ev\n", + " \n", + " # set string for filtering appropriate skim table based on skim_set argument\n", + " if skim_set == 1:\n", + " skim_set_str = \"BUS\"\n", + " elif skim_set == 2:\n", + " skim_set_str = \"PREM\"\n", + " elif skim_set == 3:\n", + " skim_set_str = \"ALLPEN\"\n", + "\n", + " # populate result dictionary\n", + " for table in table_names:\n", + " result[table] = per_skim[f\"{period.lower()}_{skim_set_str}_{table}\"][taz_o - 1, taz_d - 1] # -1 because matrix starts from index 0\n", + " \n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "def add_taz_to_taz_skim_values(base_table):\n", + "\n", + " skim_value_list = []\n", + " for i in range(len(base_table)):\n", + " period = base_table.loc[i, \"period\"]\n", + " skim_set = base_table.loc[i, \"skim_set\"]\n", + " taz_o = base_table.loc[i, \"taz_o\"]\n", + " taz_d = base_table.loc[i, \"taz_d\"]\n", + " \n", + " skim_value_list.append(get_taz_skim_value(period, skim_set, taz_o, taz_d))\n", + "\n", + " skim_values = pd.DataFrame(skim_value_list)\n", + "\n", + " return pd.concat([base_table, skim_values], axis = 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "97842\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dperiodskim_setaccess_timeegress_timeCAPPEN...HRIVTTLBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALK
01___AC Transit___2018404362011514425106PM37.7195.3060.0...34.00.0000000.00.034.0000007.5000001.7434290.00.01.743429
110___AC Transit___201823452878316876324992AM16.1813.4500.0...0.011.9324830.00.011.9324833.58620714.2673230.00.014.267323
2100___AC Transit___201829712138318567318470PM12.9917.9300.0...0.04.4643170.00.04.4643173.75000034.5199890.00.034.519989
31000___AC Transit___201823122137327175325899AM12.2936.6460.0...0.04.5591680.00.04.5591683.5862070.0000000.00.00.000000
410000___AC Transit___201820772481323825318288MD19.9025.1910.0...0.02.9849650.00.02.9849657.50000033.5212550.00.033.521255
\n", + "

5 rows × 27 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d period skim_set \\\n", + "0 1___AC Transit___2018 404 3620 11514 425106 PM 3 \n", + "1 10___AC Transit___2018 2345 2878 316876 324992 AM 1 \n", + "2 100___AC Transit___2018 2971 2138 318567 318470 PM 1 \n", + "3 1000___AC Transit___2018 2312 2137 327175 325899 AM 1 \n", + "4 10000___AC Transit___2018 2077 2481 323825 318288 MD 1 \n", + "\n", + " access_time egress_time CAPPEN ... HRIVTT LBIVTT LINKREL LRIVTT \\\n", + "0 7.719 5.306 0.0 ... 34.0 0.000000 0.0 0.0 \n", + "1 6.181 3.450 0.0 ... 0.0 11.932483 0.0 0.0 \n", + "2 2.991 7.930 0.0 ... 0.0 4.464317 0.0 0.0 \n", + "3 2.293 6.646 0.0 ... 0.0 4.559168 0.0 0.0 \n", + "4 9.902 5.191 0.0 ... 0.0 2.984965 0.0 0.0 \n", + "\n", + " TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK \n", + "0 34.000000 7.500000 1.743429 0.0 0.0 1.743429 \n", + "1 11.932483 3.586207 14.267323 0.0 0.0 14.267323 \n", + "2 4.464317 3.750000 34.519989 0.0 0.0 34.519989 \n", + "3 4.559168 3.586207 0.000000 0.0 0.0 0.000000 \n", + "4 2.984965 7.500000 33.521255 0.0 0.0 33.521255 \n", + "\n", + "[5 rows x 27 columns]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "taz_approach_db = add_taz_to_taz_skim_values(taz_base)\n", + "print(len(taz_approach_db))\n", + "taz_approach_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dperiodskim_setaccess_timeegress_timeCAPPEN...LBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIME
01___AC Transit___2018404362011514425106PM37.7195.3060.0...0.0000000.00.034.0000007.5000001.7434290.00.01.74342956.268429
110___AC Transit___201823452878316876324992AM16.1813.4500.0...11.9324830.00.011.9324833.58620714.2673230.00.014.26732339.417012
2100___AC Transit___201829712138318567318470PM12.9917.9300.0...4.4643170.00.04.4643173.75000034.5199890.00.034.51998953.655306
31000___AC Transit___201823122137327175325899AM12.2936.6460.0...4.5591680.00.04.5591683.5862070.0000000.00.00.00000017.084375
410000___AC Transit___201820772481323825318288MD19.9025.1910.0...2.9849650.00.02.9849657.50000033.5212550.00.033.52125559.099220
\n", + "

5 rows × 28 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d period skim_set \\\n", + "0 1___AC Transit___2018 404 3620 11514 425106 PM 3 \n", + "1 10___AC Transit___2018 2345 2878 316876 324992 AM 1 \n", + "2 100___AC Transit___2018 2971 2138 318567 318470 PM 1 \n", + "3 1000___AC Transit___2018 2312 2137 327175 325899 AM 1 \n", + "4 10000___AC Transit___2018 2077 2481 323825 318288 MD 1 \n", + "\n", + " access_time egress_time CAPPEN ... LBIVTT LINKREL LRIVTT \\\n", + "0 7.719 5.306 0.0 ... 0.000000 0.0 0.0 \n", + "1 6.181 3.450 0.0 ... 11.932483 0.0 0.0 \n", + "2 2.991 7.930 0.0 ... 4.464317 0.0 0.0 \n", + "3 2.293 6.646 0.0 ... 4.559168 0.0 0.0 \n", + "4 9.902 5.191 0.0 ... 2.984965 0.0 0.0 \n", + "\n", + " TOTALIVTT TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK TOTAL_TIME \n", + "0 34.000000 7.500000 1.743429 0.0 0.0 1.743429 56.268429 \n", + "1 11.932483 3.586207 14.267323 0.0 0.0 14.267323 39.417012 \n", + "2 4.464317 3.750000 34.519989 0.0 0.0 34.519989 53.655306 \n", + "3 4.559168 3.586207 0.000000 0.0 0.0 0.000000 17.084375 \n", + "4 2.984965 7.500000 33.521255 0.0 0.0 33.521255 59.099220 \n", + "\n", + "[5 rows x 28 columns]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# add total time column\n", + "taz_approach_db[\"TOTAL_TIME\"] = taz_approach_db[\"access_time\"] + taz_approach_db[\"egress_time\"] + taz_approach_db[\"TOTALIVTT\"] + taz_approach_db[\"TOTALWAIT\"] + taz_approach_db[\"XFERWALK\"]\n", + "taz_approach_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dperiodskim_setaccess_timeegress_timeCAPPEN...LBIVTTLINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIME
1610011___AC Transit___201828762681319133312527MD1NaNNaNNaN...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
3910033___AC Transit___201812432242212251314907MD1NaNNaNNaN...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
4510039___AC Transit___201822122499330901313992MD1NaNNaNNaN...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
5110044___AC Transit___201835713570420964415454MD1NaNNaNNaN...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
571005___AC Transit___201823632136327261315627AM1NaNNaNNaN...NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
\n", + "

5 rows × 28 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d period skim_set \\\n", + "16 10011___AC Transit___2018 2876 2681 319133 312527 MD 1 \n", + "39 10033___AC Transit___2018 1243 2242 212251 314907 MD 1 \n", + "45 10039___AC Transit___2018 2212 2499 330901 313992 MD 1 \n", + "51 10044___AC Transit___2018 3571 3570 420964 415454 MD 1 \n", + "57 1005___AC Transit___2018 2363 2136 327261 315627 AM 1 \n", + "\n", + " access_time egress_time CAPPEN ... LBIVTT LINKREL LRIVTT TOTALIVTT \\\n", + "16 NaN NaN NaN ... NaN NaN NaN 0.0 \n", + "39 NaN NaN NaN ... NaN NaN NaN 0.0 \n", + "45 NaN NaN NaN ... NaN NaN NaN 0.0 \n", + "51 NaN NaN NaN ... NaN NaN NaN 0.0 \n", + "57 NaN NaN NaN ... NaN NaN NaN 0.0 \n", + "\n", + " TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK TOTAL_TIME \n", + "16 NaN NaN NaN NaN NaN NaN \n", + "39 NaN NaN NaN NaN NaN NaN \n", + "45 NaN NaN NaN NaN NaN NaN \n", + "51 NaN NaN NaN NaN NaN NaN \n", + "57 NaN NaN NaN NaN NaN NaN \n", + "\n", + "[5 rows x 28 columns]" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# if TOTALIVTT == 0, set TOTAL_TIME = \"NA\"\n", + "# for walk-only paths, set all skim values to null\n", + "for column_name in [\"access_time\", \"egress_time\", \"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\", \"TOTAL_TIME\"]:\n", + " taz_approach_db.loc[taz_approach_db[\"TOTALIVTT\"] == 0, column_name] = np.nan\n", + "temp = taz_approach_db[taz_approach_db[\"TOTALIVTT\"] == 0]\n", + "temp.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### add perceived time info\n", + "- Settings for TAZ run:\n", + " - initial_wait_perception_factor = 1.5\n", + " - transfer_wait_perception_factor = 3.0\n", + " - walk_perception_factor = 2.0\n", + " - in_vehicle_perception_factor = 1.0\n", + " - initial_boarding_penalty = 10\n", + " - transfer_boarding_penalty = 40" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "TAZ_INITIAL_WAIT_PERCEPTION_FACTOR = 1.5\n", + "TAZ_TRANSFER_WAIT_PERCEPTION_FACTOR = 3.0\n", + "TAZ_WALK_PERCEPTION_FACTOR = 2.0\n", + "TAZ_IN_VEHICLE_PERCEPTION_FACTOR = 1.0\n", + "TAZ_INITIAL_BOARDING_PENALTY = 10\n", + "TAZ_TRANSFER_BOARDING_PENALTY = 40" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "# add perception total time\n", + "taz_approach_db[\"TOTAL_PERCEIVED_TIME\"] = TAZ_INITIAL_WAIT_PERCEPTION_FACTOR * taz_approach_db[\"FIRSTWAIT\"] + TAZ_TRANSFER_WAIT_PERCEPTION_FACTOR * taz_approach_db[\"XFERWAIT\"] + TAZ_WALK_PERCEPTION_FACTOR * (taz_approach_db[\"access_time\"] + taz_approach_db[\"egress_time\"] + taz_approach_db[\"XFERWALK\"]) + TAZ_IN_VEHICLE_PERCEPTION_FACTOR * taz_approach_db[\"TOTALIVTT\"] + TAZ_INITIAL_BOARDING_PENALTY + TAZ_TRANSFER_BOARDING_PENALTY * taz_approach_db[\"XFERS\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDtaz_otaz_dmaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiod...LINKRELLRIVTTTOTALIVTTTOTALWAITTOTALWALKXFERSXFERWAITXFERWALKTOTAL_TIMETOTAL_PERCEIVED_TIME
01___AC Transit___2018404362011514425106-122.40979537.773544-122.34527937.934689PM...0.00.034.0000007.5000001.7434290.00.01.74342956.26842984.786859
110___AC Transit___201823452878316876324992-122.28314337.814792-122.19978737.766251AM...0.00.011.9324833.58620714.2673230.00.014.26732339.41701275.108438
2100___AC Transit___201829712138318567318470-122.17785637.714332-122.16525837.745239PM...0.00.04.4643173.75000034.5199890.00.034.51998953.655306110.971295
31000___AC Transit___201823122137327175325899-122.19799037.765282-122.16333137.737274AM...0.00.04.5591683.5862070.0000000.00.00.00000017.08437537.816478
410000___AC Transit___201820772481323825318288-122.18870237.793200-122.24760637.755097MD...0.00.02.9849657.50000033.5212550.00.033.52125559.099220121.463476
\n", + "

5 rows × 33 columns

\n", + "
" + ], + "text/plain": [ + " unique_ID taz_o taz_d maz_o maz_d maz_o_lon \\\n", + "0 1___AC Transit___2018 404 3620 11514 425106 -122.409795 \n", + "1 10___AC Transit___2018 2345 2878 316876 324992 -122.283143 \n", + "2 100___AC Transit___2018 2971 2138 318567 318470 -122.177856 \n", + "3 1000___AC Transit___2018 2312 2137 327175 325899 -122.197990 \n", + "4 10000___AC Transit___2018 2077 2481 323825 318288 -122.188702 \n", + "\n", + " maz_o_lat maz_d_lon maz_d_lat period ... LINKREL LRIVTT TOTALIVTT \\\n", + "0 37.773544 -122.345279 37.934689 PM ... 0.0 0.0 34.000000 \n", + "1 37.814792 -122.199787 37.766251 AM ... 0.0 0.0 11.932483 \n", + "2 37.714332 -122.165258 37.745239 PM ... 0.0 0.0 4.464317 \n", + "3 37.765282 -122.163331 37.737274 AM ... 0.0 0.0 4.559168 \n", + "4 37.793200 -122.247606 37.755097 MD ... 0.0 0.0 2.984965 \n", + "\n", + " TOTALWAIT TOTALWALK XFERS XFERWAIT XFERWALK TOTAL_TIME \\\n", + "0 7.500000 1.743429 0.0 0.0 1.743429 56.268429 \n", + "1 3.586207 14.267323 0.0 0.0 14.267323 39.417012 \n", + "2 3.750000 34.519989 0.0 0.0 34.519989 53.655306 \n", + "3 3.586207 0.000000 0.0 0.0 0.000000 17.084375 \n", + "4 7.500000 33.521255 0.0 0.0 33.521255 59.099220 \n", + "\n", + " TOTAL_PERCEIVED_TIME \n", + "0 84.786859 \n", + "1 75.108438 \n", + "2 110.971295 \n", + "3 37.816478 \n", + "4 121.463476 \n", + "\n", + "[5 rows x 33 columns]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "## add maz coordinates\n", + "taz_approach_db = pd.merge(taz_approach_db, maz_nodes, how=\"left\", left_on=\"maz_o\", right_on=\"maz\")\n", + "taz_approach_db = taz_approach_db.rename(columns={\"lon\": \"maz_o_lon\", \"lat\": \"maz_o_lat\"}).drop(columns=\"maz\")\n", + "taz_approach_db = pd.merge(taz_approach_db, maz_nodes, how=\"left\", left_on=\"maz_d\", right_on=\"maz\")\n", + "taz_approach_db = taz_approach_db.rename(columns={\"lon\": \"maz_d_lon\", \"lat\": \"maz_d_lat\"}).drop(columns=\"maz\")\n", + "taz_approach_db = taz_approach_db[['unique_ID', 'taz_o', 'taz_d', 'maz_o', 'maz_d', 'maz_o_lon',\n", + " 'maz_o_lat', 'maz_d_lon', 'maz_d_lat', 'period', 'skim_set',\n", + " 'access_time', 'egress_time', 'CAPPEN',\n", + " 'CRIVTT', 'CROWD', 'EAWT', 'EBIVTT', 'FARE', 'FIRSTWAIT', 'FRIVTT',\n", + " 'HRIVTT', 'LBIVTT', 'LINKREL', 'LRIVTT', 'TOTALIVTT', 'TOTALWAIT',\n", + " 'TOTALWALK', 'XFERS', 'XFERWAIT', 'XFERWALK', 'TOTAL_TIME', 'TOTAL_PERCEIVED_TIME']]\n", + "taz_approach_db.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### create `path_found` variable" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "tap_path_found = tap_approach_db.copy()\n", + "tap_path_found = tap_path_found[[\"unique_ID\", \"TOTALIVTT\"]].rename(columns={\"TOTALIVTT\": \"tap_TOTALIVTT\"})\n", + "taz_path_found = taz_approach_db.copy()\n", + "taz_path_found = taz_path_found[[\"unique_ID\", \"TOTALIVTT\"]].rename(columns={\"TOTALIVTT\": \"taz_TOTALIVTT\"})" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDpath_found
01___AC Transit___2018TAZ_ONLY
110___AC Transit___2018BOTH
2100___AC Transit___2018BOTH
31000___AC Transit___2018BOTH
410000___AC Transit___2018BOTH
\n", + "
" + ], + "text/plain": [ + " unique_ID path_found\n", + "0 1___AC Transit___2018 TAZ_ONLY\n", + "1 10___AC Transit___2018 BOTH\n", + "2 100___AC Transit___2018 BOTH\n", + "3 1000___AC Transit___2018 BOTH\n", + "4 10000___AC Transit___2018 BOTH" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "path_found = pd.merge(taz_path_found, tap_path_found, how=\"left\", on=\"unique_ID\")\n", + "path_found[\"tap_TOTALIVTT\"] = path_found[\"tap_TOTALIVTT\"].fillna(0)\n", + "path_found.loc[(path_found[\"tap_TOTALIVTT\"] == 0) & (path_found[\"taz_TOTALIVTT\"] == 0), \"path_found\"] = \"NEITHER\"\n", + "path_found.loc[(path_found[\"tap_TOTALIVTT\"] == 0) & (path_found[\"taz_TOTALIVTT\"] > 0), \"path_found\"] = \"TAZ_ONLY\"\n", + "path_found.loc[(path_found[\"tap_TOTALIVTT\"] > 0) & (path_found[\"taz_TOTALIVTT\"] == 0), \"path_found\"] = \"TAP_ONLY\"\n", + "path_found.loc[(path_found[\"tap_TOTALIVTT\"] > 0) & (path_found[\"taz_TOTALIVTT\"] > 0), \"path_found\"] = \"BOTH\"\n", + "path_found = path_found[[\"unique_ID\", \"path_found\"]]\n", + "path_found.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Convert to long format\n", + "#### tap approach in long format" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_setskim_tabletap_value
011420___AC Transit___2018413852414639-122.29976737.904587-122.31976337.979455EA1access_timeNaN
111423___AC Transit___2018424701414651-122.32670237.921951-122.32178937.986542EA1access_time3.24
211425___AC Transit___2018418818424101-122.36267737.937884-122.32884337.990794EA1access_time5.52
311730___AC Transit___2018322305329001-122.11142037.698752-122.23093037.798295EA1access_time15.18
411732___AC Transit___2018310894329001-122.23028637.788432-122.23093037.798295EA1access_time3.12
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d maz_o_lon maz_o_lat \\\n", + "0 11420___AC Transit___2018 413852 414639 -122.299767 37.904587 \n", + "1 11423___AC Transit___2018 424701 414651 -122.326702 37.921951 \n", + "2 11425___AC Transit___2018 418818 424101 -122.362677 37.937884 \n", + "3 11730___AC Transit___2018 322305 329001 -122.111420 37.698752 \n", + "4 11732___AC Transit___2018 310894 329001 -122.230286 37.788432 \n", + "\n", + " maz_d_lon maz_d_lat period skim_set skim_table tap_value \n", + "0 -122.319763 37.979455 EA 1 access_time NaN \n", + "1 -122.321789 37.986542 EA 1 access_time 3.24 \n", + "2 -122.328843 37.990794 EA 1 access_time 5.52 \n", + "3 -122.230930 37.798295 EA 1 access_time 15.18 \n", + "4 -122.230930 37.798295 EA 1 access_time 3.12 " + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tap_approach_db_long = tap_approach_db.drop(columns=[\"tap_o\", \"tap_d\", \"renum_tap_o\", \"renum_tap_d\"])\n", + "tap_approach_db_long = pd.melt(tap_approach_db_long, \n", + " id_vars=[\"unique_ID\", \"maz_o\", \"maz_d\", \"maz_o_lon\", \"maz_o_lat\", \"maz_d_lon\", \"maz_d_lat\", \"period\", \"skim_set\"], \n", + " value_vars=[\"access_time\", \"egress_time\", \"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\", \"TOTAL_TIME\", \"TOTAL_PERCEIVED_TIME\"],\n", + " ignore_index=False)\n", + "tap_approach_db_long = tap_approach_db_long.rename(columns={\"variable\": \"skim_table\", \"value\": \"tap_value\"})\n", + "tap_approach_db_long.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### taz approach in long format" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_setskim_tabletaz_value
01___AC Transit___201811514425106-122.40979537.773544-122.34527937.934689PM3access_time7.719
110___AC Transit___2018316876324992-122.28314337.814792-122.19978737.766251AM1access_time6.181
2100___AC Transit___2018318567318470-122.17785637.714332-122.16525837.745239PM1access_time2.991
31000___AC Transit___2018327175325899-122.19799037.765282-122.16333137.737274AM1access_time2.293
410000___AC Transit___2018323825318288-122.18870237.793200-122.24760637.755097MD1access_time9.902
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d maz_o_lon maz_o_lat \\\n", + "0 1___AC Transit___2018 11514 425106 -122.409795 37.773544 \n", + "1 10___AC Transit___2018 316876 324992 -122.283143 37.814792 \n", + "2 100___AC Transit___2018 318567 318470 -122.177856 37.714332 \n", + "3 1000___AC Transit___2018 327175 325899 -122.197990 37.765282 \n", + "4 10000___AC Transit___2018 323825 318288 -122.188702 37.793200 \n", + "\n", + " maz_d_lon maz_d_lat period skim_set skim_table taz_value \n", + "0 -122.345279 37.934689 PM 3 access_time 7.719 \n", + "1 -122.199787 37.766251 AM 1 access_time 6.181 \n", + "2 -122.165258 37.745239 PM 1 access_time 2.991 \n", + "3 -122.163331 37.737274 AM 1 access_time 2.293 \n", + "4 -122.247606 37.755097 MD 1 access_time 9.902 " + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "taz_approach_db_long = taz_approach_db.drop(columns=[\"taz_o\", \"taz_d\"])\n", + "taz_approach_db_long = pd.melt(taz_approach_db_long, \n", + " id_vars=[\"unique_ID\", \"maz_o\", \"maz_d\", \"maz_o_lon\", \"maz_o_lat\", \"maz_d_lon\", \"maz_d_lat\", \"period\", \"skim_set\"], \n", + " value_vars=[\"access_time\", \"egress_time\", \"CAPPEN\", \"CRIVTT\", \"CROWD\", \"EAWT\", \"EBIVTT\", \"FARE\", \"FIRSTWAIT\", \"FRIVTT\", \"HRIVTT\", \"LBIVTT\", \"LINKREL\", \"LRIVTT\", \"TOTALIVTT\", \"TOTALWAIT\", \"TOTALWALK\", \"XFERS\", \"XFERWAIT\", \"XFERWALK\", \"TOTAL_TIME\", \"TOTAL_PERCEIVED_TIME\"],\n", + " ignore_index=False)\n", + "taz_approach_db_long = taz_approach_db_long.rename(columns={\"variable\": \"skim_table\", \"value\": \"taz_value\"})\n", + "taz_approach_db_long.head()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Combine results of both approaches into a single database" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDmaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_setskim_tabletaz_valuetap_value
01___AC Transit___201811514425106-122.40979537.773544-122.34527937.934689PM3access_time7.719NaN
110___AC Transit___2018316876324992-122.28314337.814792-122.19978737.766251AM1access_time6.18122.38
2100___AC Transit___2018318567318470-122.17785637.714332-122.16525837.745239PM1access_time2.9912.88
31000___AC Transit___2018327175325899-122.19799037.765282-122.16333137.737274AM1access_time2.2932.88
410000___AC Transit___2018323825318288-122.18870237.793200-122.24760637.755097MD1access_time9.9029.84
510001___AC Transit___2018312489330362-122.28671937.778156-122.07563737.609550MD1access_time5.376NaN
610002___AC Transit___2018316488314634-122.20465937.785926-122.16112537.791154MD1access_time7.0147.86
710003___AC Transit___2018314999312527-122.01234737.588927-121.89825537.511935MD3access_timeNaNNaN
810004___AC Transit___2018319567322475-122.21805037.789919-122.24140237.767258MD1access_time5.2104.14
910005___AC Transit___2018312905319173-122.10009737.632123-122.05952637.632255MD1access_time8.3786.48
\n", + "
" + ], + "text/plain": [ + " unique_ID maz_o maz_d maz_o_lon maz_o_lat \\\n", + "0 1___AC Transit___2018 11514 425106 -122.409795 37.773544 \n", + "1 10___AC Transit___2018 316876 324992 -122.283143 37.814792 \n", + "2 100___AC Transit___2018 318567 318470 -122.177856 37.714332 \n", + "3 1000___AC Transit___2018 327175 325899 -122.197990 37.765282 \n", + "4 10000___AC Transit___2018 323825 318288 -122.188702 37.793200 \n", + "5 10001___AC Transit___2018 312489 330362 -122.286719 37.778156 \n", + "6 10002___AC Transit___2018 316488 314634 -122.204659 37.785926 \n", + "7 10003___AC Transit___2018 314999 312527 -122.012347 37.588927 \n", + "8 10004___AC Transit___2018 319567 322475 -122.218050 37.789919 \n", + "9 10005___AC Transit___2018 312905 319173 -122.100097 37.632123 \n", + "\n", + " maz_d_lon maz_d_lat period skim_set skim_table taz_value tap_value \n", + "0 -122.345279 37.934689 PM 3 access_time 7.719 NaN \n", + "1 -122.199787 37.766251 AM 1 access_time 6.181 22.38 \n", + "2 -122.165258 37.745239 PM 1 access_time 2.991 2.88 \n", + "3 -122.163331 37.737274 AM 1 access_time 2.293 2.88 \n", + "4 -122.247606 37.755097 MD 1 access_time 9.902 9.84 \n", + "5 -122.075637 37.609550 MD 1 access_time 5.376 NaN \n", + "6 -122.161125 37.791154 MD 1 access_time 7.014 7.86 \n", + "7 -121.898255 37.511935 MD 3 access_time NaN NaN \n", + "8 -122.241402 37.767258 MD 1 access_time 5.210 4.14 \n", + "9 -122.059526 37.632255 MD 1 access_time 8.378 6.48 " + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "skim_comparison_db = pd.merge(taz_approach_db_long, tap_approach_db_long, how=\"outer\", on=[\"unique_ID\", \"maz_o\", \"maz_d\", \"maz_o_lon\", \"maz_o_lat\", \"maz_d_lon\", \"maz_d_lat\", \"period\", \"skim_set\", \"skim_table\"])\n", + "skim_comparison_db.head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDoperatorroutemaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_setskim_tabletap_valuetaz_value
01___AC Transit___2018AC TransitAC TRANSIT___72M Point Richmond to Oakland Amtrak11514425106-122.40979537.773544-122.34527937.934689PM3access_timeNaN7.719
110___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART316876324992-122.28314337.814792-122.19978737.766251AM1access_time22.386.181
2100___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART318567318470-122.17785637.714332-122.16525837.745239PM1access_time2.882.991
31000___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART327175325899-122.19799037.765282-122.16333137.737274AM1access_time2.882.293
410000___AC Transit___2018AC TransitAC TRANSIT___19 Downtown Oakland Fruitvale BART323825318288-122.18870237.793200-122.24760637.755097MD1access_time9.849.902
\n", + "
" + ], + "text/plain": [ + " unique_ID operator \\\n", + "0 1___AC Transit___2018 AC Transit \n", + "1 10___AC Transit___2018 AC Transit \n", + "2 100___AC Transit___2018 AC Transit \n", + "3 1000___AC Transit___2018 AC Transit \n", + "4 10000___AC Transit___2018 AC Transit \n", + "\n", + " route maz_o maz_d \\\n", + "0 AC TRANSIT___72M Point Richmond to Oakland Amtrak 11514 425106 \n", + "1 AC TRANSIT___1 Berkeley BART to Bay Fair BART 316876 324992 \n", + "2 AC TRANSIT___1 Berkeley BART to Bay Fair BART 318567 318470 \n", + "3 AC TRANSIT___1 Berkeley BART to Bay Fair BART 327175 325899 \n", + "4 AC TRANSIT___19 Downtown Oakland Fruitvale BART 323825 318288 \n", + "\n", + " maz_o_lon maz_o_lat maz_d_lon maz_d_lat period skim_set skim_table \\\n", + "0 -122.409795 37.773544 -122.345279 37.934689 PM 3 access_time \n", + "1 -122.283143 37.814792 -122.199787 37.766251 AM 1 access_time \n", + "2 -122.177856 37.714332 -122.165258 37.745239 PM 1 access_time \n", + "3 -122.197990 37.765282 -122.163331 37.737274 AM 1 access_time \n", + "4 -122.188702 37.793200 -122.247606 37.755097 MD 1 access_time \n", + "\n", + " tap_value taz_value \n", + "0 NaN 7.719 \n", + "1 22.38 6.181 \n", + "2 2.88 2.991 \n", + "3 2.88 2.293 \n", + "4 9.84 9.902 " + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "## add survey operator & route info\n", + "survey_info = pd.read_csv(f\"{data_path}/survey_operator_route.csv\", encoding = \"ISO-8859-1\")\n", + "skim_comparison_db = pd.merge(skim_comparison_db, survey_info, how=\"left\", on=\"unique_ID\")\n", + "skim_comparison_db = skim_comparison_db[[\"unique_ID\", \"operator\", \"route\", \"maz_o\", \"maz_d\", \"maz_o_lon\", \"maz_o_lat\", \"maz_d_lon\", \"maz_d_lat\", \"period\", \"skim_set\", \"skim_table\", \"tap_value\", \"taz_value\"]]\n", + "skim_comparison_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
unique_IDoperatorroutemaz_omaz_dmaz_o_lonmaz_o_latmaz_d_lonmaz_d_latperiodskim_setskim_tabletap_valuetaz_valuepath_found
01___AC Transit___2018AC TransitAC TRANSIT___72M Point Richmond to Oakland Amtrak11514425106-122.40979537.773544-122.34527937.934689PM3access_timeNaN7.719TAZ_ONLY
110___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART316876324992-122.28314337.814792-122.19978737.766251AM1access_time22.386.181BOTH
2100___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART318567318470-122.17785637.714332-122.16525837.745239PM1access_time2.882.991BOTH
31000___AC Transit___2018AC TransitAC TRANSIT___1 Berkeley BART to Bay Fair BART327175325899-122.19799037.765282-122.16333137.737274AM1access_time2.882.293BOTH
410000___AC Transit___2018AC TransitAC TRANSIT___19 Downtown Oakland Fruitvale BART323825318288-122.18870237.793200-122.24760637.755097MD1access_time9.849.902BOTH
\n", + "
" + ], + "text/plain": [ + " unique_ID operator \\\n", + "0 1___AC Transit___2018 AC Transit \n", + "1 10___AC Transit___2018 AC Transit \n", + "2 100___AC Transit___2018 AC Transit \n", + "3 1000___AC Transit___2018 AC Transit \n", + "4 10000___AC Transit___2018 AC Transit \n", + "\n", + " route maz_o maz_d \\\n", + "0 AC TRANSIT___72M Point Richmond to Oakland Amtrak 11514 425106 \n", + "1 AC TRANSIT___1 Berkeley BART to Bay Fair BART 316876 324992 \n", + "2 AC TRANSIT___1 Berkeley BART to Bay Fair BART 318567 318470 \n", + "3 AC TRANSIT___1 Berkeley BART to Bay Fair BART 327175 325899 \n", + "4 AC TRANSIT___19 Downtown Oakland Fruitvale BART 323825 318288 \n", + "\n", + " maz_o_lon maz_o_lat maz_d_lon maz_d_lat period skim_set skim_table \\\n", + "0 -122.409795 37.773544 -122.345279 37.934689 PM 3 access_time \n", + "1 -122.283143 37.814792 -122.199787 37.766251 AM 1 access_time \n", + "2 -122.177856 37.714332 -122.165258 37.745239 PM 1 access_time \n", + "3 -122.197990 37.765282 -122.163331 37.737274 AM 1 access_time \n", + "4 -122.188702 37.793200 -122.247606 37.755097 MD 1 access_time \n", + "\n", + " tap_value taz_value path_found \n", + "0 NaN 7.719 TAZ_ONLY \n", + "1 22.38 6.181 BOTH \n", + "2 2.88 2.991 BOTH \n", + "3 2.88 2.293 BOTH \n", + "4 9.84 9.902 BOTH " + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "## add path_found variable\n", + "skim_comparison_db = pd.merge(skim_comparison_db, path_found, how=\"left\", on=\"unique_ID\")\n", + "skim_comparison_db.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "skim_comparison_db.to_csv(\"../../outputs/skim/skim_comparison.csv\", index=False)" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "cf0ffc98cd3e6798b44bd672d9c6bf770a14d666c17f5c600d9c32eba9236d3d" + }, + "kernelspec": { + "display_name": "Python 3.9.5 64-bit ('serpm': conda)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}