From b8bcc7f806c9e99c6318c44f36bd416fcd3aa49d Mon Sep 17 00:00:00 2001 From: Hussein Mahfouz <45176416+Hussein-Mahfouz@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:26:14 +0100 Subject: [PATCH] start on primary locations notebook --- notebooks/3_locations_primary.ipynb | 1306 ++++++++++++++++++++++++++- 1 file changed, 1303 insertions(+), 3 deletions(-) diff --git a/notebooks/3_locations_primary.ipynb b/notebooks/3_locations_primary.ipynb index 709d82c..3c6a9e8 100644 --- a/notebooks/3_locations_primary.ipynb +++ b/notebooks/3_locations_primary.ipynb @@ -1,16 +1,1316 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Adding Primary Location to individuals\n", + "\n", + "After assigning an activity chain to each individual, we then need to map these activities to geographic locations. We start with primary locations (work, school) and fill in the gaps later with discretionary locations. This notebook will focus on the primary locations.\n", + "\n", + "We follow the steps outlined in this [github issue](https://github.com/Urban-Analytics-Technology-Platform/acbm/issues/12)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "import seaborn as sns" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Explore trip from and trip to for all individual activities" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " | id | \n", + "household | \n", + "location | \n", + "pid_hs | \n", + "msoa | \n", + "oa | \n", + "members | \n", + "sic1d2007 | \n", + "sic2d2007 | \n", + "pwkstat | \n", + "... | \n", + "TripStart | \n", + "TripEnd | \n", + "TripDisIncSW | \n", + "TripDisExSW | \n", + "TripTotalTime | \n", + "TripTravTime | \n", + "TripOrigGOR_B02ID | \n", + "TripDestGOR_B02ID | \n", + "W5 | \n", + "W5xHH | \n", + "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "1005.0 | \n", + "1020.0 | \n", + "5.0 | \n", + "5.0 | \n", + "15.0 | \n", + "15.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
1 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "1030.0 | \n", + "1050.0 | \n", + "9.0 | \n", + "9.0 | \n", + "20.0 | \n", + "20.0 | \n", + "9.0 | \n", + "8.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
2 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "1215.0 | \n", + "1235.0 | \n", + "9.0 | \n", + "9.0 | \n", + "20.0 | \n", + "20.0 | \n", + "8.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
3 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "1240.0 | \n", + "1255.0 | \n", + "5.0 | \n", + "5.0 | \n", + "15.0 | \n", + "15.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
4 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "720.0 | \n", + "730.0 | \n", + "2.0 | \n", + "2.0 | \n", + "10.0 | \n", + "10.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.869370 | \n", + "1.204273 | \n", + "
5 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "735.0 | \n", + "745.0 | \n", + "3.0 | \n", + "3.0 | \n", + "10.0 | \n", + "10.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
6 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "825.0 | \n", + "830.0 | \n", + "1.0 | \n", + "1.0 | \n", + "5.0 | \n", + "5.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
7 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "900.0 | \n", + "905.0 | \n", + "1.0 | \n", + "1.0 | \n", + "5.0 | \n", + "5.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
8 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "1065.0 | \n", + "1070.0 | \n", + "1.0 | \n", + "1.0 | \n", + "5.0 | \n", + "5.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.721904 | \n", + "1.000000 | \n", + "
9 | \n", + "0 | \n", + "0 | \n", + "{'x': -1.7892179489135742, 'y': 53.91915130615... | \n", + "2905399 | \n", + "E02002183 | \n", + "E00053954 | \n", + "[0] | \n", + "J | \n", + "58.0 | \n", + "6 | \n", + "... | \n", + "690.0 | \n", + "700.0 | \n", + "3.0 | \n", + "3.0 | \n", + "10.0 | \n", + "10.0 | \n", + "9.0 | \n", + "9.0 | \n", + "0.812293 | \n", + "1.125208 | \n", + "
10 rows × 70 columns
\n", + "\n", + " | from_id | \n", + "to_id | \n", + "combination | \n", + "routes | \n", + "departure_time | \n", + "access_time | \n", + "wait_time | \n", + "ride_time | \n", + "transfer_time | \n", + "egress_time | \n", + "total_time | \n", + "n_rides | \n", + "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", + "156993 | \n", + "156993 | \n", + "pt_wkday_afternoon | \n", + "[WALK] | \n", + "12:30:00 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.5 | \n", + "0.0 | \n", + "
1 | \n", + "156993 | \n", + "156993 | \n", + "pt_wkday_evening | \n", + "[WALK] | \n", + "18:30:00 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.5 | \n", + "0.0 | \n", + "
2 | \n", + "156993 | \n", + "156993 | \n", + "pt_wkday_morning | \n", + "[WALK] | \n", + "07:30:00 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.5 | \n", + "0.0 | \n", + "
3 | \n", + "156993 | \n", + "156993 | \n", + "pt_wkday_night | \n", + "[WALK] | \n", + "23:30:00 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.5 | \n", + "0.0 | \n", + "
4 | \n", + "156993 | \n", + "156993 | \n", + "pt_wkend_evening | \n", + "[WALK] | \n", + "18:30:00 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.0 | \n", + "0.5 | \n", + "0.0 | \n", + "
... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "... | \n", + "
95 | \n", + "156993 | \n", + "157015 | \n", + "pt_wkday_afternoon | \n", + "30533|12594|12522 | \n", + "12:30:00 | \n", + "2.9 | \n", + "17.3 | \n", + "32.6 | \n", + "10.2 | \n", + "3.2 | \n", + "66.2 | \n", + "3.0 | \n", + "
96 | \n", + "156993 | \n", + "157015 | \n", + "pt_wkday_evening | \n", + "30533|12657 | \n", + "18:30:00 | \n", + "2.9 | \n", + "12.9 | \n", + "49.0 | \n", + "2.3 | \n", + "5.5 | \n", + "72.6 | \n", + "2.0 | \n", + "
97 | \n", + "156993 | \n", + "157015 | \n", + "pt_wkday_morning | \n", + "30533|12594|12522 | \n", + "07:30:00 | \n", + "2.9 | \n", + "16.7 | \n", + "37.1 | \n", + "10.2 | \n", + "3.2 | \n", + "70.1 | \n", + "3.0 | \n", + "
98 | \n", + "156993 | \n", + "157015 | \n", + "pt_wkend_evening | \n", + "54718|12657 | \n", + "18:30:00 | \n", + "3.8 | \n", + "34.3 | \n", + "43.3 | \n", + "2.1 | \n", + "5.5 | \n", + "89.0 | \n", + "2.0 | \n", + "
99 | \n", + "156993 | \n", + "157015 | \n", + "pt_wkend_morning | \n", + "30533|12522 | \n", + "07:30:00 | \n", + "2.9 | \n", + "49.8 | \n", + "40.4 | \n", + "1.9 | \n", + "5.5 | \n", + "100.5 | \n", + "2.0 | \n", + "
100 rows × 12 columns
\n", + "\n", + " | OBJECTID | \n", + "OA21CD | \n", + "GlobalID | \n", + "LSOA21CD | \n", + "LSOA21NM | \n", + "MSOA21CD | \n", + "MSOA21NM | \n", + "LEP22CD1 | \n", + "LEP22NM1 | \n", + "LAD22CD | \n", + "LAD22NM | \n", + "rgn22cd | \n", + "rgn22nm | \n", + "ctry22cd | \n", + "ctry22nm | \n", + "geometry | \n", + "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", + "1 | \n", + "E00000001 | \n", + "bc5eb21b-d42b-4715-a771-2c27575a08f0 | \n", + "E01000001 | \n", + "City of London 001A | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532303.492 181814.110, 532213.... | \n", + "
1 | \n", + "2 | \n", + "E00000003 | \n", + "a1a2b34f-320e-4bb8-acb4-7ca7ca16ef9c | \n", + "E01000001 | \n", + "City of London 001A | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532213.378 181846.192, 532190.... | \n", + "
2 | \n", + "3 | \n", + "E00000005 | \n", + "9337da1a-fe0f-4210-9c95-ed2d20fd6287 | \n", + "E01000001 | \n", + "City of London 001A | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532180.131 181763.020, 532219.... | \n", + "
3 | \n", + "4 | \n", + "E00000007 | \n", + "b336e11f-af26-48a6-ac67-44f5b8b8840a | \n", + "E01000001 | \n", + "City of London 001A | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532201.292 181668.180, 532267.... | \n", + "
4 | \n", + "5 | \n", + "E00000010 | \n", + "ca8f9874-cdf5-4c1a-9d39-f74a410dae44 | \n", + "E01000003 | \n", + "City of London 001C | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532127.958 182133.192, 532089.... | \n", + "
5 | \n", + "6 | \n", + "E00000013 | \n", + "b9b93246-bbfb-46af-8011-6b8ed5908956 | \n", + "E01000003 | \n", + "City of London 001C | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532247.654 181897.577, 532248.... | \n", + "
6 | \n", + "7 | \n", + "E00000018 | \n", + "fcb7c232-4165-44da-8ff8-b6cc383b528a | \n", + "E01000002 | \n", + "City of London 001B | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532440.197 181842.934, 532544.... | \n", + "
7 | \n", + "8 | \n", + "E00000019 | \n", + "715e0851-2375-4d6a-94ac-532ba0833c60 | \n", + "E01000002 | \n", + "City of London 001B | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532619.141 181847.188, 532603.... | \n", + "
8 | \n", + "9 | \n", + "E00000020 | \n", + "4251a2ff-8fbe-4c11-aece-044f23ab9af2 | \n", + "E01000002 | \n", + "City of London 001B | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532515.000 181686.981, 532544.... | \n", + "
9 | \n", + "10 | \n", + "E00000021 | \n", + "48b2df49-45ed-48a4-b7fc-e0e32c1ad088 | \n", + "E01000002 | \n", + "City of London 001B | \n", + "E02000001 | \n", + "City of London 001 | \n", + "E37000051 | \n", + "The London Economic Action Partnership | \n", + "E09000001 | \n", + "City of London | \n", + "E12000007 | \n", + "London | \n", + "E92000001 | \n", + "England | \n", + "MULTIPOLYGON (((532746.813 181786.891, 532671.... | \n", + "