Skip to content

Commit

Permalink
Merge pull request #946 from cal-itp/speeds-on-roads
Browse files Browse the repository at this point in the history
Clean up segment speeds methodology and refactor trip speeds and route speeds
  • Loading branch information
tiffanychu90 authored Nov 7, 2023
2 parents 9f3ec33 + 52e7914 commit 9fe222f
Show file tree
Hide file tree
Showing 40 changed files with 2,068 additions and 3,021 deletions.
35 changes: 28 additions & 7 deletions gtfs_funnel/stop_times_with_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import numpy as np
import pandas as pd

from typing import Literal

from calitp_data_analysis import utils
from shared_utils import rt_utils
from segment_speed_utils import helpers, wrangle_shapes
Expand Down Expand Up @@ -79,15 +81,31 @@ def find_prior_stop(
.groupby("trip_instance_key")
.stop_sequence
.shift(1)
),
subseq_stop_sequence = (
prior_stop
.sort_values(["trip_instance_key", "stop_sequence"])
.groupby("trip_instance_key")
.stop_sequence
.shift(-1)
)
)

prior_stop_geom = stop_times[
["trip_instance_key", "stop_sequence", "geometry"]
].rename(columns = {
"stop_sequence": "prior_stop_sequence",
"geometry": "prior_geometry"
}).set_geometry("prior_geometry").repartition(npartitions=1)
def renamed_geom_stop_times(
stop_times: dd.DataFrame,
suffix: Literal["prior", "subseq"]
) -> dd.DataFrame:

renamed_stop_geom = stop_times[
["trip_instance_key", "stop_sequence", "geometry"]
].rename(columns = {
"stop_sequence": f"{suffix}_stop_sequence",
"geometry": f"{suffix}_geometry"
}).set_geometry(f"{suffix}_geometry").repartition(npartitions=1)

return renamed_stop_geom

prior_stop_geom = renamed_geom_stop_times(stop_times, suffix="prior")

stop_times_with_prior = dd.merge(
stop_times,
Expand All @@ -101,7 +119,10 @@ def find_prior_stop(
prior_stop_geom,
on = ["trip_instance_key", "prior_stop_sequence"],
how = "left"
).astype({"prior_stop_sequence": "Int64"})
).astype({
"prior_stop_sequence": "Int64",
"subseq_stop_sequence": "Int64"
})

return stop_times_with_prior_geom

Expand Down
7 changes: 5 additions & 2 deletions gtfs_funnel/update_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from shared_utils import rt_dates

months = [
"mar", "apr", "may",
"jun", "jul", "aug",
"sep",
"oct"
]

analysis_date_list = [
rt_dates.DATES["oct2023a"],
rt_dates.DATES["oct2023b"]
#rt_dates.DATES["sep2023"],
rt_dates.DATES[f"{m}2023"] for m in months
]

CONFIG_PATH = Path("config.yml")
Expand Down
Loading

0 comments on commit 9fe222f

Please sign in to comment.