diff --git a/traffic_ops/04_station_locations.ipynb b/traffic_ops/04_station_locations.ipynb new file mode 100644 index 000000000..19c08cb0e --- /dev/null +++ b/traffic_ops/04_station_locations.ipynb @@ -0,0 +1,1793 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "9c9fb135-eec5-4e43-9ef8-9f266d4ea5ac", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "1f8dbab0-b39a-4ba0-962c-9577a621a0f5", + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import pandas as pd\n", + "\n", + "from IPython.display import Markdown\n", + "from utils import PROCESSED_GCS" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "fb2551c6-5391-4835-9ccd-1ab31f4569da", + "metadata": {}, + "outputs": [], + "source": [ + "df = gpd.read_parquet(\n", + " f\"{PROCESSED_GCS}stations_postmiles_crosswalk.parquet\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5efa394d-9c0a-43e9-b43d-8369a20c6154", + "metadata": {}, + "outputs": [], + "source": [ + "stations = df[[\"district_id\", \"geometry\"]].dissolve(by=\"district_id\").reset_index()\n", + "\n", + "df2 = (df\n", + " .groupby([\"district_id\", \"freeway_id\", \"freeway_direction\", \"routetype\"])\n", + " .agg({\n", + " \"station_uuid\": \"nunique\",\n", + " \"physical_lanes\": \"mean\",\n", + " \"county_id\": lambda x: list(set(x))\n", + " }).reset_index()\n", + " .rename(columns = {\n", + " \"station_uuid\": \"n_stations\",\n", + " \"county_id\": \"county_codes\",\n", + " \"physical_lanes\": \"avg_lanes\"\n", + " })\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "fec2e5b0-c2e4-454d-acfa-daf19c321def", + "metadata": {}, + "outputs": [], + "source": [ + "def district_summaries(df: pd.DataFrame, stations: gpd.GeoDataFrame, one_district: int):\n", + " display(Markdown(f\"## D{one_district}\"))\n", + " \n", + " display(df[df.district_id==one_district].reset_index(drop=True))\n", + " \n", + " m = stations[stations.district_id==one_district].explore(\n", + " tiles = \"CartoDB Positron\"\n", + " )\n", + " display(m)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e077032d-040c-480c-a153-2a3e5b9e05dd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "## D3" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
035NInterstate373.513514[67]
135SInterstate313.645161[67]
2350EUS1572.165605[17, 67]
3350WUS1342.108696[17, 67]
4351NState23.500000[67]
5351SState22.000000[67]
6380EInterstate842.666667[67, 61]
7380WInterstate1042.432692[67, 61]
8399NState621.870968[67]
9399SState582.034483[67]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 3 5 N Interstate 37 \n", + "1 3 5 S Interstate 31 \n", + "2 3 50 E US 157 \n", + "3 3 50 W US 134 \n", + "4 3 51 N State 2 \n", + "5 3 51 S State 2 \n", + "6 3 80 E Interstate 84 \n", + "7 3 80 W Interstate 104 \n", + "8 3 99 N State 62 \n", + "9 3 99 S State 58 \n", + "\n", + " avg_lanes county_codes \n", + "0 3.513514 [67] \n", + "1 3.645161 [67] \n", + "2 2.165605 [17, 67] \n", + "3 2.108696 [17, 67] \n", + "4 3.500000 [67] \n", + "5 2.000000 [67] \n", + "6 2.666667 [67, 61] \n", + "7 2.432692 [67, 61] \n", + "8 1.870968 [67] \n", + "9 2.034483 [67] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D4" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
044EState163.944444[13]
144WState204.227273[13]
2480EInterstate534.396226[1, 13, 95]
3480WInterstate554.500000[1, 13, 95]
4485NState243.125000[85]
5485SState283.142857[85]
6487NState23.000000[85]
7487SState13.000000[85]
8492WState34.000000[1]
94101NUS1524.013072[81, 85, 97, 41]
104101SUS1483.906667[81, 85, 97, 41]
114237EState63.000000[85]
124237WState83.125000[85]
134280NInterstate54.200000[85]
144280SInterstate64.000000[85]
154680NInterstate384.105263[1, 13]
164680SInterstate614.459016[1, 85, 13]
174880NInterstate344.333333[1, 85]
184880SInterstate454.425532[1, 85]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 4 4 E State 16 \n", + "1 4 4 W State 20 \n", + "2 4 80 E Interstate 53 \n", + "3 4 80 W Interstate 55 \n", + "4 4 85 N State 24 \n", + "5 4 85 S State 28 \n", + "6 4 87 N State 2 \n", + "7 4 87 S State 1 \n", + "8 4 92 W State 3 \n", + "9 4 101 N US 152 \n", + "10 4 101 S US 148 \n", + "11 4 237 E State 6 \n", + "12 4 237 W State 8 \n", + "13 4 280 N Interstate 5 \n", + "14 4 280 S Interstate 6 \n", + "15 4 680 N Interstate 38 \n", + "16 4 680 S Interstate 61 \n", + "17 4 880 N Interstate 34 \n", + "18 4 880 S Interstate 45 \n", + "\n", + " avg_lanes county_codes \n", + "0 3.944444 [13] \n", + "1 4.227273 [13] \n", + "2 4.396226 [1, 13, 95] \n", + "3 4.500000 [1, 13, 95] \n", + "4 3.125000 [85] \n", + "5 3.142857 [85] \n", + "6 3.000000 [85] \n", + "7 3.000000 [85] \n", + "8 4.000000 [1] \n", + "9 4.013072 [81, 85, 97, 41] \n", + "10 3.906667 [81, 85, 97, 41] \n", + "11 3.000000 [85] \n", + "12 3.125000 [85] \n", + "13 4.200000 [85] \n", + "14 4.000000 [85] \n", + "15 4.105263 [1, 13] \n", + "16 4.459016 [1, 85, 13] \n", + "17 4.333333 [1, 85] \n", + "18 4.425532 [1, 85] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D5" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
05101NUS52.857143[83]
15101SUS63.000000[83]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations avg_lanes \\\n", + "0 5 101 N US 5 2.857143 \n", + "1 5 101 S US 6 3.000000 \n", + "\n", + " county_codes \n", + "0 [83] \n", + "1 [83] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D7" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
075NInterstate64.000000[37]
175SInterstate64.000000[37]
2710EInterstate413.121951[37]
3710WInterstate483.187500[37]
4714NState102.083333[37]
5714SState171.894737[37]
6760EState462.782609[37]
7760WState482.833333[37]
8791EState192.826087[37]
9791WState212.480000[37]
107105WInterstate52.400000[37]
117110NInterstate15.000000[37]
127110SInterstate23.000000[37]
137118EState222.500000[37]
147118WState232.391304[37, 111]
157134EState83.400000[37]
167134WState82.500000[37]
177210EInterstate452.644444[37]
187210EState62.166667[37]
197210WInterstate482.458333[37]
207210WState102.200000[37]
217405NInterstate872.574713[37]
227405SInterstate1012.584158[37]
237605NInterstate532.660377[37]
247605SInterstate552.563636[37]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 7 5 N Interstate 6 \n", + "1 7 5 S Interstate 6 \n", + "2 7 10 E Interstate 41 \n", + "3 7 10 W Interstate 48 \n", + "4 7 14 N State 10 \n", + "5 7 14 S State 17 \n", + "6 7 60 E State 46 \n", + "7 7 60 W State 48 \n", + "8 7 91 E State 19 \n", + "9 7 91 W State 21 \n", + "10 7 105 W Interstate 5 \n", + "11 7 110 N Interstate 1 \n", + "12 7 110 S Interstate 2 \n", + "13 7 118 E State 22 \n", + "14 7 118 W State 23 \n", + "15 7 134 E State 8 \n", + "16 7 134 W State 8 \n", + "17 7 210 E Interstate 45 \n", + "18 7 210 E State 6 \n", + "19 7 210 W Interstate 48 \n", + "20 7 210 W State 10 \n", + "21 7 405 N Interstate 87 \n", + "22 7 405 S Interstate 101 \n", + "23 7 605 N Interstate 53 \n", + "24 7 605 S Interstate 55 \n", + "\n", + " avg_lanes county_codes \n", + "0 4.000000 [37] \n", + "1 4.000000 [37] \n", + "2 3.121951 [37] \n", + "3 3.187500 [37] \n", + "4 2.083333 [37] \n", + "5 1.894737 [37] \n", + "6 2.782609 [37] \n", + "7 2.833333 [37] \n", + "8 2.826087 [37] \n", + "9 2.480000 [37] \n", + "10 2.400000 [37] \n", + "11 5.000000 [37] \n", + "12 3.000000 [37] \n", + "13 2.500000 [37] \n", + "14 2.391304 [37, 111] \n", + "15 3.400000 [37] \n", + "16 2.500000 [37] \n", + "17 2.644444 [37] \n", + "18 2.166667 [37] \n", + "19 2.458333 [37] \n", + "20 2.200000 [37] \n", + "21 2.574713 [37] \n", + "22 2.584158 [37] \n", + "23 2.660377 [37] \n", + "24 2.563636 [37] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D8" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
0810EInterstate442.200000[71]
1810WInterstate532.245283[71]
2815NInterstate1102.690909[65]
3815SInterstate862.720930[65]
4860EState952.135922[65, 71]
5860WState952.538462[65, 71]
6891EState413.853659[65]
7891WState1412.539007[65]
88210EState1062.142857[71]
98210WState1062.105263[71]
108215NInterstate492.265306[65, 71]
118215SInterstate532.226415[65, 71]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 8 10 E Interstate 44 \n", + "1 8 10 W Interstate 53 \n", + "2 8 15 N Interstate 110 \n", + "3 8 15 S Interstate 86 \n", + "4 8 60 E State 95 \n", + "5 8 60 W State 95 \n", + "6 8 91 E State 41 \n", + "7 8 91 W State 141 \n", + "8 8 210 E State 106 \n", + "9 8 210 W State 106 \n", + "10 8 215 N Interstate 49 \n", + "11 8 215 S Interstate 53 \n", + "\n", + " avg_lanes county_codes \n", + "0 2.200000 [71] \n", + "1 2.245283 [71] \n", + "2 2.690909 [65] \n", + "3 2.720930 [65] \n", + "4 2.135922 [65, 71] \n", + "5 2.538462 [65, 71] \n", + "6 3.853659 [65] \n", + "7 2.539007 [65] \n", + "8 2.142857 [71] \n", + "9 2.105263 [71] \n", + "10 2.265306 [65, 71] \n", + "11 2.226415 [65, 71] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D10" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
0105NInterstate22.0[77]
1105SInterstate22.0[77]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 10 5 N Interstate 2 \n", + "1 10 5 S Interstate 2 \n", + "\n", + " avg_lanes county_codes \n", + "0 2.0 [77] \n", + "1 2.0 [77] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D11" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
0115NInterstate293.766667[73]
1115SInterstate253.320000[73]
21115NInterstate54.600000[73]
31115NState54.600000[73]
41115SInterstate134.230769[73]
51115SState34.666667[73]
611805NInterstate112.545455[73]
711805SInterstate202.550000[73]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 11 5 N Interstate 29 \n", + "1 11 5 S Interstate 25 \n", + "2 11 15 N Interstate 5 \n", + "3 11 15 N State 5 \n", + "4 11 15 S Interstate 13 \n", + "5 11 15 S State 3 \n", + "6 11 805 N Interstate 11 \n", + "7 11 805 S Interstate 20 \n", + "\n", + " avg_lanes county_codes \n", + "0 3.766667 [73] \n", + "1 3.320000 [73] \n", + "2 4.600000 [73] \n", + "3 4.600000 [73] \n", + "4 4.230769 [73] \n", + "5 4.666667 [73] \n", + "6 2.545455 [73] \n", + "7 2.550000 [73] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/markdown": [ + "## D12" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "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", + "
district_idfreeway_idfreeway_directionroutetypen_stationsavg_lanescounty_codes
0125NInterstate1572.788820[59]
1125SInterstate1602.993902[59]
21222EState702.214286[59]
31222WState662.409091[59]
41255NState452.466667[59]
51255SState242.375000[59]
61257NState553.000000[59]
71257SState472.702128[59]
81273NState103.333333[59]
91273SState73.142857[59]
101291EState743.070588[59]
111291WState712.849315[59]
1212405NInterstate1263.222222[59]
1312405SInterstate1123.044643[59]
1412605NInterstate62.666667[59]
1512605SInterstate33.333333[59]
\n", + "
" + ], + "text/plain": [ + " district_id freeway_id freeway_direction routetype n_stations \\\n", + "0 12 5 N Interstate 157 \n", + "1 12 5 S Interstate 160 \n", + "2 12 22 E State 70 \n", + "3 12 22 W State 66 \n", + "4 12 55 N State 45 \n", + "5 12 55 S State 24 \n", + "6 12 57 N State 55 \n", + "7 12 57 S State 47 \n", + "8 12 73 N State 10 \n", + "9 12 73 S State 7 \n", + "10 12 91 E State 74 \n", + "11 12 91 W State 71 \n", + "12 12 405 N Interstate 126 \n", + "13 12 405 S Interstate 112 \n", + "14 12 605 N Interstate 6 \n", + "15 12 605 S Interstate 3 \n", + "\n", + " avg_lanes county_codes \n", + "0 2.788820 [59] \n", + "1 2.993902 [59] \n", + "2 2.214286 [59] \n", + "3 2.409091 [59] \n", + "4 2.466667 [59] \n", + "5 2.375000 [59] \n", + "6 3.000000 [59] \n", + "7 2.702128 [59] \n", + "8 3.333333 [59] \n", + "9 3.142857 [59] \n", + "10 3.070588 [59] \n", + "11 2.849315 [59] \n", + "12 3.222222 [59] \n", + "13 3.044643 [59] \n", + "14 2.666667 [59] \n", + "15 3.333333 [59] " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "for d in sorted(df2.district_id.unique()):\n", + " district_summaries(df2, stations, d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86519e29-a303-4597-bcda-544c4bcdd98d", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/traffic_ops/05_volume_maps.ipynb b/traffic_ops/05_volume_maps.ipynb new file mode 100644 index 000000000..772364a24 --- /dev/null +++ b/traffic_ops/05_volume_maps.ipynb @@ -0,0 +1,401 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "51947a90-8bff-4ec8-8569-442ffe66b432", + "metadata": {}, + "source": [ + "# Traffic flows on a map\n", + "\n", + "Exploratory maps taking a look at whether we can merge PeMS data with SHN postmile segments.\n", + "\n", + "Notes:\n", + "* maps look like certain highways are missing - some interstates, as well as state routes (boulevards)....is this expected? some stations are missing, maybe 200ish out of 4,000 as we merge things together. do more work to look at which freeways are present in original PeMS.\n", + "* some districts don't have detectors? there are some districts with very few detectors, but 2-3 districts have no detectors...expected?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "29e8eb83-44ef-444b-8f0c-e4b1c91df18c", + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import pandas as pd\n", + "\n", + "from utils import PROCESSED_GCS\n", + "from shared_utils.shared_data import GCS_FILE_PATH as SHARED_GCS\n", + "\n", + "from stations_with_shn_postmiles import postmiles_to_pems_format" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "594d299f-8bb7-4d56-aae0-9b2b32c73590", + "metadata": {}, + "outputs": [], + "source": [ + "postmile_segments = gpd.read_parquet(\n", + " f\"{SHARED_GCS}state_highway_network_postmile_segments.parquet\",\n", + ").pipe(postmiles_to_pems_format)\n", + "\n", + "metric = \"flow\"\n", + "df = pd.read_parquet(\n", + " f\"{PROCESSED_GCS}station_daytype_hour_{metric}.parquet\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4cd454dd-9dc0-4621-b7e8-20d7bddf268e", + "metadata": {}, + "outputs": [], + "source": [ + "merge_cols = [\"freeway_id\", \"freeway_direction\", \"abs_pm\"]\n", + "\n", + "station_postmiles_crosswalk = pd.read_parquet(\n", + " f\"{PROCESSED_GCS}stations_postmiles_crosswalk.parquet\",\n", + " columns = [\n", + " \"station_uuid\", \"routetype\", \n", + " \"city_id\", \"county_id\", \"district_id\", \n", + " \"station_type\", \"length\", \"physical_lanes\"\n", + " ] + merge_cols\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "06dd0fc4-9734-44bf-aef4-489b1650fcc9", + "metadata": {}, + "outputs": [], + "source": [ + "df2 = df.groupby(\"station_uuid\").agg({\"tot_flow\": \"sum\"}).reset_index()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e95efcd9-3d5b-4cc1-9916-4a37f733a4d3", + "metadata": {}, + "outputs": [], + "source": [ + "gdf = pd.merge(\n", + " postmile_segments,\n", + " station_postmiles_crosswalk,\n", + " on = merge_cols,\n", + " how = \"inner\",\n", + ").merge(\n", + " df2,\n", + " on = \"station_uuid\",\n", + " how = \"inner\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "ee6f5485-b400-4f83-9082-4dffc02a6055", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4465, 15)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "5de36822-e711-43b4-b3a7-4b874e405835", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4344, 11)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "station_postmiles_crosswalk.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "cf43c84c-9b88-44fa-8a9b-8bb682e1cb14", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4242, 2)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df2.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "486b91fe-61e2-4cef-90bd-0c17bf41f740", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12 1096\n", + "8 1032\n", + "7 773\n", + "4 732\n", + "3 681\n", + "11 130\n", + "5 17\n", + "10 4\n", + "Name: district_id, dtype: int64" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gdf.district_id.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "bdaf20fe-d8e7-40f6-85cc-7610904310cc", + "metadata": {}, + "outputs": [], + "source": [ + "def make_map(gdf, district):\n", + " return gdf[gdf.district_id==district].explore(\n", + " \"tot_flow\", tiles=\"CartoDB Positron\"\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "1721342e-4bfc-4930-8b9b-89abe01fce0d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 4)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a079c936-69a4-468a-9075-4427865a40f7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 7)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "675eed8e-87d5-42b1-a061-6158469759fb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "dcbd8800-f454-459d-8b08-1fe721026d69", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 8)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "fad6a764-b790-480e-bb73-4576d35cd2d1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "4d8e1c8e-9132-4947-ad78-933504a15e7e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 11)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "86a3cbb7-7128-415d-915e-4e9d327f030b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "make_map(gdf, 12)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74642e69-caf7-4ddc-ac02-789e9d0e17dd", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/traffic_ops/Makefile b/traffic_ops/Makefile new file mode 100644 index 000000000..663288692 --- /dev/null +++ b/traffic_ops/Makefile @@ -0,0 +1,8 @@ +pems_crosswalks: + python crosswalks.py + python stations_with_shn_postmiles.py + +process_pems: + #python import_data.py + #make pems_crosswalks + python aggregate.py \ No newline at end of file