Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sccp lpp 2024a #1309

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rt_delay/rt_analysis/rt_filter_map_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def quick_map_corridor(self):
selector = select(_.geometry, _.total_speed_delay, _.total_schedule_delay)
else:
selector = select(_.geometry, _.total_speed_delay)
gdf = (self.corridor >> selector).iloc[:1,:]
gdf = (self.corridor >> selector).dissolve()
m = pd.concat([mappable_stops, gdf]).explore(tiles = "CartoDB positron")
return m

Expand Down Expand Up @@ -814,8 +814,9 @@ def corridor_metrics(self, sccp = False):
>> mutate(new_avg_trips_hr = ((_.n_trips + _.trips_added) / _.span_hours) / 2)
# create avg per direction by div 2
)
both_metrics_df['length_miles'] = (self.corridor.distance_meters / METERS_PER_MILE).iloc[0]
both_metrics_df['distance_meters'] = self.corridor.distance_meters
if 'distance_meters' in self.corridor.columns:
both_metrics_df['length_miles'] = (self.corridor.distance_meters / METERS_PER_MILE).iloc[0]
both_metrics_df['distance_meters'] = self.corridor.distance_meters
both_metrics_df['target_mph'] = self.transit_priority_target_mph
# both_metrics_df.length_miles = both_metrics_df.length_miles.fillna(value=gdf.length_miles.iloc[0])
gdf = gpd.GeoDataFrame(both_metrics_df, geometry=self.corridor.geometry, crs=self.corridor.crs)
Expand Down
7 changes: 3 additions & 4 deletions rt_delay/rt_analysis/sccp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ def sccp_average_metrics(itp_id: int, date_range: np.arange, corridor: gpd.GeoDa
schedule_metrics = []
speed_metrics = []
for date in date_range:
date = date.astype(dt.date)
try:
rt_day = rt_filter_map_plot.from_gcs(itp_id, date)
rt_day.add_corridor(corridor)
if filter_dict:
rt_day.set_filter(**filter_dict)
metrics = rt_day.corridor_metrics()
schedule_metrics += [metrics['schedule_metric_minutes']]
speed_metrics += [metrics['speed_metric_minutes']]
metrics = rt_day.corridor_metrics(sccp=True)
schedule_metrics += [metrics['schedule_delay_minutes'].sum()]
speed_metrics += [metrics['speed_delay_minutes'].sum()]
print(f'complete for date: {date}')
except Exception as e:
print(f'failed for date: {date}')
Expand Down
335 changes: 335 additions & 0 deletions sccp/0_sccp_refactor_scratchpad.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "d528f399-cf33-459e-b5dc-92e0b4ae389a",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import geopandas as gpd\n",
"from siuba import *\n",
"import shared_utils\n",
"\n",
"from calitp_data_analysis import get_fs\n",
"from segment_speed_utils import helpers, time_series_utils, gtfs_schedule_wrangling\n",
"from segment_speed_utils.project_vars import SCHED_GCS, SEGMENT_GCS, GTFS_DATA_DICT, analysis_date"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6cd318e5-5c4e-4249-b158-232f4d940770",
"metadata": {},
"outputs": [],
"source": [
"catalog = shared_utils.catalog_utils.get_catalog('gtfs_analytics_data')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6e86c1a8-d3de-4fc6-9478-c03133b6745c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'dir': '${gcs_paths.SEGMENT_GCS}', 'stage1': '${speeds_tables.vp_dwell}', 'stage2': 'nearest/nearest_vp_shape_segments', 'stage2b': 'nearest/nearest2_vp_shape_segments', 'stage3': 'stop_arrivals', 'stage4': 'speeds_stop_segments', 'trip_stop_cols': ['trip_instance_key', 'stop_sequence'], 'shape_stop_cols': ['shape_array_key', 'shape_id', 'stop_sequence'], 'stop_pair_cols': ['stop_pair', 'stop_pair_name'], 'route_dir_cols': ['route_id', 'direction_id'], 'shape_stop_single_segment': 'rollup_singleday/speeds_shape_stop_segments', 'route_dir_single_segment': 'rollup_singleday/speeds_route_dir_segments', 'route_dir_multi_segment': 'rollup_multiday/speeds_route_dir_segments', 'segments_file': 'segment_options/shape_stop_segments', 'max_speed': '${speed_vars.max_speed}'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"catalog.stop_segments"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f766b50a-c70d-4681-992c-d7f8979ada69",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2024-10-16'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"analysis_date"
]
},
{
"cell_type": "markdown",
"id": "a5dbe9fc-5997-4232-ae4b-980dd5dff349",
"metadata": {},
"source": [
"## wait, isn't 'rt_stop_times' what I need?\n",
"\n",
"* I basically need the same data Amanda's using for bunching, except I do also care about schedule"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "74a301dc-4455-430a-8209-79ed5d431026",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'dir': '${gcs_paths.SEGMENT_GCS}', 'stage1': '${speeds_tables.vp_dwell}', 'stage2': 'nearest/nearest_vp_rt_stop_times', 'stage2b': 'nearest/nearest2_vp_rt_stop_times', 'stage3': 'rt_stop_times/stop_arrivals', 'stage4': 'rt_stop_times/speeds', 'trip_stop_cols': ['trip_instance_key', 'stop_sequence'], 'shape_stop_cols': ['shape_array_key', 'shape_id', 'stop_sequence'], 'stop_pair_cols': ['stop_pair', 'stop_pair_name'], 'route_dir_cols': ['route_id', 'direction_id'], 'segments_file': 'segment_options/stop_segments', 'trip_speeds_single_summary': 'rollup_singleday/speeds_trip', 'route_dir_single_summary': 'rollup_singleday/speeds_route_dir', 'route_dir_multi_summary': 'rollup_multiday/speeds_route_dir', 'min_trip_minutes': '${speed_vars.time_min_cutoff}', 'max_trip_minutes': 180, 'max_speed': '${speed_vars.max_speed}', 'min_meters_elapsed': 1609}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"catalog.rt_stop_times"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4c8f882f-a60f-4007-9062-6c998088d808",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'dir': '${gcs_paths.RT_SCHED_GCS}', 'stop_times_direction': 'stop_times_direction', 'sched_trip_metrics': 'schedule_trip/schedule_trip_metrics', 'sched_route_direction_metrics': 'schedule_route_dir/schedule_route_direction_metrics', 'vp_trip_metrics': 'vp_trip/trip_metrics', 'vp_route_direction_metrics': 'vp_route_dir/route_direction_metrics', 'vp_operator_metrics': 'vp_operator/operator_metrics', 'sched_stop_metrics': 'schedule_stop/schedule_stop_metrics', 'schedule_rt_stop_times': 'schedule_rt_stop_times', 'early_trip_minutes': -5, 'late_trip_minutes': 5}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"catalog.rt_vs_schedule_tables"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "294b8f67-1486-48e9-8fe9-015b009d8e53",
"metadata": {},
"outputs": [],
"source": [
"path = f'{catalog.schedule_downloads.dir}{catalog.schedule_downloads.trips}_{analysis_date}.parquet'"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "508d38d4-086c-43e6-8044-6ded0882e105",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'gs://calitp-analytics-data/data-analyses/rt_delay/compiled_cached_views/trips_2024-10-16.parquet'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"path"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "dc3543ea-2544-4917-887e-9de4441fb460",
"metadata": {},
"outputs": [],
"source": [
"trips = pd.read_parquet(path)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7c8ec6df-fd29-4a16-a063-7e03af3dd9d7",
"metadata": {},
"outputs": [],
"source": [
"path = f'{catalog.rt_vs_schedule_tables.dir}{catalog.rt_vs_schedule_tables.schedule_rt_stop_times}_{analysis_date}.parquet'"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9d95c8be-a1d7-4b9f-814f-57f295d3d1df",
"metadata": {},
"outputs": [],
"source": [
"schedule_rt = pd.read_parquet(path)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "a5a84ce0-3ae4-41c7-a8fb-82caea7aa268",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>trip_id</th>\n",
" <th>stop_id</th>\n",
" <th>stop_sequence</th>\n",
" <th>scheduled_arrival_sec</th>\n",
" <th>schedule_gtfs_dataset_key</th>\n",
" <th>trip_instance_key</th>\n",
" <th>rt_arrival_sec</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>t_5912118_b_83127_tn_0</td>\n",
" <td>7728100</td>\n",
" <td>5</td>\n",
" <td>25426.0</td>\n",
" <td>09e16227fc42c4fe90204a9d11581034</td>\n",
" <td>893cb960f2ca78f823bd67adee30eaa3</td>\n",
" <td>25434</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>t_5912118_b_83127_tn_0</td>\n",
" <td>7728400</td>\n",
" <td>8</td>\n",
" <td>25559.0</td>\n",
" <td>09e16227fc42c4fe90204a9d11581034</td>\n",
" <td>893cb960f2ca78f823bd67adee30eaa3</td>\n",
" <td>25594</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>t_5912118_b_83127_tn_0</td>\n",
" <td>7728900</td>\n",
" <td>12</td>\n",
" <td>25768.0</td>\n",
" <td>09e16227fc42c4fe90204a9d11581034</td>\n",
" <td>893cb960f2ca78f823bd67adee30eaa3</td>\n",
" <td>25751</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" trip_id stop_id stop_sequence scheduled_arrival_sec \\\n",
"0 t_5912118_b_83127_tn_0 7728100 5 25426.0 \n",
"1 t_5912118_b_83127_tn_0 7728400 8 25559.0 \n",
"2 t_5912118_b_83127_tn_0 7728900 12 25768.0 \n",
"\n",
" schedule_gtfs_dataset_key trip_instance_key \\\n",
"0 09e16227fc42c4fe90204a9d11581034 893cb960f2ca78f823bd67adee30eaa3 \n",
"1 09e16227fc42c4fe90204a9d11581034 893cb960f2ca78f823bd67adee30eaa3 \n",
"2 09e16227fc42c4fe90204a9d11581034 893cb960f2ca78f823bd67adee30eaa3 \n",
"\n",
" rt_arrival_sec \n",
"0 25434 \n",
"1 25594 \n",
"2 25751 "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"schedule_rt >> head(3)"
]
},
{
"cell_type": "markdown",
"id": "158d8fe4-4640-4ae9-84aa-e4b8391f6bdf",
"metadata": {},
"source": [
"Good, but we don't have distance (and thus speed) available..."
]
},
{
"cell_type": "markdown",
"id": "0ef4a641-283b-4b68-bce7-8e3d9beb51c9",
"metadata": {},
"source": [
"get from cut segments?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ceba93c9-accd-4da7-b77c-6c0a7786cb01",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.13"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
8 changes: 8 additions & 0 deletions sccp/corridors_sccp_lpp/2024/BSVII_BoundingBox_SCVTA.geojson

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sccp/corridors_sccp_lpp/2024/beaumont_map.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"coordinates":[[[-116.99044694002112,33.926399060021296],[-116.99044694002112,33.92403782209635],[-116.98813434742624,33.92403782209635],[-116.98813434742624,33.926399060021296],[-116.99044694002112,33.926399060021296]]],"type":"Polygon"}}]}
Loading
Loading