{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# PAM Read-Modify-Write\n", "\n", "This notebook is an introduction to the basic read - modify - write use case of PAM:\n", "\n", "- Read: Load activity plans from existing data (either tabular or MATSim)\n", "- Modify: Use the PAM api to modify the activity plans\n", "- Write: Write activity plans back to disk in the chosen format\n", "\n", "For this example, we use policies to make our modifications. But you might also try the following:\n", "\n", "- spatial sampling\n", "- location modelling\n", "- rescheduling\n", "- adding noise\n", "- simulating aging or the passing of time\n", "- and so on..." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-05-18T14:31:06.631005Z", "start_time": "2020-05-18T14:31:06.133057Z" }, "execution": { "iopub.execute_input": "2024-04-05T15:21:36.418420Z", "iopub.status.busy": "2024-04-05T15:21:36.417935Z", "iopub.status.idle": "2024-04-05T15:21:38.530106Z", "shell.execute_reply": "2024-04-05T15:21:38.529504Z" } }, "outputs": [], "source": [ "import os\n", "from collections import defaultdict\n", "\n", "import geopandas as gp\n", "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "from pam import policy, read\n", "from pam.policy import apply_policies\n", "\n", "%matplotlib inline" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load Data\n", "\n", "Here we load simple travel diary data of London commuters. This is a very simple 0.1% sample of data about work and education commutes from the 2011 census. \n", "Because we're sharing this data, we've aggregated locations to borough level and randomized personal attributes; so, don't get too excited about the results.\n", "\n", "The data is available in the [`data/example_data`](https://github.com/arup-group/pam/tree/main/examples/data/example_data) sub-directory.\n", "All data paths in this example are relative to the [notebook directory](https://github.com/arup-group/pam/tree/main/examples) in the PAM repository " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-05-18T13:40:08.588305Z", "start_time": "2020-05-18T13:40:08.557000Z" }, "execution": { "iopub.execute_input": "2024-04-05T15:21:38.532837Z", "iopub.status.busy": "2024-04-05T15:21:38.532576Z", "iopub.status.idle": "2024-04-05T15:21:38.619211Z", "shell.execute_reply": "2024-04-05T15:21:38.618134Z" } }, "outputs": [], "source": [ "trips = pd.read_csv(\n", " os.path.join(\"data\", \"example_data\", \"example_travel_diaries.csv\"), index_col=\"uid\"\n", ")\n", "attributes = pd.read_csv(\n", " os.path.join(\"data\", \"example_data\", \"example_attributes.csv\"), index_col=\"pid\"\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-05-18T13:40:08.625157Z", "start_time": "2020-05-18T13:40:08.591798Z" }, "execution": { "iopub.execute_input": "2024-04-05T15:21:38.626470Z", "iopub.status.busy": "2024-04-05T15:21:38.625883Z", "iopub.status.idle": "2024-04-05T15:21:38.736562Z", "shell.execute_reply": "2024-04-05T15:21:38.733915Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " | pid | \n", "hid | \n", "seq | \n", "hzone | \n", "ozone | \n", "dzone | \n", "purp | \n", "mode | \n", "tst | \n", "tet | \n", "freq | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
uid | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
0 | \n", "census_0 | \n", "census_0 | \n", "0 | \n", "Harrow | \n", "Harrow | \n", "Camden | \n", "work | \n", "pt | \n", "444 | \n", "473 | \n", "1000 | \n", "
1 | \n", "census_0 | \n", "census_0 | \n", "1 | \n", "Harrow | \n", "Camden | \n", "Harrow | \n", "work | \n", "pt | \n", "890 | \n", "919 | \n", "1000 | \n", "
2 | \n", "census_1 | \n", "census_1 | \n", "0 | \n", "Greenwich | \n", "Greenwich | \n", "Tower Hamlets | \n", "work | \n", "pt | \n", "507 | \n", "528 | \n", "1000 | \n", "
3 | \n", "census_1 | \n", "census_1 | \n", "1 | \n", "Greenwich | \n", "Tower Hamlets | \n", "Greenwich | \n", "work | \n", "pt | \n", "1065 | \n", "1086 | \n", "1000 | \n", "
4 | \n", "census_2 | \n", "census_2 | \n", "0 | \n", "Croydon | \n", "Croydon | \n", "Croydon | \n", "work | \n", "pt | \n", "422 | \n", "425 | \n", "1000 | \n", "
5 | \n", "census_2 | \n", "census_2 | \n", "1 | \n", "Croydon | \n", "Croydon | \n", "Croydon | \n", "work | \n", "pt | \n", "917 | \n", "920 | \n", "1000 | \n", "
6 | \n", "census_3 | \n", "census_3 | \n", "0 | \n", "Haringey | \n", "Haringey | \n", "Redbridge | \n", "work | \n", "pt | \n", "428 | \n", "447 | \n", "1000 | \n", "
7 | \n", "census_3 | \n", "census_3 | \n", "1 | \n", "Haringey | \n", "Redbridge | \n", "Haringey | \n", "work | \n", "pt | \n", "1007 | \n", "1026 | \n", "1000 | \n", "
8 | \n", "census_4 | \n", "census_4 | \n", "0 | \n", "Hounslow | \n", "Hounslow | \n", "Westminster,City of London | \n", "work | \n", "car | \n", "483 | \n", "516 | \n", "1000 | \n", "
9 | \n", "census_4 | \n", "census_4 | \n", "1 | \n", "Hounslow | \n", "Westminster,City of London | \n", "Hounslow | \n", "work | \n", "car | \n", "1017 | \n", "1050 | \n", "1000 | \n", "