{ "cells": [ { "cell_type": "markdown", "id": "3aef6311", "metadata": {}, "source": [ "# Service provision\n", "\n", "`get_service_provision` allocates the demand of buildings to services with limited capacity, given a matrix of\n", "travel costs and a normative threshold. This notebook\n", "\n", "1. computes provision with a 10-minute threshold on a precomputed intermodal travel-time matrix;\n", "2. maps the provision value and service load;\n", "3. removes links longer than 8 minutes with `recalculate_links` and clips the result to a subarea;\n", "4. repeats the calculation with a pandas sparse matrix.\n", "\n", "The matrix in `examples_data/matrix_time.parquet` was computed with IduEdu\n", "([calculate_od_matrix](calculate_od_matrix.ipynb)); unreachable pairs are `inf`.\n", "\n", "The last section, *Your own area*, shows what to replace to get the same pictures for another territory." ] }, { "cell_type": "code", "execution_count": 1, "id": "3377c405", "metadata": { "execution": { "iopub.execute_input": "2026-11-06T16:16:26.527587Z", "iopub.status.busy": "2026-11-06T16:16:26.527587Z", "iopub.status.idle": "2026-11-06T16:16:26.530843Z", "shell.execute_reply": "2026-11-06T16:16:26.530843Z" } }, "outputs": [], "source": [ "# !pip install objectnat pyarrow matplotlib" ] }, { "cell_type": "code", "execution_count": 2, "id": "ef790601", "metadata": { "execution": { "iopub.execute_input": "2026-11-06T16:16:26.531855Z", "iopub.status.busy": "2026-11-06T16:16:26.531855Z", "iopub.status.idle": "2026-11-06T16:16:29.699788Z", "shell.execute_reply": "2026-11-06T16:16:29.699788Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4101 buildings (demand 29596), 36 services (capacity 31142), matrix (4101, 36)\n" ] } ], "source": [ "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from objectnat import (\n", " clip_provision,\n", " get_provision_buildings,\n", " get_provision_links,\n", " get_provision_services,\n", " get_service_provision,\n", " recalculate_links,\n", ")\n", "\n", "buildings = gpd.read_parquet(\"examples_data/buildings.parquet\")\n", "services = gpd.read_parquet(\"examples_data/services.parquet\")\n", "matrix = pd.read_parquet(\"examples_data/matrix_time.parquet\") # minutes, rows: buildings, columns: services\n", "print(f\"{len(buildings)} buildings (demand {buildings['demand'].sum()}), \"\n", " f\"{len(services)} services (capacity {services['capacity'].sum()}), matrix {matrix.shape}\")" ] }, { "cell_type": "markdown", "id": "db6123a9", "metadata": {}, "source": [ "## 1. Provision within 10 minutes\n", "\n", "The result is a `ProvisionResult`: a sparse `flow` matrix of allocated demand and the tables `demand_rows` and\n", "`capacity_rows`. A fixed `seed` makes the allocation reproducible." ] }, { "cell_type": "code", "execution_count": 3, "id": "7a661415", "metadata": { "execution": { "iopub.execute_input": "2026-11-06T16:16:29.701800Z", "iopub.status.busy": "2026-11-06T16:16:29.701800Z", "iopub.status.idle": "2026-11-06T16:16:29.747504Z", "shell.execute_reply": "2026-11-06T16:16:29.747000Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "supplied within 10 min: 61.7%, beyond: 33.4%, left: 4.9%\n" ] }, { "data": { "text/html": [ "
| \n", " | capacity | \n", "capacity_left | \n", "carried_capacity_within | \n", "carried_capacity_without | \n", "service_load | \n", "
|---|---|---|---|---|---|
| count | \n", "36.0 | \n", "36.0 | \n", "36.0 | \n", "36.0 | \n", "36.0 | \n", "
| mean | \n", "865.1 | \n", "83.3 | \n", "507.0 | \n", "274.7 | \n", "781.8 | \n", "
| std | \n", "487.1 | \n", "110.6 | \n", "319.9 | \n", "320.0 | \n", "434.1 | \n", "
| min | \n", "120.0 | \n", "0.0 | \n", "61.0 | \n", "2.0 | \n", "100.0 | \n", "
| 25% | \n", "550.8 | \n", "13.8 | \n", "242.5 | \n", "42.2 | \n", "457.0 | \n", "
| 50% | \n", "960.0 | \n", "36.0 | \n", "493.0 | \n", "185.0 | \n", "805.5 | \n", "
| 75% | \n", "1200.0 | \n", "113.0 | \n", "725.2 | \n", "398.0 | \n", "1138.2 | \n", "
| max | \n", "2161.0 | \n", "457.0 | \n", "1145.0 | \n", "1402.0 | \n", "1756.0 | \n", "