From ac4c40976f1aee89b907c2ef69fb6804dcfce796 Mon Sep 17 00:00:00 2001 From: Eric Dasmalchi Date: Mon, 4 Nov 2024 21:22:58 +0000 Subject: [PATCH] tweak functions, test --- _shared_utils/shared_utils/rt_utils.py | 2 +- ca_transit_speed_maps/01_new_speedmaps.ipynb | 1089 ++++------------ .../40_speedmap_scratchpad.ipynb | 1104 ++++++----------- rt_segment_speeds/logs/avg_speeds.log | 3 + .../scripts/average_segment_speeds.py | 6 + .../gtfs_schedule_wrangling.py | 21 + 6 files changed, 628 insertions(+), 1597 deletions(-) diff --git a/_shared_utils/shared_utils/rt_utils.py b/_shared_utils/shared_utils/rt_utils.py index a22374cc5..5b987b404 100644 --- a/_shared_utils/shared_utils/rt_utils.py +++ b/_shared_utils/shared_utils/rt_utils.py @@ -561,7 +561,7 @@ def categorize_time_of_day(value: Union[int, dt.datetime]) -> str: else: return "Evening" -def time_of_day_durations(): +def time_of_day_durations() -> pd.Series: """ Get duration in hours of each time of day classification. """ diff --git a/ca_transit_speed_maps/01_new_speedmaps.ipynb b/ca_transit_speed_maps/01_new_speedmaps.ipynb index d990d379e..dd18c87f5 100644 --- a/ca_transit_speed_maps/01_new_speedmaps.ipynb +++ b/ca_transit_speed_maps/01_new_speedmaps.ipynb @@ -21,7 +21,8 @@ "import geopandas as gpd\n", "from siuba import *\n", "\n", - "import shared_utils" + "import shared_utils\n", + "import segment_speed_utils" ] }, { @@ -36,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 36, "id": "9f15ed6a-5ab7-4f57-9695-3f762781b74c", "metadata": { "tags": [ @@ -46,12 +47,12 @@ "outputs": [], "source": [ "## parameters cell\n", - "itp_id = 167" + "itp_id = 182" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 37, "id": "a639fd84-29ca-4678-b568-2b1022701e14", "metadata": {}, "outputs": [], @@ -64,426 +65,7 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "1f9f9a1e-7435-45e3-8555-dc1d29a6af00", - "metadata": {}, - "outputs": [], - "source": [ - "speedmap_index = pd.read_parquet(f'_rt_progress_{analysis_date}.parquet') >> filter(_.caltrans_district == '04 - Oakland')" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "a2975449-8fc0-4970-95d8-3429e15b11af", - "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", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
organization_nameorganization_itp_idorganization_source_record_idcaltrans_district_is_currentanalysis_dateschedule_gtfs_dataset_keystatus
2City of Union City350recmB4uxrVLRXYF3L04 - OaklandTrue2024-10-16b82a23bef8a501e980c086ef269ffec7speedmap_segs_available
4Capitol Corridor Joint Powers Authority56recvEBkSBc7UxlarC04 - OaklandTrue2024-10-16f5a749dd65924e025b1293c58f95f8d6speedmap_segs_available
5Golden Gate Bridge, Highway and Transportation...127recoX7qMhlPrgfuz304 - OaklandTrue2024-10-16aea4108997c66a74fbdae27b34b69fdespeedmap_segs_available
6Sonoma-Marin Area Rail Transit District315recUmm4gcNXaqrwpn04 - OaklandTrue2024-10-160881af3822466784992a49f1cc57d38fspeedmap_segs_available
7Central Contra Costa Transit Authority61recjnaKVDEgulsko304 - OaklandTrue2024-10-16587e730fac4db21d54037e0f12b0dd5dspeedmap_segs_available
8University of California, Berkeley33recD9x7GHPrN46v6m04 - OaklandTrue2024-10-16a8d5f90bfd689badb7e1deb041408e96speedmap_segs_available
9Solano County Transit310reclLbvvKE1V4zsZg04 - OaklandTrue2024-10-161ebafaca8716652559b2017b6eedc4efspeedmap_segs_available
10Solano Transportation Authority381rec7ShjfgRPLU0yjY04 - OaklandTrue2024-10-161ebafaca8716652559b2017b6eedc4efspeedmap_segs_available
17San Mateo County Transit District290recw3mRsmKDTNnVlT04 - OaklandTrue2024-10-165456c80d420043e15c8eb7368a8a4d89speedmap_segs_available
22Peninsula Corridor Joint Powers Board246rec2ErIfztLMJ4rgG04 - OaklandTrue2024-10-169b4c9cf681dfcc10dffe9523b43598bfspeedmap_segs_available
27City of Santa Rosa301recsNvWvLQwGsoxlE04 - OaklandTrue2024-10-168fa3380c9291d3694494c34b014642d0speedmap_segs_available
32Western Contra Costa Transit Authority368recIKnsnTdKQ0vsiv04 - OaklandTrue2024-10-1678b44303c1714f6c6a4801637c2a5c9dspeedmap_segs_available
39Livermore-Amador Valley Transit Authority167recANs4M9yDhvDyob04 - OaklandFalse2024-10-16dcb6fb26f2d08393f9b0b1c14dc8775cspeedmap_segs_available
41City of Fairfield110recot6qBamlOoLcrM04 - OaklandTrue2024-10-160f5e1b251db53223200c5bfc365d33f2speedmap_segs_available
46Eastern Contra Costa Transit Authority336recEEJVeGrHGoTwgj04 - OaklandTrue2024-10-1655a01ef72af21906934ae8ffb4786e86speedmap_segs_available
50Cloverdale Transit70recRM3c9Zfaft4V2B04 - OaklandTrue2024-10-1609e16227fc42c4fe90204a9d11581034speedmap_segs_available
51Sonoma County314recDupUxInMUgxeiz04 - OaklandTrue2024-10-1609e16227fc42c4fe90204a9d11581034speedmap_segs_available
73Napa Valley Transportation Authority218rec9RGrya9SjWYp2p04 - OaklandTrue2024-10-161dc8ca4d6e9e915c60172b9ff57baefcspeedmap_segs_available
75Santa Clara Valley Transportation Authority294recC5CT95EufmQCXr04 - OaklandTrue2024-10-16fb467982dcc77a7f9199bebe709bb700speedmap_segs_available
85City of Petaluma247recUbGDXhPdx3494b04 - OaklandTrue2024-10-165ecac12d61709ec34b5f30a34fdbab64speedmap_segs_available
89City and County of San Francisco282rechaapWbeffO33OX04 - OaklandTrue2024-10-167cc0cb1871dfd558f11a2885c145d144speedmap_segs_available
96Alameda-Contra Costa Transit District4recOZgevYf7Jimm9L04 - OaklandTrue2024-10-16c499f905e33929a641f083dad55c521espeedmap_segs_available
106San Francisco Bay Area Water Emergency Transit...280recmatCuQAUrNcs8j04 - OaklandTrue2024-10-16de10a800dfec0f380e0abc7204c7dc91speedmap_segs_available
114Marin County Transit District194recNOb7pqBRlQVG5e04 - OaklandTrue2024-10-16015d67d5b75b5cf2b710bbadadfb75f5speedmap_segs_available
117Presidio Trust257recsBfXgev9ICDCY104 - OaklandFalse2024-10-164be4d02062a1a82dae5c039092ee8541speedmap_segs_available
\n", - "
" - ], - "text/plain": [ - " organization_name organization_itp_id \\\n", - "2 City of Union City 350 \n", - "4 Capitol Corridor Joint Powers Authority 56 \n", - "5 Golden Gate Bridge, Highway and Transportation... 127 \n", - "6 Sonoma-Marin Area Rail Transit District 315 \n", - "7 Central Contra Costa Transit Authority 61 \n", - "8 University of California, Berkeley 33 \n", - "9 Solano County Transit 310 \n", - "10 Solano Transportation Authority 381 \n", - "17 San Mateo County Transit District 290 \n", - "22 Peninsula Corridor Joint Powers Board 246 \n", - "27 City of Santa Rosa 301 \n", - "32 Western Contra Costa Transit Authority 368 \n", - "39 Livermore-Amador Valley Transit Authority 167 \n", - "41 City of Fairfield 110 \n", - "46 Eastern Contra Costa Transit Authority 336 \n", - "50 Cloverdale Transit 70 \n", - "51 Sonoma County 314 \n", - "73 Napa Valley Transportation Authority 218 \n", - "75 Santa Clara Valley Transportation Authority 294 \n", - "85 City of Petaluma 247 \n", - "89 City and County of San Francisco 282 \n", - "96 Alameda-Contra Costa Transit District 4 \n", - "106 San Francisco Bay Area Water Emergency Transit... 280 \n", - "114 Marin County Transit District 194 \n", - "117 Presidio Trust 257 \n", - "\n", - " organization_source_record_id caltrans_district _is_current \\\n", - "2 recmB4uxrVLRXYF3L 04 - Oakland True \n", - "4 recvEBkSBc7UxlarC 04 - Oakland True \n", - "5 recoX7qMhlPrgfuz3 04 - Oakland True \n", - "6 recUmm4gcNXaqrwpn 04 - Oakland True \n", - "7 recjnaKVDEgulsko3 04 - Oakland True \n", - "8 recD9x7GHPrN46v6m 04 - Oakland True \n", - "9 reclLbvvKE1V4zsZg 04 - Oakland True \n", - "10 rec7ShjfgRPLU0yjY 04 - Oakland True \n", - "17 recw3mRsmKDTNnVlT 04 - Oakland True \n", - "22 rec2ErIfztLMJ4rgG 04 - Oakland True \n", - "27 recsNvWvLQwGsoxlE 04 - Oakland True \n", - "32 recIKnsnTdKQ0vsiv 04 - Oakland True \n", - "39 recANs4M9yDhvDyob 04 - Oakland False \n", - "41 recot6qBamlOoLcrM 04 - Oakland True \n", - "46 recEEJVeGrHGoTwgj 04 - Oakland True \n", - "50 recRM3c9Zfaft4V2B 04 - Oakland True \n", - "51 recDupUxInMUgxeiz 04 - Oakland True \n", - "73 rec9RGrya9SjWYp2p 04 - Oakland True \n", - "75 recC5CT95EufmQCXr 04 - Oakland True \n", - "85 recUbGDXhPdx3494b 04 - Oakland True \n", - "89 rechaapWbeffO33OX 04 - Oakland True \n", - "96 recOZgevYf7Jimm9L 04 - Oakland True \n", - "106 recmatCuQAUrNcs8j 04 - Oakland True \n", - "114 recNOb7pqBRlQVG5e 04 - Oakland True \n", - "117 recsBfXgev9ICDCY1 04 - Oakland False \n", - "\n", - " analysis_date schedule_gtfs_dataset_key status \n", - "2 2024-10-16 b82a23bef8a501e980c086ef269ffec7 speedmap_segs_available \n", - "4 2024-10-16 f5a749dd65924e025b1293c58f95f8d6 speedmap_segs_available \n", - "5 2024-10-16 aea4108997c66a74fbdae27b34b69fde speedmap_segs_available \n", - "6 2024-10-16 0881af3822466784992a49f1cc57d38f speedmap_segs_available \n", - "7 2024-10-16 587e730fac4db21d54037e0f12b0dd5d speedmap_segs_available \n", - "8 2024-10-16 a8d5f90bfd689badb7e1deb041408e96 speedmap_segs_available \n", - "9 2024-10-16 1ebafaca8716652559b2017b6eedc4ef speedmap_segs_available \n", - "10 2024-10-16 1ebafaca8716652559b2017b6eedc4ef speedmap_segs_available \n", - "17 2024-10-16 5456c80d420043e15c8eb7368a8a4d89 speedmap_segs_available \n", - "22 2024-10-16 9b4c9cf681dfcc10dffe9523b43598bf speedmap_segs_available \n", - "27 2024-10-16 8fa3380c9291d3694494c34b014642d0 speedmap_segs_available \n", - "32 2024-10-16 78b44303c1714f6c6a4801637c2a5c9d speedmap_segs_available \n", - "39 2024-10-16 dcb6fb26f2d08393f9b0b1c14dc8775c speedmap_segs_available \n", - "41 2024-10-16 0f5e1b251db53223200c5bfc365d33f2 speedmap_segs_available \n", - "46 2024-10-16 55a01ef72af21906934ae8ffb4786e86 speedmap_segs_available \n", - "50 2024-10-16 09e16227fc42c4fe90204a9d11581034 speedmap_segs_available \n", - "51 2024-10-16 09e16227fc42c4fe90204a9d11581034 speedmap_segs_available \n", - "73 2024-10-16 1dc8ca4d6e9e915c60172b9ff57baefc speedmap_segs_available \n", - "75 2024-10-16 fb467982dcc77a7f9199bebe709bb700 speedmap_segs_available \n", - "85 2024-10-16 5ecac12d61709ec34b5f30a34fdbab64 speedmap_segs_available \n", - "89 2024-10-16 7cc0cb1871dfd558f11a2885c145d144 speedmap_segs_available \n", - "96 2024-10-16 c499f905e33929a641f083dad55c521e speedmap_segs_available \n", - "106 2024-10-16 de10a800dfec0f380e0abc7204c7dc91 speedmap_segs_available \n", - "114 2024-10-16 015d67d5b75b5cf2b710bbadadfb75f5 speedmap_segs_available \n", - "117 2024-10-16 4be4d02062a1a82dae5c039092ee8541 speedmap_segs_available " - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "speedmap_index" - ] - }, - { - "cell_type": "code", - "execution_count": 7, + "execution_count": 38, "id": "eea40f4b-c378-4b70-a80b-bbe79f8441bf", "metadata": { "tags": [] @@ -496,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 39, "id": "c54b78fd-de92-45d9-b54d-49c5b88945c7", "metadata": {}, "outputs": [ @@ -533,14 +115,14 @@ " \n", " \n", " \n", - " 39\n", - " Livermore-Amador Valley Transit Authority\n", - " 167\n", - " recANs4M9yDhvDyob\n", - " 04 - Oakland\n", - " False\n", + " 42\n", + " Los Angeles County Metropolitan Transportation...\n", + " 182\n", + " recPnGkwdpnr8jmHB\n", + " 07 - Los Angeles\n", + " True\n", " 2024-10-16\n", - " dcb6fb26f2d08393f9b0b1c14dc8775c\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", " speedmap_segs_available\n", " \n", " \n", @@ -548,17 +130,17 @@ "" ], "text/plain": [ - " organization_name organization_itp_id \\\n", - "39 Livermore-Amador Valley Transit Authority 167 \n", + " organization_name organization_itp_id \\\n", + "42 Los Angeles County Metropolitan Transportation... 182 \n", "\n", " organization_source_record_id caltrans_district _is_current analysis_date \\\n", - "39 recANs4M9yDhvDyob 04 - Oakland False 2024-10-16 \n", + "42 recPnGkwdpnr8jmHB 07 - Los Angeles True 2024-10-16 \n", "\n", " schedule_gtfs_dataset_key status \n", - "39 dcb6fb26f2d08393f9b0b1c14dc8775c speedmap_segs_available " + "42 0666caf3ec1ecc96b74f4477ee4bc939 speedmap_segs_available " ] }, - "execution_count": 8, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -569,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 40, "id": "1b9762c8-0235-4d8f-b7a4-20a3213eb45e", "metadata": {}, "outputs": [], @@ -579,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 41, "id": "9302c0ad-1201-4c5a-8267-ec52719cf777", "metadata": {}, "outputs": [], @@ -589,33 +171,17 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 42, "id": "19dbeff0-faf6-43e3-9edf-6e68dfeceeac", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['schedule_gtfs_dataset_key', 'shape_array_key', 'shape_id', 'route_id',\n", - " 'route_short_name', 'stop_pair', 'stop_pair_name', 'segment_id',\n", - " 'time_of_day', 'p50_mph', 'n_trips', 'p20_mph', 'p80_mph', 'name',\n", - " 'caltrans_district', 'organization_source_record_id',\n", - " 'organization_name', 'base64_url', 'geometry'],\n", - " dtype='object')" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "speedmap_segs.columns" + "# speedmap_segs.columns" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 43, "id": "9f3c4c93-a5f5-40d7-9315-63e4fecbd738", "metadata": {}, "outputs": [], @@ -625,8 +191,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "id": "33038798-16a0-46b5-a50e-2609c5729534", + "execution_count": 69, + "id": "e35e835e-9041-4735-917b-2517532e6166", "metadata": {}, "outputs": [ { @@ -660,7 +226,7 @@ " segment_id\n", " time_of_day\n", " p50_mph\n", - " n_trips\n", + " ...\n", " p20_mph\n", " p80_mph\n", " name\n", @@ -669,127 +235,138 @@ " organization_name\n", " base64_url\n", " geometry\n", + " n_trips_sch\n", + " trips_hr_sch\n", " \n", " \n", " \n", " \n", - " 599754\n", - " dcb6fb26f2d08393f9b0b1c14dc8775c\n", - " 71cf8d5071087c7a5ac5a4192f73a881\n", - " 44232\n", - " 603\n", - " 603\n", - " 881869__881870\n", - " Las Positas Blvd & Willow Rd__Las Positas Blvd...\n", - " 881869-881870-1\n", - " PM Peak\n", - " 22.71\n", - " 2\n", - " 13.62\n", - " 31.79\n", - " Bay Area 511 Tri-Valley Wheels Schedule\n", - " 04 - Oakland\n", - " recANs4M9yDhvDyob\n", - " Livermore-Amador Valley Transit Authority\n", - " aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...\n", - " LINESTRING (-121.89922 37.68350, -121.89953 37...\n", + " 9729\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 1d801329ec1c7b1da3460ede3c0fe8bc\n", + " 1200106_JUNE24\n", + " 120-13183\n", + " 120\n", + " 16644__14345\n", + " Whittwood Center__Santa Gertrudes / Starbuck\n", + " 16644-14345-1\n", + " AM Peak\n", + " 14.49\n", + " ...\n", + " 13.00\n", + " 16.38\n", + " LA Metro Bus Schedule\n", + " 07 - Los Angeles\n", + " recPnGkwdpnr8jmHB\n", + " Los Angeles County Metropolitan Transportation...\n", + " aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy...\n", + " LINESTRING (-117.99579 33.94440, -117.99579 33...\n", + " 4\n", + " 1.333333\n", " \n", " \n", - " 599755\n", - " dcb6fb26f2d08393f9b0b1c14dc8775c\n", - " 71cf8d5071087c7a5ac5a4192f73a881\n", - " 44232\n", - " 603\n", - " 603\n", - " 881870__882311\n", - " Las Positas Blvd & Hopyard Rd__Las Positas Blv...\n", - " 881870-882311-1\n", - " PM Peak\n", - " 9.12\n", - " 2\n", - " 7.97\n", - " 10.26\n", - " Bay Area 511 Tri-Valley Wheels Schedule\n", - " 04 - Oakland\n", - " recANs4M9yDhvDyob\n", - " Livermore-Amador Valley Transit Authority\n", - " aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...\n", - " LINESTRING (-121.90267 37.68194, -121.90291 37...\n", + " 9730\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 1d801329ec1c7b1da3460ede3c0fe8bc\n", + " 1200106_JUNE24\n", + " 120-13183\n", + " 120\n", + " 14345__14346\n", + " Santa Gertrudes / Starbuck__Santa Gertrudes / ...\n", + " 14345-14346-1\n", + " AM Peak\n", + " 26.67\n", + " ...\n", + " 22.58\n", + " 28.96\n", + " LA Metro Bus Schedule\n", + " 07 - Los Angeles\n", + " recPnGkwdpnr8jmHB\n", + " Los Angeles County Metropolitan Transportation...\n", + " aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy...\n", + " LINESTRING (-117.99307 33.93974, -117.99307 33...\n", + " 4\n", + " 1.333333\n", " \n", " \n", - " 599756\n", - " dcb6fb26f2d08393f9b0b1c14dc8775c\n", - " 71cf8d5071087c7a5ac5a4192f73a881\n", - " 44232\n", - " 603\n", - " 603\n", - " 882311__882707\n", - " Las Positas Blvd & Dorman Rd__Muirwood Dr & La...\n", - " 882311-882707-1\n", - " PM Peak\n", - " 18.23\n", + " 9731\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 1d801329ec1c7b1da3460ede3c0fe8bc\n", + " 1200106_JUNE24\n", + " 120-13183\n", + " 120\n", + " 14346__14344\n", + " Santa Gertrudes / Yermo__Santa Gertrudes / Lef...\n", + " 14346-14344-1\n", + " AM Peak\n", + " 11.10\n", + " ...\n", + " 7.31\n", + " 16.04\n", + " LA Metro Bus Schedule\n", + " 07 - Los Angeles\n", + " recPnGkwdpnr8jmHB\n", + " Los Angeles County Metropolitan Transportation...\n", + " aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy...\n", + " LINESTRING (-117.99308 33.93630, -117.99308 33...\n", " 4\n", - " 17.26\n", - " 19.30\n", - " Bay Area 511 Tri-Valley Wheels Schedule\n", - " 04 - Oakland\n", - " recANs4M9yDhvDyob\n", - " Livermore-Amador Valley Transit Authority\n", - " aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...\n", - " LINESTRING (-121.90600 37.68078, -121.90618 37...\n", + " 1.333333\n", " \n", " \n", "\n", + "

3 rows × 21 columns

\n", "" ], "text/plain": [ - " schedule_gtfs_dataset_key shape_array_key \\\n", - "599754 dcb6fb26f2d08393f9b0b1c14dc8775c 71cf8d5071087c7a5ac5a4192f73a881 \n", - "599755 dcb6fb26f2d08393f9b0b1c14dc8775c 71cf8d5071087c7a5ac5a4192f73a881 \n", - "599756 dcb6fb26f2d08393f9b0b1c14dc8775c 71cf8d5071087c7a5ac5a4192f73a881 \n", + " schedule_gtfs_dataset_key shape_array_key \\\n", + "9729 0666caf3ec1ecc96b74f4477ee4bc939 1d801329ec1c7b1da3460ede3c0fe8bc \n", + "9730 0666caf3ec1ecc96b74f4477ee4bc939 1d801329ec1c7b1da3460ede3c0fe8bc \n", + "9731 0666caf3ec1ecc96b74f4477ee4bc939 1d801329ec1c7b1da3460ede3c0fe8bc \n", "\n", - " shape_id route_id route_short_name stop_pair \\\n", - "599754 44232 603 603 881869__881870 \n", - "599755 44232 603 603 881870__882311 \n", - "599756 44232 603 603 882311__882707 \n", + " shape_id route_id route_short_name stop_pair \\\n", + "9729 1200106_JUNE24 120-13183 120 16644__14345 \n", + "9730 1200106_JUNE24 120-13183 120 14345__14346 \n", + "9731 1200106_JUNE24 120-13183 120 14346__14344 \n", "\n", - " stop_pair_name segment_id \\\n", - "599754 Las Positas Blvd & Willow Rd__Las Positas Blvd... 881869-881870-1 \n", - "599755 Las Positas Blvd & Hopyard Rd__Las Positas Blv... 881870-882311-1 \n", - "599756 Las Positas Blvd & Dorman Rd__Muirwood Dr & La... 882311-882707-1 \n", + " stop_pair_name segment_id \\\n", + "9729 Whittwood Center__Santa Gertrudes / Starbuck 16644-14345-1 \n", + "9730 Santa Gertrudes / Starbuck__Santa Gertrudes / ... 14345-14346-1 \n", + "9731 Santa Gertrudes / Yermo__Santa Gertrudes / Lef... 14346-14344-1 \n", "\n", - " time_of_day p50_mph n_trips p20_mph p80_mph \\\n", - "599754 PM Peak 22.71 2 13.62 31.79 \n", - "599755 PM Peak 9.12 2 7.97 10.26 \n", - "599756 PM Peak 18.23 4 17.26 19.30 \n", + " time_of_day p50_mph ... p20_mph p80_mph name \\\n", + "9729 AM Peak 14.49 ... 13.00 16.38 LA Metro Bus Schedule \n", + "9730 AM Peak 26.67 ... 22.58 28.96 LA Metro Bus Schedule \n", + "9731 AM Peak 11.10 ... 7.31 16.04 LA Metro Bus Schedule \n", "\n", - " name caltrans_district \\\n", - "599754 Bay Area 511 Tri-Valley Wheels Schedule 04 - Oakland \n", - "599755 Bay Area 511 Tri-Valley Wheels Schedule 04 - Oakland \n", - "599756 Bay Area 511 Tri-Valley Wheels Schedule 04 - Oakland \n", + " caltrans_district organization_source_record_id \\\n", + "9729 07 - Los Angeles recPnGkwdpnr8jmHB \n", + "9730 07 - Los Angeles recPnGkwdpnr8jmHB \n", + "9731 07 - Los Angeles recPnGkwdpnr8jmHB \n", "\n", - " organization_source_record_id \\\n", - "599754 recANs4M9yDhvDyob \n", - "599755 recANs4M9yDhvDyob \n", - "599756 recANs4M9yDhvDyob \n", + " organization_name \\\n", + "9729 Los Angeles County Metropolitan Transportation... \n", + "9730 Los Angeles County Metropolitan Transportation... \n", + "9731 Los Angeles County Metropolitan Transportation... \n", "\n", - " organization_name \\\n", - "599754 Livermore-Amador Valley Transit Authority \n", - "599755 Livermore-Amador Valley Transit Authority \n", - "599756 Livermore-Amador Valley Transit Authority \n", + " base64_url \\\n", + "9729 aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy... \n", + "9730 aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy... \n", + "9731 aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy... \n", "\n", - " base64_url \\\n", - "599754 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "599755 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "599756 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", + " geometry n_trips_sch \\\n", + "9729 LINESTRING (-117.99579 33.94440, -117.99579 33... 4 \n", + "9730 LINESTRING (-117.99307 33.93974, -117.99307 33... 4 \n", + "9731 LINESTRING (-117.99308 33.93630, -117.99308 33... 4 \n", "\n", - " geometry \n", - "599754 LINESTRING (-121.89922 37.68350, -121.89953 37... \n", - "599755 LINESTRING (-121.90267 37.68194, -121.90291 37... \n", - "599756 LINESTRING (-121.90600 37.68078, -121.90618 37... " + " trips_hr_sch \n", + "9729 1.333333 \n", + "9730 1.333333 \n", + "9731 1.333333 \n", + "\n", + "[3 rows x 21 columns]" ] }, - "execution_count": 13, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -800,29 +377,7 @@ }, { "cell_type": "code", - "execution_count": 14, - "id": "8e89173e-a0ea-4823-bbce-0aa6cdb3f075", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['PM Peak', 'AM Peak', 'Early AM', 'Midday', 'Evening'],\n", - " dtype=object)" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "speedmap_segs.time_of_day.unique()" - ] - }, - { - "cell_type": "code", - "execution_count": 15, + "execution_count": 45, "id": "f87584fb-f37d-4869-ba5d-af70a5a0e0e3", "metadata": {}, "outputs": [], @@ -832,151 +387,37 @@ }, { "cell_type": "code", - "execution_count": 16, - "id": "c0080473-a119-45b2-8ebc-9f9913b97ecd", - "metadata": {}, - "outputs": [], - "source": [ - "time_periods = [(x, shared_utils.rt_utils.categorize_time_of_day(x)) for x in range(25)]" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "7b72ddbb-4b1b-4169-bfcd-f64eb499ac85", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Midday 5\n", - "PM Peak 5\n", - "Evening 5\n", - "Owl 4\n", - "Early AM 3\n", - "AM Peak 3\n", - "dtype: int64" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pd.Series([shared_utils.rt_utils.categorize_time_of_day(x) for x in range(25)]).value_counts()" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "1df01b6f-c29e-4ccc-9b1f-03cda0241bd9", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[(0, 'Owl'),\n", - " (1, 'Owl'),\n", - " (2, 'Owl'),\n", - " (3, 'Owl'),\n", - " (4, 'Early AM'),\n", - " (5, 'Early AM'),\n", - " (6, 'Early AM'),\n", - " (7, 'AM Peak'),\n", - " (8, 'AM Peak'),\n", - " (9, 'AM Peak'),\n", - " (10, 'Midday'),\n", - " (11, 'Midday'),\n", - " (12, 'Midday'),\n", - " (13, 'Midday'),\n", - " (14, 'Midday'),\n", - " (15, 'PM Peak'),\n", - " (16, 'PM Peak'),\n", - " (17, 'PM Peak'),\n", - " (18, 'PM Peak'),\n", - " (19, 'PM Peak'),\n", - " (20, 'Evening'),\n", - " (21, 'Evening'),\n", - " (22, 'Evening'),\n", - " (23, 'Evening'),\n", - " (24, 'Evening')]" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "time_periods" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "590d0196-ab95-47e8-8ce0-e0b93b4da5d4", - "metadata": {}, - "outputs": [], - "source": [ - "am_peak_hrs = len([x[1] for x in time_periods if 'AM Peak' in x[1]])" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "c5c469eb-df45-4925-8888-2cc2bfc04cc6", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "am_peak_hrs" - ] - }, - { - "cell_type": "code", - "execution_count": 33, + "execution_count": 46, "id": "edc84eda-ce2b-481f-ac78-6b7209cb25f4", "metadata": {}, "outputs": [], "source": [ - "def prep_gdf(gdf, hrs):\n", + "def prep_gdf(gdf):\n", " \n", " gdf = gdf.to_crs(calitp_data_analysis.geography_utils.CA_NAD83Albers)\n", - " gdf['trips_per_hour'] = gdf.n_trips / hrs\n", "\n", " ## shift to right side of road to display direction\n", " gdf.geometry = gdf.geometry.apply(shared_utils.rt_utils.try_parallel)\n", - " gdf = gdf.apply(shared_utils.rt_utils.arrowize_by_frequency, axis=1)\n", + " gdf = gdf.apply(shared_utils.rt_utils.arrowize_by_frequency, axis=1, frequency_col='trips_hr_sch')\n", "\n", - " gdf = gdf >> arrange(_.trips_per_hour)\n", + " gdf = gdf >> arrange(_.trips_hr_sch)\n", "\n", " return gdf" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 47, "id": "6af2c7fd-b769-4fbf-bbcf-75080972cc67", "metadata": {}, "outputs": [], "source": [ - "peak_test = prep_gdf(peak_test, am_peak_hrs)" + "peak_test = prep_gdf(peak_test)" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 48, "id": "cedc030e-8d19-4a0b-b3a5-5a3d6c0dce23", "metadata": {}, "outputs": [], @@ -985,17 +426,9 @@ "url = shared_utils.rt_utils.ACCESS_SPEEDMAP_LEGEND_URL" ] }, - { - "cell_type": "markdown", - "id": "2e9ae65e-0ed4-4f00-ac8e-27ac85790804", - "metadata": {}, - "source": [ - "## adding identifiers for map display" - ] - }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 49, "id": "87c7db4f-3da9-4ba4-915b-88432a841b39", "metadata": {}, "outputs": [ @@ -1030,7 +463,7 @@ " segment_id\n", " time_of_day\n", " p50_mph\n", - " n_trips\n", + " ...\n", " p20_mph\n", " p80_mph\n", " name\n", @@ -1039,95 +472,105 @@ " organization_name\n", " base64_url\n", " geometry\n", - " trips_per_hour\n", + " n_trips_sch\n", + " trips_hr_sch\n", " \n", " \n", " \n", " \n", - " 526507\n", - " c499f905e33929a641f083dad55c521e\n", - " f59dce41f6c4e6cf0b9dbfc1a29095f1\n", - " shp-7-53\n", - " 7\n", - " 7\n", - " 53019__53372\n", - " San Pablo Av & Wall Av__San Pablo Av & Conlon Av\n", - " 53019-53372-1\n", + " 34253\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 4901c1a3b0efda4363bafac83036f8af\n", + " 1110423_JUNE24\n", + " 111-13183\n", + " 111\n", + " 12569__14726\n", + " Studebaker / Borson__Studebaker / Imperial\n", + " 12569-14726-1\n", " AM Peak\n", - " 5.80\n", + " 8.59\n", + " ...\n", + " 8.59\n", + " 8.59\n", + " LA Metro Bus Schedule\n", + " 07 - Los Angeles\n", + " recPnGkwdpnr8jmHB\n", + " Los Angeles County Metropolitan Transportation...\n", + " aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy...\n", + " POLYGON ((175823.879 -453844.437, 175808.618 -...\n", " 1\n", - " 5.80\n", - " 5.80\n", - " Bay Area 511 AC Transit Schedule\n", - " 04 - Oakland\n", - " recOZgevYf7Jimm9L\n", - " Alameda-Contra Costa Transit District\n", - " aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...\n", - " POLYGON ((-203712.125 -7192.575, -203734.516 -...\n", " 0.333333\n", " \n", " \n", - " 527527\n", - " c499f905e33929a641f083dad55c521e\n", - " 261a73dd824eab6a8fb3616a320d00e0\n", - " shp-62-01\n", - " 62\n", - " 62\n", - " 50553__57505\n", - " 23rd Av & Foothill Blvd (Garfield School)__23r...\n", - " 50553-57505-1\n", + " 34254\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 4901c1a3b0efda4363bafac83036f8af\n", + " 1110423_JUNE24\n", + " 111-13183\n", + " 111\n", + " 14726__14724\n", + " Studebaker / Imperial__Studebaker / Firestone\n", + " 14726-14724-1\n", " AM Peak\n", - " 13.48\n", + " 7.14\n", + " ...\n", + " 7.14\n", + " 7.14\n", + " LA Metro Bus Schedule\n", + " 07 - Los Angeles\n", + " recPnGkwdpnr8jmHB\n", + " Los Angeles County Metropolitan Transportation...\n", + " aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy...\n", + " POLYGON ((175820.029 -453597.893, 175804.674 -...\n", " 1\n", - " 13.48\n", - " 13.48\n", - " Bay Area 511 AC Transit Schedule\n", - " 04 - Oakland\n", - " recOZgevYf7Jimm9L\n", - " Alameda-Contra Costa Transit District\n", - " aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...\n", - " POLYGON ((-196613.695 -23524.639, -196614.785 ...\n", " 0.333333\n", " \n", " \n", "\n", + "

2 rows × 21 columns

\n", "" ], "text/plain": [ - " schedule_gtfs_dataset_key shape_array_key \\\n", - "526507 c499f905e33929a641f083dad55c521e f59dce41f6c4e6cf0b9dbfc1a29095f1 \n", - "527527 c499f905e33929a641f083dad55c521e 261a73dd824eab6a8fb3616a320d00e0 \n", + " schedule_gtfs_dataset_key shape_array_key \\\n", + "34253 0666caf3ec1ecc96b74f4477ee4bc939 4901c1a3b0efda4363bafac83036f8af \n", + "34254 0666caf3ec1ecc96b74f4477ee4bc939 4901c1a3b0efda4363bafac83036f8af \n", + "\n", + " shape_id route_id route_short_name stop_pair \\\n", + "34253 1110423_JUNE24 111-13183 111 12569__14726 \n", + "34254 1110423_JUNE24 111-13183 111 14726__14724 \n", + "\n", + " stop_pair_name segment_id \\\n", + "34253 Studebaker / Borson__Studebaker / Imperial 12569-14726-1 \n", + "34254 Studebaker / Imperial__Studebaker / Firestone 14726-14724-1 \n", "\n", - " shape_id route_id route_short_name stop_pair \\\n", - "526507 shp-7-53 7 7 53019__53372 \n", - "527527 shp-62-01 62 62 50553__57505 \n", + " time_of_day p50_mph ... p20_mph p80_mph name \\\n", + "34253 AM Peak 8.59 ... 8.59 8.59 LA Metro Bus Schedule \n", + "34254 AM Peak 7.14 ... 7.14 7.14 LA Metro Bus Schedule \n", "\n", - " stop_pair_name segment_id \\\n", - "526507 San Pablo Av & Wall Av__San Pablo Av & Conlon Av 53019-53372-1 \n", - "527527 23rd Av & Foothill Blvd (Garfield School)__23r... 50553-57505-1 \n", + " caltrans_district organization_source_record_id \\\n", + "34253 07 - Los Angeles recPnGkwdpnr8jmHB \n", + "34254 07 - Los Angeles recPnGkwdpnr8jmHB \n", "\n", - " time_of_day p50_mph n_trips p20_mph p80_mph \\\n", - "526507 AM Peak 5.80 1 5.80 5.80 \n", - "527527 AM Peak 13.48 1 13.48 13.48 \n", + " organization_name \\\n", + "34253 Los Angeles County Metropolitan Transportation... \n", + "34254 Los Angeles County Metropolitan Transportation... \n", "\n", - " name caltrans_district \\\n", - "526507 Bay Area 511 AC Transit Schedule 04 - Oakland \n", - "527527 Bay Area 511 AC Transit Schedule 04 - Oakland \n", + " base64_url \\\n", + "34253 aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy... \n", + "34254 aHR0cHM6Ly9naXRsYWIuY29tL0xBQ01UQS9ndGZzX2J1cy... \n", "\n", - " organization_source_record_id organization_name \\\n", - "526507 recOZgevYf7Jimm9L Alameda-Contra Costa Transit District \n", - "527527 recOZgevYf7Jimm9L Alameda-Contra Costa Transit District \n", + " geometry n_trips_sch \\\n", + "34253 POLYGON ((175823.879 -453844.437, 175808.618 -... 1 \n", + "34254 POLYGON ((175820.029 -453597.893, 175804.674 -... 1 \n", "\n", - " base64_url \\\n", - "526507 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "527527 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", + " trips_hr_sch \n", + "34253 0.333333 \n", + "34254 0.333333 \n", "\n", - " geometry trips_per_hour \n", - "526507 POLYGON ((-203712.125 -7192.575, -203734.516 -... 0.333333 \n", - "527527 POLYGON ((-196613.695 -23524.639, -196614.785 ... 0.333333 " + "[2 rows x 21 columns]" ] }, - "execution_count": 36, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -1136,21 +579,9 @@ "peak_test >> head(2)" ] }, - { - "cell_type": "markdown", - "id": "21725c98-e8cf-47bb-a880-09e67d25f0fe", - "metadata": {}, - "source": [ - "## to-do\n", - "\n", - "* where does new n_trips come from? should be schedule-based for speedmaps applications...\n", - "* split am/pm peak\n", - "* https://github.com/cal-itp/data-analyses/issues/1218 upstream add route identifiers" - ] - }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 50, "id": "e7c32718-4eb2-4c2b-aba0-cca397aaabf3", "metadata": {}, "outputs": [ @@ -1161,11 +592,12 @@ " 'route_short_name', 'stop_pair', 'stop_pair_name', 'segment_id',\n", " 'time_of_day', 'p50_mph', 'n_trips', 'p20_mph', 'p80_mph', 'name',\n", " 'caltrans_district', 'organization_source_record_id',\n", - " 'organization_name', 'base64_url', 'geometry', 'trips_per_hour'],\n", + " 'organization_name', 'base64_url', 'geometry', 'n_trips_sch',\n", + " 'trips_hr_sch'],\n", " dtype='object')" ] }, - "execution_count": 37, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1184,7 +616,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 58, "id": "10a3ff1d-04f8-40b8-ab91-5ef96fde9b6a", "metadata": {}, "outputs": [ @@ -1192,7 +624,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "writing to calitp-map-tiles/testing/4_new.geojson.gz\n" + "writing to calitp-map-tiles/testing/182_new.geojson.gz\n" ] } ], @@ -1200,12 +632,12 @@ "speedmap_state = shared_utils.rt_utils.set_state_export(\n", " peak_test, filename=f'{itp_id}_new', map_type='speedmap',\n", " color_col='p20_mph', cmap=cmap, legend_url=url,\n", - " cache_seconds=0, map_title=f'Speedmap Segs {analysis_date}')" + " cache_seconds=0, map_title=f'Speedmap Segs {time_of_day} {analysis_date}')" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 59, "id": "75f2695e-4b80-4d91-8dce-1fa8e347729b", "metadata": {}, "outputs": [ @@ -1213,19 +645,19 @@ "data": { "text/plain": [ "{'state_dict': {'name': 'null',\n", - " 'layers': [{'name': 'Speedmap Segs 2024-10-16',\n", - " 'url': 'https://storage.googleapis.com/calitp-map-tiles/testing/4_new.geojson.gz',\n", + " 'layers': [{'name': 'Speedmap Segs Early AM 2024-10-16',\n", + " 'url': 'https://storage.googleapis.com/calitp-map-tiles/testing/182_new.geojson.gz',\n", " 'properties': {'stroked': False,\n", " 'highlight_saturation_multiplier': 0.5,\n", " 'tooltip_speed_key': 'p20_mph'},\n", " 'type': 'speedmap'}],\n", - " 'lat_lon': (37.777276879932664, -122.20458759054884),\n", + " 'lat_lon': (34.05429096594501, -118.29944262320139),\n", " 'zoom': 13,\n", - " 'legend_url': 'https://storage.googleapis.com/calitp-map-tiles/speeds_legend.svg'},\n", - " 'spa_link': 'https://embeddable-maps.calitp.org/?state=eyJuYW1lIjogIm51bGwiLCAibGF5ZXJzIjogW3sibmFtZSI6ICJTcGVlZG1hcCBTZWdzIDIwMjQtMTAtMTYiLCAidXJsIjogImh0dHBzOi8vc3RvcmFnZS5nb29nbGVhcGlzLmNvbS9jYWxpdHAtbWFwLXRpbGVzL3Rlc3RpbmcvNF9uZXcuZ2VvanNvbi5neiIsICJwcm9wZXJ0aWVzIjogeyJzdHJva2VkIjogZmFsc2UsICJoaWdobGlnaHRfc2F0dXJhdGlvbl9tdWx0aXBsaWVyIjogMC41LCAidG9vbHRpcF9zcGVlZF9rZXkiOiAicDIwX21waCJ9LCAidHlwZSI6ICJzcGVlZG1hcCJ9XSwgImxhdF9sb24iOiBbMzcuNzc3Mjc2ODc5OTMyNjY0LCAtMTIyLjIwNDU4NzU5MDU0ODg0XSwgInpvb20iOiAxMywgImxlZ2VuZF91cmwiOiAiaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL2NhbGl0cC1tYXAtdGlsZXMvc3BlZWRzX2xlZ2VuZC5zdmcifQ=='}" + " 'legend_url': 'https://storage.googleapis.com/calitp-map-tiles/speeds_legend_color_access.svg'},\n", + " 'spa_link': 'https://embeddable-maps.calitp.org/?state=eyJuYW1lIjogIm51bGwiLCAibGF5ZXJzIjogW3sibmFtZSI6ICJTcGVlZG1hcCBTZWdzIEVhcmx5IEFNIDIwMjQtMTAtMTYiLCAidXJsIjogImh0dHBzOi8vc3RvcmFnZS5nb29nbGVhcGlzLmNvbS9jYWxpdHAtbWFwLXRpbGVzL3Rlc3RpbmcvMTgyX25ldy5nZW9qc29uLmd6IiwgInByb3BlcnRpZXMiOiB7InN0cm9rZWQiOiBmYWxzZSwgImhpZ2hsaWdodF9zYXR1cmF0aW9uX211bHRpcGxpZXIiOiAwLjUsICJ0b29sdGlwX3NwZWVkX2tleSI6ICJwMjBfbXBoIn0sICJ0eXBlIjogInNwZWVkbWFwIn1dLCAibGF0X2xvbiI6IFszNC4wNTQyOTA5NjU5NDUwMSwgLTExOC4yOTk0NDI2MjMyMDEzOV0sICJ6b29tIjogMTMsICJsZWdlbmRfdXJsIjogImh0dHBzOi8vc3RvcmFnZS5nb29nbGVhcGlzLmNvbS9jYWxpdHAtbWFwLXRpbGVzL3NwZWVkc19sZWdlbmRfY29sb3JfYWNjZXNzLnN2ZyJ9'}" ] }, - "execution_count": 39, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1244,17 +676,17 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 60, "id": "02ffc2b6-9b8f-456b-ae33-85e7eea79df5", "metadata": {}, "outputs": [], "source": [ - "time_of_day = 'Early AM'" + "time_of_day = 'PM Peak'" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 61, "id": "2f44c03e-c7cc-4e49-8da4-be653d4c3546", "metadata": {}, "outputs": [], @@ -1264,48 +696,17 @@ }, { "cell_type": "code", - "execution_count": 97, - "id": "2cbffab5-c927-4a0f-a28f-eb07cf12800f", - "metadata": {}, - "outputs": [], - "source": [ - "hrs = len([x[1] for x in time_periods if x[1] == time_of_day])" - ] - }, - { - "cell_type": "code", - "execution_count": 98, - "id": "7c0bb82e-3173-4a4f-a6e4-4bfa66a79044", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 98, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "hrs" - ] - }, - { - "cell_type": "code", - "execution_count": 99, + "execution_count": 62, "id": "53a9f9cc-38d8-44d3-b7a6-a33fca62d32b", "metadata": {}, "outputs": [], "source": [ - "period_test = prep_gdf(period_speeds, hrs)" + "period_test = prep_gdf(period_speeds)" ] }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 63, "id": "d483e182-b36c-487e-a194-7a9e48d5b32f", "metadata": {}, "outputs": [], @@ -1315,7 +716,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 65, "id": "51e108ee-19f5-4266-8848-fb5ac57f5108", "metadata": {}, "outputs": [ @@ -1323,7 +724,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "writing to calitp-map-tiles/testing/4_early_am_new.geojson.gz\n" + "writing to calitp-map-tiles/testing/182_pm_peak_new.geojson.gz\n" ] } ], @@ -1336,7 +737,7 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 66, "id": "360aee2f-9076-4c7d-9843-0f7959489f5c", "metadata": {}, "outputs": [ @@ -1344,19 +745,19 @@ "data": { "text/plain": [ "{'state_dict': {'name': 'null',\n", - " 'layers': [{'name': 'Speedmap Segs Early AM 2024-10-16',\n", - " 'url': 'https://storage.googleapis.com/calitp-map-tiles/testing/4_early_am_new.geojson.gz',\n", + " 'layers': [{'name': 'Speedmap Segs PM Peak 2024-10-16',\n", + " 'url': 'https://storage.googleapis.com/calitp-map-tiles/testing/182_pm_peak_new.geojson.gz',\n", " 'properties': {'stroked': False,\n", " 'highlight_saturation_multiplier': 0.5,\n", " 'tooltip_speed_key': 'p20_mph'},\n", " 'type': 'speedmap'}],\n", - " 'lat_lon': (37.77940573965417, -122.21209975403526),\n", + " 'lat_lon': (34.04804074656423, -118.29635317134563),\n", " 'zoom': 13,\n", " 'legend_url': 'https://storage.googleapis.com/calitp-map-tiles/speeds_legend_color_access.svg'},\n", - " 'spa_link': 'https://embeddable-maps.calitp.org/?state=eyJuYW1lIjogIm51bGwiLCAibGF5ZXJzIjogW3sibmFtZSI6ICJTcGVlZG1hcCBTZWdzIEVhcmx5IEFNIDIwMjQtMTAtMTYiLCAidXJsIjogImh0dHBzOi8vc3RvcmFnZS5nb29nbGVhcGlzLmNvbS9jYWxpdHAtbWFwLXRpbGVzL3Rlc3RpbmcvNF9lYXJseV9hbV9uZXcuZ2VvanNvbi5neiIsICJwcm9wZXJ0aWVzIjogeyJzdHJva2VkIjogZmFsc2UsICJoaWdobGlnaHRfc2F0dXJhdGlvbl9tdWx0aXBsaWVyIjogMC41LCAidG9vbHRpcF9zcGVlZF9rZXkiOiAicDIwX21waCJ9LCAidHlwZSI6ICJzcGVlZG1hcCJ9XSwgImxhdF9sb24iOiBbMzcuNzc5NDA1NzM5NjU0MTcsIC0xMjIuMjEyMDk5NzU0MDM1MjZdLCAiem9vbSI6IDEzLCAibGVnZW5kX3VybCI6ICJodHRwczovL3N0b3JhZ2UuZ29vZ2xlYXBpcy5jb20vY2FsaXRwLW1hcC10aWxlcy9zcGVlZHNfbGVnZW5kX2NvbG9yX2FjY2Vzcy5zdmcifQ=='}" + " 'spa_link': 'https://embeddable-maps.calitp.org/?state=eyJuYW1lIjogIm51bGwiLCAibGF5ZXJzIjogW3sibmFtZSI6ICJTcGVlZG1hcCBTZWdzIFBNIFBlYWsgMjAyNC0xMC0xNiIsICJ1cmwiOiAiaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL2NhbGl0cC1tYXAtdGlsZXMvdGVzdGluZy8xODJfcG1fcGVha19uZXcuZ2VvanNvbi5neiIsICJwcm9wZXJ0aWVzIjogeyJzdHJva2VkIjogZmFsc2UsICJoaWdobGlnaHRfc2F0dXJhdGlvbl9tdWx0aXBsaWVyIjogMC41LCAidG9vbHRpcF9zcGVlZF9rZXkiOiAicDIwX21waCJ9LCAidHlwZSI6ICJzcGVlZG1hcCJ9XSwgImxhdF9sb24iOiBbMzQuMDQ4MDQwNzQ2NTY0MjMsIC0xMTguMjk2MzUzMTcxMzQ1NjNdLCAiem9vbSI6IDEzLCAibGVnZW5kX3VybCI6ICJodHRwczovL3N0b3JhZ2UuZ29vZ2xlYXBpcy5jb20vY2FsaXRwLW1hcC10aWxlcy9zcGVlZHNfbGVnZW5kX2NvbG9yX2FjY2Vzcy5zdmcifQ=='}" ] }, - "execution_count": 102, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } diff --git a/rt_segment_speeds/40_speedmap_scratchpad.ipynb b/rt_segment_speeds/40_speedmap_scratchpad.ipynb index 29757e05d..2ceb1a11b 100644 --- a/rt_segment_speeds/40_speedmap_scratchpad.ipynb +++ b/rt_segment_speeds/40_speedmap_scratchpad.ipynb @@ -305,493 +305,7 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "f8201973-a5cf-4349-88c2-bfb171cc3484", - "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", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
schedule_gtfs_dataset_keyshape_array_keyshape_idroute_idroute_short_namestop_pairstop_pair_namesegment_idtime_of_dayp50_mphn_tripsp20_mphp80_mphnamecaltrans_districtorganization_source_record_idorganization_namebase64_urlgeometry
00139b1253130b33adcd4b3a4490530d251530f7b5ba4cdde7c644c14f262005cb0c096a2-4c32-4675-b005-43b58b3781e6874b0dfa-ab3d-47da-ac75-5fd7b9bdea42C30 WB0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352...Woodlake Park EB__Cypress St & Naranjo Blvd WB0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-...AM Peak17.27415.2020.96TCRTA TripShot Schedule06 - Fresnorec4YWVqVwJ9XqDbqTulare County Regional Transit AgencyaHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy...LINESTRING (-119.09762 36.41481, -119.09762 36...
10139b1253130b33adcd4b3a4490530d251530f7b5ba4cdde7c644c14f262005cb0c096a2-4c32-4675-b005-43b58b3781e6874b0dfa-ab3d-47da-ac75-5fd7b9bdea42C30 WB0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352...Woodlake Park EB__Cypress St & Naranjo Blvd WB0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-...Midday20.38618.4623.02TCRTA TripShot Schedule06 - Fresnorec4YWVqVwJ9XqDbqTulare County Regional Transit AgencyaHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy...LINESTRING (-119.09762 36.41481, -119.09762 36...
20139b1253130b33adcd4b3a4490530d251530f7b5ba4cdde7c644c14f262005cb0c096a2-4c32-4675-b005-43b58b3781e6874b0dfa-ab3d-47da-ac75-5fd7b9bdea42C30 WB0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352...Woodlake Park EB__Cypress St & Naranjo Blvd WB0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-...PM Peak23.90522.4925.11TCRTA TripShot Schedule06 - Fresnorec4YWVqVwJ9XqDbqTulare County Regional Transit AgencyaHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy...LINESTRING (-119.09762 36.41481, -119.09762 36...
30139b1253130b33adcd4b3a4490530d251530f7b5ba4cdde7c644c14f262005cb0c096a2-4c32-4675-b005-43b58b3781e6874b0dfa-ab3d-47da-ac75-5fd7b9bdea42C30 WB5b9a7352-556f-4272-b663-22f9821d6a40__5f894da7...Cypress St & Naranjo Blvd WB__Millwood and Roa...5b9a7352-556f-4272-b663-22f9821d6a40-5f894da7-...AM Peak49.50843.8551.81TCRTA TripShot Schedule06 - Fresnorec4YWVqVwJ9XqDbqTulare County Regional Transit AgencyaHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy...LINESTRING (-119.10550 36.41377, -119.10562 36...
40139b1253130b33adcd4b3a4490530d251530f7b5ba4cdde7c644c14f262005cb0c096a2-4c32-4675-b005-43b58b3781e6874b0dfa-ab3d-47da-ac75-5fd7b9bdea42C30 WB5b9a7352-556f-4272-b663-22f9821d6a40__5f894da7...Cypress St & Naranjo Blvd WB__Millwood and Roa...5b9a7352-556f-4272-b663-22f9821d6a40-5f894da7-...Midday47.581244.7449.68TCRTA TripShot Schedule06 - Fresnorec4YWVqVwJ9XqDbqTulare County Regional Transit AgencyaHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy...LINESTRING (-119.10550 36.41377, -119.10562 36...
............................................................
693202fb467982dcc77a7f9199bebe709bb7008d34a33f017ea0d1498b0cebf26fc5f9114150212161591__61592California & Showers__California & Ortega61591-61592-1Evening24.71124.7124.71Bay Area 511 Santa Clara Transit Schedule04 - OaklandrecC5CT95EufmQCXrSanta Clara Valley Transportation AuthorityaHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...LINESTRING (-122.10605 37.40280, -122.10581 37...
693203fb467982dcc77a7f9199bebe709bb7008d34a33f017ea0d1498b0cebf26fc5f9114150212161592__61593California & Ortega__California & Rengstorff61592-61593-1Evening24.68124.6824.68Bay Area 511 Santa Clara Transit Schedule04 - OaklandrecC5CT95EufmQCXrSanta Clara Valley Transportation AuthorityaHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...LINESTRING (-122.10339 37.40108, -122.10266 37...
693204fb467982dcc77a7f9199bebe709bb7008d34a33f017ea0d1498b0cebf26fc5f9114150212161593__61422California & Rengstorff__California & Escuela61593-61422-1Evening24.44124.4424.44Bay Area 511 Santa Clara Transit Schedule04 - OaklandrecC5CT95EufmQCXrSanta Clara Valley Transportation AuthorityaHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...LINESTRING (-122.09992 37.39895, -122.09902 37...
693205fb467982dcc77a7f9199bebe709bb7008d34a33f017ea0d1498b0cebf26fc5f9114150212161422__61423California & Escuela__California & Mariposa61422-61423-1Evening15.27115.2715.27Bay Area 511 Santa Clara Transit Schedule04 - OaklandrecC5CT95EufmQCXrSanta Clara Valley Transportation AuthorityaHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...LINESTRING (-122.09415 37.39670, -122.09225 37...
693206fb467982dcc77a7f9199bebe709bb7008d34a33f017ea0d1498b0cebf26fc5f9114150212161423__61424California & Mariposa__California & Palo Alto61423-61424-1Evening14.83114.8314.83Bay Area 511 Santa Clara Transit Schedule04 - OaklandrecC5CT95EufmQCXrSanta Clara Valley Transportation AuthorityaHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW...LINESTRING (-122.08948 37.39486, -122.08939 37...
\n", - "

693207 rows × 19 columns

\n", - "
" - ], - "text/plain": [ - " schedule_gtfs_dataset_key shape_array_key \\\n", - "0 0139b1253130b33adcd4b3a4490530d2 51530f7b5ba4cdde7c644c14f262005c \n", - "1 0139b1253130b33adcd4b3a4490530d2 51530f7b5ba4cdde7c644c14f262005c \n", - "2 0139b1253130b33adcd4b3a4490530d2 51530f7b5ba4cdde7c644c14f262005c \n", - "3 0139b1253130b33adcd4b3a4490530d2 51530f7b5ba4cdde7c644c14f262005c \n", - "4 0139b1253130b33adcd4b3a4490530d2 51530f7b5ba4cdde7c644c14f262005c \n", - "... ... ... \n", - "693202 fb467982dcc77a7f9199bebe709bb700 8d34a33f017ea0d1498b0cebf26fc5f9 \n", - "693203 fb467982dcc77a7f9199bebe709bb700 8d34a33f017ea0d1498b0cebf26fc5f9 \n", - "693204 fb467982dcc77a7f9199bebe709bb700 8d34a33f017ea0d1498b0cebf26fc5f9 \n", - "693205 fb467982dcc77a7f9199bebe709bb700 8d34a33f017ea0d1498b0cebf26fc5f9 \n", - "693206 fb467982dcc77a7f9199bebe709bb700 8d34a33f017ea0d1498b0cebf26fc5f9 \n", - "\n", - " shape_id \\\n", - "0 b0c096a2-4c32-4675-b005-43b58b3781e6 \n", - "1 b0c096a2-4c32-4675-b005-43b58b3781e6 \n", - "2 b0c096a2-4c32-4675-b005-43b58b3781e6 \n", - "3 b0c096a2-4c32-4675-b005-43b58b3781e6 \n", - "4 b0c096a2-4c32-4675-b005-43b58b3781e6 \n", - "... ... \n", - "693202 114150 \n", - "693203 114150 \n", - "693204 114150 \n", - "693205 114150 \n", - "693206 114150 \n", - "\n", - " route_id route_short_name \\\n", - "0 874b0dfa-ab3d-47da-ac75-5fd7b9bdea42 C30 WB \n", - "1 874b0dfa-ab3d-47da-ac75-5fd7b9bdea42 C30 WB \n", - "2 874b0dfa-ab3d-47da-ac75-5fd7b9bdea42 C30 WB \n", - "3 874b0dfa-ab3d-47da-ac75-5fd7b9bdea42 C30 WB \n", - "4 874b0dfa-ab3d-47da-ac75-5fd7b9bdea42 C30 WB \n", - "... ... ... \n", - "693202 21 21 \n", - "693203 21 21 \n", - "693204 21 21 \n", - "693205 21 21 \n", - "693206 21 21 \n", - "\n", - " stop_pair \\\n", - "0 0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352... \n", - "1 0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352... \n", - "2 0d1ef8b5-90e4-40de-b37b-504cb862d18b__5b9a7352... \n", - "3 5b9a7352-556f-4272-b663-22f9821d6a40__5f894da7... \n", - "4 5b9a7352-556f-4272-b663-22f9821d6a40__5f894da7... \n", - "... ... \n", - "693202 61591__61592 \n", - "693203 61592__61593 \n", - "693204 61593__61422 \n", - "693205 61422__61423 \n", - "693206 61423__61424 \n", - "\n", - " stop_pair_name \\\n", - "0 Woodlake Park EB__Cypress St & Naranjo Blvd WB \n", - "1 Woodlake Park EB__Cypress St & Naranjo Blvd WB \n", - "2 Woodlake Park EB__Cypress St & Naranjo Blvd WB \n", - "3 Cypress St & Naranjo Blvd WB__Millwood and Roa... \n", - "4 Cypress St & Naranjo Blvd WB__Millwood and Roa... \n", - "... ... \n", - "693202 California & Showers__California & Ortega \n", - "693203 California & Ortega__California & Rengstorff \n", - "693204 California & Rengstorff__California & Escuela \n", - "693205 California & Escuela__California & Mariposa \n", - "693206 California & Mariposa__California & Palo Alto \n", - "\n", - " segment_id time_of_day \\\n", - "0 0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-... AM Peak \n", - "1 0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-... Midday \n", - "2 0d1ef8b5-90e4-40de-b37b-504cb862d18b-5b9a7352-... PM Peak \n", - "3 5b9a7352-556f-4272-b663-22f9821d6a40-5f894da7-... AM Peak \n", - "4 5b9a7352-556f-4272-b663-22f9821d6a40-5f894da7-... Midday \n", - "... ... ... \n", - "693202 61591-61592-1 Evening \n", - "693203 61592-61593-1 Evening \n", - "693204 61593-61422-1 Evening \n", - "693205 61422-61423-1 Evening \n", - "693206 61423-61424-1 Evening \n", - "\n", - " p50_mph n_trips p20_mph p80_mph \\\n", - "0 17.27 4 15.20 20.96 \n", - "1 20.38 6 18.46 23.02 \n", - "2 23.90 5 22.49 25.11 \n", - "3 49.50 8 43.85 51.81 \n", - "4 47.58 12 44.74 49.68 \n", - "... ... ... ... ... \n", - "693202 24.71 1 24.71 24.71 \n", - "693203 24.68 1 24.68 24.68 \n", - "693204 24.44 1 24.44 24.44 \n", - "693205 15.27 1 15.27 15.27 \n", - "693206 14.83 1 14.83 14.83 \n", - "\n", - " name caltrans_district \\\n", - "0 TCRTA TripShot Schedule 06 - Fresno \n", - "1 TCRTA TripShot Schedule 06 - Fresno \n", - "2 TCRTA TripShot Schedule 06 - Fresno \n", - "3 TCRTA TripShot Schedule 06 - Fresno \n", - "4 TCRTA TripShot Schedule 06 - Fresno \n", - "... ... ... \n", - "693202 Bay Area 511 Santa Clara Transit Schedule 04 - Oakland \n", - "693203 Bay Area 511 Santa Clara Transit Schedule 04 - Oakland \n", - "693204 Bay Area 511 Santa Clara Transit Schedule 04 - Oakland \n", - "693205 Bay Area 511 Santa Clara Transit Schedule 04 - Oakland \n", - "693206 Bay Area 511 Santa Clara Transit Schedule 04 - Oakland \n", - "\n", - " organization_source_record_id \\\n", - "0 rec4YWVqVwJ9XqDbq \n", - "1 rec4YWVqVwJ9XqDbq \n", - "2 rec4YWVqVwJ9XqDbq \n", - "3 rec4YWVqVwJ9XqDbq \n", - "4 rec4YWVqVwJ9XqDbq \n", - "... ... \n", - "693202 recC5CT95EufmQCXr \n", - "693203 recC5CT95EufmQCXr \n", - "693204 recC5CT95EufmQCXr \n", - "693205 recC5CT95EufmQCXr \n", - "693206 recC5CT95EufmQCXr \n", - "\n", - " organization_name \\\n", - "0 Tulare County Regional Transit Agency \n", - "1 Tulare County Regional Transit Agency \n", - "2 Tulare County Regional Transit Agency \n", - "3 Tulare County Regional Transit Agency \n", - "4 Tulare County Regional Transit Agency \n", - "... ... \n", - "693202 Santa Clara Valley Transportation Authority \n", - "693203 Santa Clara Valley Transportation Authority \n", - "693204 Santa Clara Valley Transportation Authority \n", - "693205 Santa Clara Valley Transportation Authority \n", - "693206 Santa Clara Valley Transportation Authority \n", - "\n", - " base64_url \\\n", - "0 aHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy... \n", - "1 aHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy... \n", - "2 aHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy... \n", - "3 aHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy... \n", - "4 aHR0cHM6Ly90Y3J0YS50cmlwc2hvdC5jb20vdjEvZ3Rmcy... \n", - "... ... \n", - "693202 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "693203 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "693204 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "693205 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "693206 aHR0cHM6Ly9hcGkuNTExLm9yZy90cmFuc2l0L2RhdGFmZW... \n", - "\n", - " geometry \n", - "0 LINESTRING (-119.09762 36.41481, -119.09762 36... \n", - "1 LINESTRING (-119.09762 36.41481, -119.09762 36... \n", - "2 LINESTRING (-119.09762 36.41481, -119.09762 36... \n", - "3 LINESTRING (-119.10550 36.41377, -119.10562 36... \n", - "4 LINESTRING (-119.10550 36.41377, -119.10562 36... \n", - "... ... \n", - "693202 LINESTRING (-122.10605 37.40280, -122.10581 37... \n", - "693203 LINESTRING (-122.10339 37.40108, -122.10266 37... \n", - "693204 LINESTRING (-122.09992 37.39895, -122.09902 37... \n", - "693205 LINESTRING (-122.09415 37.39670, -122.09225 37... \n", - "693206 LINESTRING (-122.08948 37.39486, -122.08939 37... \n", - "\n", - "[693207 rows x 19 columns]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "detail" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "64d2f707-77c7-4d4d-be06-156728ae0e2b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'dir': '${gcs_paths.COMPILED_CACHED_VIEWS}', 'trips': 'trips', 'shapes': 'routelines', 'stops': 'stops', 'stop_times': 'st'}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "catalog.schedule_downloads" - ] - }, - { - "cell_type": "code", - "execution_count": 12, + "execution_count": 25, "id": "294b8f67-1486-48e9-8fe9-015b009d8e53", "metadata": {}, "outputs": [], @@ -801,7 +315,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 26, "id": "508d38d4-086c-43e6-8044-6ded0882e105", "metadata": {}, "outputs": [ @@ -811,7 +325,7 @@ "'gs://calitp-analytics-data/data-analyses/rt_delay/compiled_cached_views/trips_2024-10-16.parquet'" ] }, - "execution_count": 13, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -822,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 27, "id": "dc3543ea-2544-4917-887e-9de4441fb460", "metadata": {}, "outputs": [], @@ -832,39 +346,18 @@ }, { "cell_type": "code", - "execution_count": 15, - "id": "2153ab94-b927-40b4-8496-6bf82b4dd591", - "metadata": {}, - "outputs": [], - "source": [ - "trips = trips >> select(_.trip_instance_key, _.schedule_gtfs_dataset_key == _.gtfs_dataset_key,\n", - " _.route_id, _.direction_id, _.shape_id)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "8ea7c1f6-7b14-4651-8263-c2a76fa9d38c", - "metadata": {}, - "outputs": [], - "source": [ - "time_buckets = gtfs_schedule_wrangling.get_trip_time_buckets(analysis_date)" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "75ce3325-f97a-4848-bee2-e034264221a1", + "execution_count": 28, + "id": "de097b6e-9b83-4d3a-b3e6-3646c7c7be86", "metadata": {}, "outputs": [], "source": [ - "trips = trips >> inner_join(_, time_buckets, on='trip_instance_key')" + "df = gtfs_schedule_wrangling.get_sched_trips_hr(analysis_date)" ] }, { "cell_type": "code", - "execution_count": 22, - "id": "2ad85cd8-59eb-43d2-ac4b-7b4473d6047b", + "execution_count": 29, + "id": "55d704c5-1a87-4bbf-bcde-e867b53c3988", "metadata": {}, "outputs": [ { @@ -894,6 +387,7 @@ " time_of_day\n", " schedule_gtfs_dataset_key\n", " n_trips\n", + " trips_hr\n", " \n", " \n", " \n", @@ -905,6 +399,7 @@ " AM Peak\n", " 9809d3f8121513057bc5cb8de7b54ce2\n", " 3\n", + " 1.000000\n", " \n", " \n", " 1\n", @@ -914,6 +409,7 @@ " Early AM\n", " 9809d3f8121513057bc5cb8de7b54ce2\n", " 1\n", + " 0.333333\n", " \n", " \n", " 2\n", @@ -923,168 +419,45 @@ " Midday\n", " 9809d3f8121513057bc5cb8de7b54ce2\n", " 5\n", - " \n", - " \n", - " 3\n", - " 001\n", - " 0.0\n", - " 0010111\n", - " PM Peak\n", - " 9809d3f8121513057bc5cb8de7b54ce2\n", - " 3\n", - " \n", - " \n", - " 4\n", - " 001\n", - " 0.0\n", - " 47840\n", - " AM Peak\n", - " 70c8a8b71c815224299523bf2115924a\n", - " 12\n", - " \n", - " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " \n", - " \n", - " 18369\n", - " shrdserv\n", - " 0.0\n", - " shrdserv_loop_3\n", - " PM Peak\n", - " a8d5f90bfd689badb7e1deb041408e96\n", - " 1\n", - " \n", - " \n", - " 18370\n", - " valleywide\n", - " 1.0\n", - " valleywide\n", - " AM Peak\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 12\n", - " \n", - " \n", - " 18371\n", - " valleywide\n", - " 1.0\n", - " valleywide\n", - " Evening\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 9\n", - " \n", - " \n", - " 18372\n", - " valleywide\n", - " 1.0\n", - " valleywide\n", - " Midday\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 20\n", - " \n", - " \n", - " 18373\n", - " valleywide\n", - " 1.0\n", - " valleywide\n", - " PM Peak\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 20\n", + " 1.000000\n", " \n", " \n", "\n", - "

18374 rows × 6 columns

\n", "" ], "text/plain": [ - " route_id direction_id shape_id time_of_day \\\n", - "0 001 0.0 0010111 AM Peak \n", - "1 001 0.0 0010111 Early AM \n", - "2 001 0.0 0010111 Midday \n", - "3 001 0.0 0010111 PM Peak \n", - "4 001 0.0 47840 AM Peak \n", - "... ... ... ... ... \n", - "18369 shrdserv 0.0 shrdserv_loop_3 PM Peak \n", - "18370 valleywide 1.0 valleywide AM Peak \n", - "18371 valleywide 1.0 valleywide Evening \n", - "18372 valleywide 1.0 valleywide Midday \n", - "18373 valleywide 1.0 valleywide PM Peak \n", - "\n", - " schedule_gtfs_dataset_key n_trips \n", - "0 9809d3f8121513057bc5cb8de7b54ce2 3 \n", - "1 9809d3f8121513057bc5cb8de7b54ce2 1 \n", - "2 9809d3f8121513057bc5cb8de7b54ce2 5 \n", - "3 9809d3f8121513057bc5cb8de7b54ce2 3 \n", - "4 70c8a8b71c815224299523bf2115924a 12 \n", - "... ... ... \n", - "18369 a8d5f90bfd689badb7e1deb041408e96 1 \n", - "18370 31152914d10e2d0977b8b2fabb167922 12 \n", - "18371 31152914d10e2d0977b8b2fabb167922 9 \n", - "18372 31152914d10e2d0977b8b2fabb167922 20 \n", - "18373 31152914d10e2d0977b8b2fabb167922 20 \n", - "\n", - "[18374 rows x 6 columns]" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "schedule_trip_counts = gtfs_schedule_wrangling.count_trips_by_group(trips, ['route_id', 'direction_id', 'shape_id',\n", - " 'time_of_day', 'schedule_gtfs_dataset_key'])\n", - "schedule_trip_counts" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "a34abeb3-e433-4731-962e-3394af7b6f61", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Midday 5\n", - "PM Peak 5\n", - "Evening 5\n", - "Owl 4\n", - "Early AM 3\n", - "AM Peak 3\n", - "dtype: int64" + " route_id direction_id shape_id time_of_day \\\n", + "0 001 0.0 0010111 AM Peak \n", + "1 001 0.0 0010111 Early AM \n", + "2 001 0.0 0010111 Midday \n", + "\n", + " schedule_gtfs_dataset_key n_trips trips_hr \n", + "0 9809d3f8121513057bc5cb8de7b54ce2 3 1.000000 \n", + "1 9809d3f8121513057bc5cb8de7b54ce2 1 0.333333 \n", + "2 9809d3f8121513057bc5cb8de7b54ce2 5 1.000000 " ] }, - "execution_count": 23, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "durations = shared_utils.rt_utils.time_of_day_durations()\n", - "durations" + "df >> head(3)" ] }, { - "cell_type": "code", - "execution_count": 28, - "id": "f1b1c9f1-166f-4f64-81d7-51c8eb4b23ff", + "cell_type": "markdown", + "id": "6a062796-ae2f-4081-b73b-8923c7bd85b2", "metadata": {}, - "outputs": [], "source": [ - "schedule_trip_counts['trips_hr'] = schedule_trip_counts.apply(\n", - " lambda x: x.n_trips / durations[x.time_of_day], axis=1)" + "## Where'd the J line go??" ] }, { "cell_type": "code", - "execution_count": 29, - "id": "be6afedb-9009-4374-9cd8-dba841487615", + "execution_count": 30, + "id": "1ded1f93-6458-4365-b30b-744417bbf19f", "metadata": {}, "outputs": [ { @@ -1119,166 +492,393 @@ " \n", " \n", " \n", - " 0\n", - " 001\n", + " 15680\n", + " 910-13183\n", " 0.0\n", - " 0010111\n", + " 9100214_JUNE24\n", " AM Peak\n", - " 9809d3f8121513057bc5cb8de7b54ce2\n", - " 3\n", - " 1.000000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 19\n", + " 6.333333\n", " \n", " \n", - " 1\n", - " 001\n", + " 15681\n", + " 910-13183\n", " 0.0\n", - " 0010111\n", + " 9100214_JUNE24\n", " Early AM\n", - " 9809d3f8121513057bc5cb8de7b54ce2\n", - " 1\n", - " 0.333333\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 15\n", + " 5.000000\n", " \n", " \n", - " 2\n", - " 001\n", + " 15682\n", + " 910-13183\n", " 0.0\n", - " 0010111\n", + " 9100214_JUNE24\n", + " Evening\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 9\n", + " 1.800000\n", + " \n", + " \n", + " 15683\n", + " 910-13183\n", + " 0.0\n", + " 9100214_JUNE24\n", " Midday\n", - " 9809d3f8121513057bc5cb8de7b54ce2\n", - " 5\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 22\n", + " 4.400000\n", + " \n", + " \n", + " 15684\n", + " 910-13183\n", + " 0.0\n", + " 9100214_JUNE24\n", + " Owl\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 4\n", " 1.000000\n", " \n", " \n", - " 3\n", - " 001\n", + " 15685\n", + " 910-13183\n", " 0.0\n", - " 0010111\n", + " 9100214_JUNE24\n", " PM Peak\n", - " 9809d3f8121513057bc5cb8de7b54ce2\n", - " 3\n", - " 0.600000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 32\n", + " 6.400000\n", " \n", " \n", - " 4\n", - " 001\n", + " 15686\n", + " 910-13183\n", " 0.0\n", - " 47840\n", + " 9100215_JUNE24\n", " AM Peak\n", - " 70c8a8b71c815224299523bf2115924a\n", - " 12\n", - " 4.000000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 7\n", + " 2.333333\n", " \n", " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", + " 15687\n", + " 910-13183\n", + " 0.0\n", + " 9100215_JUNE24\n", + " Early AM\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 8\n", + " 2.666667\n", " \n", " \n", - " 18369\n", - " shrdserv\n", + " 15688\n", + " 910-13183\n", " 0.0\n", - " shrdserv_loop_3\n", - " PM Peak\n", - " a8d5f90bfd689badb7e1deb041408e96\n", + " 9100215_JUNE24\n", + " Evening\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", " 1\n", " 0.200000\n", " \n", " \n", - " 18370\n", - " valleywide\n", + " 15689\n", + " 910-13183\n", + " 0.0\n", + " 9100215_JUNE24\n", + " Midday\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 11\n", + " 2.200000\n", + " \n", + " \n", + " 15690\n", + " 910-13183\n", + " 0.0\n", + " 9100215_JUNE24\n", + " PM Peak\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 11\n", + " 2.200000\n", + " \n", + " \n", + " 15691\n", + " 910-13183\n", " 1.0\n", - " valleywide\n", + " 9100209_JUNE24\n", " AM Peak\n", - " 31152914d10e2d0977b8b2fabb167922\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 7\n", + " 2.333333\n", + " \n", + " \n", + " 15692\n", + " 910-13183\n", + " 1.0\n", + " 9100209_JUNE24\n", + " Early AM\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 8\n", + " 2.666667\n", + " \n", + " \n", + " 15693\n", + " 910-13183\n", + " 1.0\n", + " 9100209_JUNE24\n", + " Midday\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", " 12\n", - " 4.000000\n", + " 2.400000\n", " \n", " \n", - " 18371\n", - " valleywide\n", + " 15694\n", + " 910-13183\n", " 1.0\n", - " valleywide\n", + " 9100209_JUNE24\n", + " Owl\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 1\n", + " 0.250000\n", + " \n", + " \n", + " 15695\n", + " 910-13183\n", + " 1.0\n", + " 9100209_JUNE24\n", + " PM Peak\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 15\n", + " 3.000000\n", + " \n", + " \n", + " 15696\n", + " 910-13183\n", + " 1.0\n", + " 9100210_JUNE24\n", + " AM Peak\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 19\n", + " 6.333333\n", + " \n", + " \n", + " 15697\n", + " 910-13183\n", + " 1.0\n", + " 9100210_JUNE24\n", + " Early AM\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 18\n", + " 6.000000\n", + " \n", + " \n", + " 15698\n", + " 910-13183\n", + " 1.0\n", + " 9100210_JUNE24\n", " Evening\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 9\n", - " 1.800000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 11\n", + " 2.200000\n", " \n", " \n", - " 18372\n", - " valleywide\n", + " 15699\n", + " 910-13183\n", " 1.0\n", - " valleywide\n", + " 9100210_JUNE24\n", " Midday\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 20\n", - " 4.000000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 21\n", + " 4.200000\n", " \n", " \n", - " 18373\n", - " valleywide\n", + " 15700\n", + " 910-13183\n", " 1.0\n", - " valleywide\n", + " 9100210_JUNE24\n", + " Owl\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 4\n", + " 1.000000\n", + " \n", + " \n", + " 15701\n", + " 910-13183\n", + " 1.0\n", + " 9100210_JUNE24\n", " PM Peak\n", - " 31152914d10e2d0977b8b2fabb167922\n", - " 20\n", - " 4.000000\n", + " 0666caf3ec1ecc96b74f4477ee4bc939\n", + " 30\n", + " 6.000000\n", " \n", " \n", "\n", - "

18374 rows × 7 columns

\n", "" ], "text/plain": [ - " route_id direction_id shape_id time_of_day \\\n", - "0 001 0.0 0010111 AM Peak \n", - "1 001 0.0 0010111 Early AM \n", - "2 001 0.0 0010111 Midday \n", - "3 001 0.0 0010111 PM Peak \n", - "4 001 0.0 47840 AM Peak \n", - "... ... ... ... ... \n", - "18369 shrdserv 0.0 shrdserv_loop_3 PM Peak \n", - "18370 valleywide 1.0 valleywide AM Peak \n", - "18371 valleywide 1.0 valleywide Evening \n", - "18372 valleywide 1.0 valleywide Midday \n", - "18373 valleywide 1.0 valleywide PM Peak \n", + " route_id direction_id shape_id time_of_day \\\n", + "15680 910-13183 0.0 9100214_JUNE24 AM Peak \n", + "15681 910-13183 0.0 9100214_JUNE24 Early AM \n", + "15682 910-13183 0.0 9100214_JUNE24 Evening \n", + "15683 910-13183 0.0 9100214_JUNE24 Midday \n", + "15684 910-13183 0.0 9100214_JUNE24 Owl \n", + "15685 910-13183 0.0 9100214_JUNE24 PM Peak \n", + "15686 910-13183 0.0 9100215_JUNE24 AM Peak \n", + "15687 910-13183 0.0 9100215_JUNE24 Early AM \n", + "15688 910-13183 0.0 9100215_JUNE24 Evening \n", + "15689 910-13183 0.0 9100215_JUNE24 Midday \n", + "15690 910-13183 0.0 9100215_JUNE24 PM Peak \n", + "15691 910-13183 1.0 9100209_JUNE24 AM Peak \n", + "15692 910-13183 1.0 9100209_JUNE24 Early AM \n", + "15693 910-13183 1.0 9100209_JUNE24 Midday \n", + "15694 910-13183 1.0 9100209_JUNE24 Owl \n", + "15695 910-13183 1.0 9100209_JUNE24 PM Peak \n", + "15696 910-13183 1.0 9100210_JUNE24 AM Peak \n", + "15697 910-13183 1.0 9100210_JUNE24 Early AM \n", + "15698 910-13183 1.0 9100210_JUNE24 Evening \n", + "15699 910-13183 1.0 9100210_JUNE24 Midday \n", + "15700 910-13183 1.0 9100210_JUNE24 Owl \n", + "15701 910-13183 1.0 9100210_JUNE24 PM Peak \n", "\n", " schedule_gtfs_dataset_key n_trips trips_hr \n", - "0 9809d3f8121513057bc5cb8de7b54ce2 3 1.000000 \n", - "1 9809d3f8121513057bc5cb8de7b54ce2 1 0.333333 \n", - "2 9809d3f8121513057bc5cb8de7b54ce2 5 1.000000 \n", - "3 9809d3f8121513057bc5cb8de7b54ce2 3 0.600000 \n", - "4 70c8a8b71c815224299523bf2115924a 12 4.000000 \n", - "... ... ... ... \n", - "18369 a8d5f90bfd689badb7e1deb041408e96 1 0.200000 \n", - "18370 31152914d10e2d0977b8b2fabb167922 12 4.000000 \n", - "18371 31152914d10e2d0977b8b2fabb167922 9 1.800000 \n", - "18372 31152914d10e2d0977b8b2fabb167922 20 4.000000 \n", - "18373 31152914d10e2d0977b8b2fabb167922 20 4.000000 \n", - "\n", - "[18374 rows x 7 columns]" + "15680 0666caf3ec1ecc96b74f4477ee4bc939 19 6.333333 \n", + "15681 0666caf3ec1ecc96b74f4477ee4bc939 15 5.000000 \n", + "15682 0666caf3ec1ecc96b74f4477ee4bc939 9 1.800000 \n", + "15683 0666caf3ec1ecc96b74f4477ee4bc939 22 4.400000 \n", + "15684 0666caf3ec1ecc96b74f4477ee4bc939 4 1.000000 \n", + "15685 0666caf3ec1ecc96b74f4477ee4bc939 32 6.400000 \n", + "15686 0666caf3ec1ecc96b74f4477ee4bc939 7 2.333333 \n", + "15687 0666caf3ec1ecc96b74f4477ee4bc939 8 2.666667 \n", + "15688 0666caf3ec1ecc96b74f4477ee4bc939 1 0.200000 \n", + "15689 0666caf3ec1ecc96b74f4477ee4bc939 11 2.200000 \n", + "15690 0666caf3ec1ecc96b74f4477ee4bc939 11 2.200000 \n", + "15691 0666caf3ec1ecc96b74f4477ee4bc939 7 2.333333 \n", + "15692 0666caf3ec1ecc96b74f4477ee4bc939 8 2.666667 \n", + "15693 0666caf3ec1ecc96b74f4477ee4bc939 12 2.400000 \n", + "15694 0666caf3ec1ecc96b74f4477ee4bc939 1 0.250000 \n", + "15695 0666caf3ec1ecc96b74f4477ee4bc939 15 3.000000 \n", + "15696 0666caf3ec1ecc96b74f4477ee4bc939 19 6.333333 \n", + "15697 0666caf3ec1ecc96b74f4477ee4bc939 18 6.000000 \n", + "15698 0666caf3ec1ecc96b74f4477ee4bc939 11 2.200000 \n", + "15699 0666caf3ec1ecc96b74f4477ee4bc939 21 4.200000 \n", + "15700 0666caf3ec1ecc96b74f4477ee4bc939 4 1.000000 \n", + "15701 0666caf3ec1ecc96b74f4477ee4bc939 30 6.000000 " ] }, - "execution_count": 29, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "schedule_trip_counts" + "df >> filter(_.route_id.str.contains('910'))" ] }, { "cell_type": "code", - "execution_count": null, - "id": "de097b6e-9b83-4d3a-b3e6-3646c7c7be86", + "execution_count": 37, + "id": "32cf4f45-bf10-4edf-a525-7804ea7ada47", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "path = f'{catalog.speedmap_segments.dir}{catalog.speedmap_segments.shape_stop_single_segment_detail}_{analysis_date}.parquet'" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "ef401846-f54c-4805-a7aa-53ed1b630837", + "metadata": {}, + "outputs": [], + "source": [ + "speedmap_segs = gpd.read_parquet(path) # aggregated" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "ffcec5ce-dcc2-402b-bef0-60f6bd25dd77", + "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", + "
schedule_gtfs_dataset_keyshape_array_keyshape_idroute_idroute_short_namestop_pairstop_pair_namesegment_idtime_of_dayp50_mph...p20_mphp80_mphnamecaltrans_districtorganization_source_record_idorganization_namebase64_urlgeometryn_trips_schtrips_hr_sch
\n", + "

0 rows × 21 columns

\n", + "
" + ], + "text/plain": [ + "Empty GeoDataFrame\n", + "Columns: [schedule_gtfs_dataset_key, shape_array_key, shape_id, route_id, route_short_name, stop_pair, stop_pair_name, segment_id, time_of_day, p50_mph, n_trips, p20_mph, p80_mph, name, caltrans_district, organization_source_record_id, organization_name, base64_url, geometry, n_trips_sch, trips_hr_sch]\n", + "Index: []\n", + "\n", + "[0 rows x 21 columns]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "speedmap_segs >> filter(_.route_id.str.contains('910'))" + ] + }, + { + "cell_type": "markdown", + "id": "f919f640-261f-427f-be55-e8b2e4349f12", + "metadata": {}, + "source": [ + "it has no route_short_name...\n", + "```\n", + "857-13183,857,Metro Local Line,C & K LINE LINK,3,,,\n", + "901-13183,,Metro G Line 901,METRO G LINE,3,FC4C02,FFFFFF,https://www.metro.net/g-line/\n", + "910-13183,,Metro J Line 910/950,METRO J LINE,3,ADB8BF,000000,https://www.metro.net/j-line/\n", + "```" + ] } ], "metadata": { diff --git a/rt_segment_speeds/logs/avg_speeds.log b/rt_segment_speeds/logs/avg_speeds.log index c91452ed7..d46d0d878 100644 --- a/rt_segment_speeds/logs/avg_speeds.log +++ b/rt_segment_speeds/logs/avg_speeds.log @@ -537,3 +537,6 @@ 2024-11-01 09:18:04.863 | INFO | average_segment_speeds:segment_averages_detail:239 - speedmap_segments detailed segment averaging for ['2024-10-16'] execution time: 0:06:29.243269 2024-11-01 09:23:55.409 | INFO | average_segment_speeds:segment_averages:182 - speedmap_segments segment averaging for ['2024-10-16'] execution time: 0:05:50.230382 2024-11-01 09:28:10.012 | INFO | average_segment_speeds:segment_averages:182 - speedmap_segments segment averaging for ['2024-10-16'] execution time: 0:04:14.446376 +2024-11-04 12:49:57.565 | INFO | average_segment_speeds:segment_averages_detail:245 - speedmap_segments detailed segment averaging for ['2024-10-16'] execution time: 0:06:25.396982 +2024-11-04 12:55:52.804 | INFO | average_segment_speeds:segment_averages:182 - speedmap_segments segment averaging for ['2024-10-16'] execution time: 0:05:55.031920 +2024-11-04 13:00:43.796 | INFO | average_segment_speeds:segment_averages:182 - speedmap_segments segment averaging for ['2024-10-16'] execution time: 0:04:50.815376 diff --git a/rt_segment_speeds/scripts/average_segment_speeds.py b/rt_segment_speeds/scripts/average_segment_speeds.py index d795407af..de1dcd32e 100644 --- a/rt_segment_speeds/scripts/average_segment_speeds.py +++ b/rt_segment_speeds/scripts/average_segment_speeds.py @@ -228,6 +228,12 @@ def segment_averages_detail( ) avg_speeds_with_geom = compute(avg_speeds_with_geom)[0] + # is this the best spot to add scheduled frequency? + sched_trips_hr = gtfs_schedule_wrangling.get_sched_trips_hr(analysis_date) + sched_trips_hr = sched_trips_hr.rename(columns={'n_trips': 'n_trips_sch', 'trips_hr': 'trips_hr_sch'}) + sched_trips_hr_cols = ['route_id', 'shape_id', + 'time_of_day', 'schedule_gtfs_dataset_key'] + avg_speeds_with_geom = pd.merge(avg_speeds_with_geom, sched_trips_hr, on=sched_trips_hr_cols) utils.geoparquet_gcs_export( avg_speeds_with_geom, diff --git a/rt_segment_speeds/segment_speed_utils/gtfs_schedule_wrangling.py b/rt_segment_speeds/segment_speed_utils/gtfs_schedule_wrangling.py index c11ae220a..3ddef7107 100644 --- a/rt_segment_speeds/segment_speed_utils/gtfs_schedule_wrangling.py +++ b/rt_segment_speeds/segment_speed_utils/gtfs_schedule_wrangling.py @@ -515,6 +515,27 @@ def merge_operator_identifiers( return df +def get_sched_trips_hr(analysis_date: str) -> pd.DataFrame: + """ + For speedmaps (and other analyses), it's helpful to have scheduled + frequency available. Currently only supports detailed time of day. + """ + keep_trip_cols = ['trip_instance_key', 'gtfs_dataset_key', 'route_id', + 'shape_id'] + trips = helpers.import_scheduled_trips(analysis_date, columns=keep_trip_cols) + trips = trips.rename( + columns={'gtfs_dataset_key': 'schedule_gtfs_dataset_key'}) + time_buckets = get_trip_time_buckets(analysis_date) + trips = pd.merge(trips, time_buckets, on='trip_instance_key', how='inner') + schedule_trip_counts = count_trips_by_group(trips, + ['route_id', 'shape_id', + 'time_of_day', 'schedule_gtfs_dataset_key'] + ) + durations = rt_utils.time_of_day_durations() + schedule_trip_counts['trips_hr'] = schedule_trip_counts.apply( + lambda x: x.n_trips / durations[x.time_of_day], axis=1) + return schedule_trip_counts + def fill_missing_stop_sequence1(df: pd.DataFrame) -> pd.DataFrame: """