Skip to content

Commit

Permalink
add taz-stop walk time estimation method
Browse files Browse the repository at this point in the history
  • Loading branch information
ychtw committed Nov 5, 2021
1 parent 0a38540 commit cae4d58
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions lasso/mtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,3 +3151,81 @@ def _calculate_impedance(x):

# optional return df: result_maz_trn_stops, shortest_paths_fail
return est_maz_walk_time


def estimate_transit_taz_connectors(
est_maz_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"
else:
dir_col_maz = "to_maz"
dir_col_taz = "to_taz"

# 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})
)

# calculate taz-scale transit demand
taz_demand = (
maz_demand.groupby(["skim_set", "time_period", dir_col_taz])["maz_demand"]
.agg("sum")
.reset_index(name="taz_demand")
)

# calculate share of maz transit demand in its corresponding taz
maz_demand = pd.merge(
maz_demand, taz_demand, how="left", on=["skim_set", "time_period", dir_col_taz]
)

maz_demand["maz_demand_weight"] = maz_demand["maz_demand"] / maz_demand["taz_demand"]

# add weight info to est_maz_walk_time df
est_maz_walk_time = pd.merge(
est_maz_walk_time,
maz_demand[["skim_set", "time_period", dir_col_maz, dir_col_taz, "maz_demand_weight"]],
how="left",
on=["skim_set", "time_period", dir_col_maz],
)

# drop records w/o weight info (means w/o maz transit demand)
est_maz_walk_time = est_maz_walk_time[~est_maz_walk_time["maz_demand_weight"].isnull()]
est_maz_walk_time[dir_col_taz] = est_maz_walk_time[dir_col_taz].astype(int)

# calculated weighted walk time
est_maz_walk_time["weighted_time"] = (
est_maz_walk_time[f"est_maz_walk_{direction}_min"] * est_maz_walk_time["maz_demand_weight"]
)

est_taz_walk_time = (
est_maz_walk_time.groupby(["skim_set", "time_period", dir_col_taz])["weighted_time"]
.agg("sum")
.reset_index(name=f"est_taz_walk_{direction}_min")
)
est_taz_walk_time[f"est_taz_walk_{direction}_min"] = est_taz_walk_time[
f"est_taz_walk_{direction}_min"
].round(3)

return est_taz_walk_time

0 comments on commit cae4d58

Please sign in to comment.