{ "cells": [ { "cell_type": "markdown", "id": "cell-00", "metadata": {}, "source": [ "# COVID-19 in England, winter 2020–21: rate maps\n", "\n", "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/leehart3000/epiplot/blob/main/docs/case-studies/covid-england-2020-21.ipynb)\n", "\n", "In the winter of 2020–21, England had its largest wave of COVID-19 cases up to\n", "that point. A new variant, later named Alpha, had been first detected in Kent in\n", "the autumn. Over the following weeks it spread from the south-east across the\n", "whole country.\n", "\n", "This case study maps that wave by local authority, using real case counts and\n", "populations. A **rate map** shades each area by its rate of cases per 100,000\n", "people, so places with very different populations can be compared fairly." ] }, { "cell_type": "markdown", "id": "cell-01", "metadata": {}, "source": [ "## Set up\n", "\n", "If you are running this notebook in Google Colab, the next cell installs\n", "**epiplot** with its map libraries first. Elsewhere it does nothing.\n", "\n", "Colab will warn that the notebook was not authored by Google. It shows this for any\n", "notebook opened from GitHub. This one only installs **epiplot** and reads public data\n", "files: it does not ask for access to your Google account or data." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-02", "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "if \"google.colab\" in sys.modules:\n", " %pip install --quiet \"epiplot[maps]>=0.5\"" ] }, { "cell_type": "code", "execution_count": null, "id": "cell-03", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import geopandas\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "\n", "import epiplot" ] }, { "cell_type": "markdown", "id": "cell-04", "metadata": {}, "source": [ "## Load the data\n", "\n", "There are two files, prepared from public UKHSA and ONS data (see the notes at\n", "the end):\n", "\n", "- **Cases and populations:** one row per local authority per period, with the\n", " number of new cases (by date the test sample was taken) and the mid-2020\n", " population.\n", "- **Boundaries:** the shape of each local authority, as at December 2020." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-05", "metadata": {}, "outputs": [], "source": [ "FOLDER = Path(\"data\")\n", "if not FOLDER.exists(): # for example in Colab: read the copies on GitHub instead\n", " FOLDER = (\n", " \"https://raw.githubusercontent.com/leehart3000/epiplot/main/\"\n", " \"docs/case-studies/data\"\n", " )\n", "\n", "data = pd.read_csv(f\"{FOLDER}/covid_england_2020_21.csv\")\n", "regions = geopandas.read_file(f\"{FOLDER}/england_lad_2020.geojson\")\n", "data.head()" ] }, { "cell_type": "markdown", "id": "cell-06", "metadata": {}, "source": [ "## Equal periods, so rates compare fairly\n", "\n", "A rate depends on how long you count for: twice as many days gives roughly twice\n", "as many cases. Calendar months would be a trap here, because February 2021 had\n", "28 days and January 31, so February would look about 10% lower for no real\n", "reason.\n", "\n", "So the data use **four equal 28-day periods**, each starting on a Monday, and the\n", "maps say so: `counted_over=\"28 days\"` adds the period to the colour scale label,\n", "because a rate without its time window is ambiguous. Making\n", "the period column *categorical*, in date order, keeps the maps in time order\n", "rather than alphabetical order." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-07", "metadata": {}, "outputs": [], "source": [ "periods = data.drop_duplicates(\"period\").sort_values(\"period_start\")[\"period\"]\n", "data[\"period\"] = pd.Categorical(data[\"period\"], categories=periods)\n", "list(data[\"period\"].cat.categories)" ] }, { "cell_type": "markdown", "id": "cell-08", "metadata": {}, "source": [ "## Use a map projection that keeps areas fair\n", "\n", "The boundary file stores positions as longitude and latitude. Drawn directly,\n", "that stretches England sideways and distorts the size of each area, which\n", "matters on a map where the eye reads large shaded areas as \"a lot\". **epiplot**\n", "warns if you forget. Converting to the British National Grid (EPSG:27700), the\n", "standard projection for Great Britain, fixes it." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-09", "metadata": {}, "outputs": [], "source": [ "regions = regions.to_crs(27700)" ] }, { "cell_type": "markdown", "id": "cell-10", "metadata": {}, "source": [ "## One period: the peak\n", "\n", "Before looking at the whole winter, here is a single map of the busiest period." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-11", "metadata": {}, "outputs": [], "source": [ "peak = data[data[\"period\"] == \"28 Dec – 24 Jan\"]\n", "ax = epiplot.rate_map(\n", " regions,\n", " peak,\n", " \"area_code\",\n", " cases_col=\"cases\",\n", " population_col=\"population\",\n", " counted_over=\"28 days\",\n", ")\n", "ax.set_title(\"COVID-19 cases, England, 28 Dec 2020 – 24 Jan 2021\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "cell-12", "metadata": {}, "source": [ "Small areas, such as the London boroughs, are hard to see on a map of the whole\n", "country. A table of the highest rates fills in the detail, with exact 95%\n", "confidence intervals:" ] }, { "cell_type": "code", "execution_count": null, "id": "cell-13", "metadata": {}, "outputs": [], "source": [ "rates = epiplot.calculate_rates(peak, \"area_code\", \"cases\", \"population\")\n", "rates = rates.merge(peak[[\"area_code\", \"area_name\"]], on=\"area_code\")\n", "top = rates.sort_values(\"rate\", ascending=False).head(10)\n", "top[[\"area_name\", \"cases\", \"population\", \"rate\", \"rate_lower\", \"rate_upper\"]].round(0)" ] }, { "cell_type": "markdown", "id": "cell-14", "metadata": {}, "source": [ "## The whole winter: a timeline\n", "\n", "Four small maps, one per period, all sharing **one colour scale**: the same\n", "shade means the same rate in every map, so the maps can be compared directly." ] }, { "cell_type": "code", "execution_count": null, "id": "cell-15", "metadata": {}, "outputs": [], "source": [ "figure = epiplot.rate_map_timeline(\n", " regions,\n", " data,\n", " \"area_code\",\n", " \"period\",\n", " cases_col=\"cases\",\n", " population_col=\"population\",\n", " ncols=4,\n", " counted_over=\"28 days\",\n", ")\n", "figure.suptitle(\"COVID-19 cases, England, winter 2020–21\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "cell-16", "metadata": {}, "source": [ "## What the maps show\n", "\n", "- **2–29 November:** during England's second national lockdown, the highest\n", " rates were in the north, in parts of Lancashire, Yorkshire and the Humber.\n", "- **30 November – 27 December:** the north eased, but rates climbed sharply in\n", " Kent, Essex and east London, where the Alpha variant was spreading fastest.\n", " London and much of the south-east moved into the new, strictest \"Tier 4\" on\n", " 20 December.\n", "- **28 December – 24 January:** the peak. High rates spread across almost the\n", " whole country. A third national lockdown began on 6 January.\n", "- **25 January – 21 February:** rates fell everywhere.\n", "\n", "Maps like these show *where* and *when*, not *why*. Rates also depend on how\n", "much testing was done, which varied between places and over time.\n", "\n", "## Good practice, built in\n", "\n", "- **Rates, not counts.** Raw case counts mostly show where people live. Rates\n", " per 100,000 people allow fair comparison between areas of very different\n", " size. The colour bar says they are *crude* rates, not adjusted for age.\n", "- **The rate says what it covers:** \"Crude rate per 100,000 people over 28 days\".\n", " **epiplot** can't know how long the cases were counted over, so it asks.\n", "- **One colour scale for all four maps,** starting at zero, in a single colour\n", " that gets darker as the rate rises.\n", "- **Small numbers would be hidden.** Areas with fewer than 5 cases in a period\n", " would be shaded as \"hidden\", because such rates are unreliable and could\n", " identify individuals. This winter, every area had more than that.\n", "- **Missing data would be shown differently from zero,** so a gap in reporting\n", " is never mistaken for an absence of disease.\n", "\n", "## Try it yourself\n", "\n", "- Use `bands=5` to show the rates in five colour bands instead of a smooth\n", " scale.\n", "- Draw `rate_map` for another period, such as `\"30 Nov – 27 Dec\"`.\n", "- Sort the `rates` table the other way, to find the areas with the lowest rates.\n", "\n", "## Data sources and licences\n", "\n", "- **Cases:** UKHSA COVID-19 archive data, new cases by specimen date for each\n", " lower-tier local authority.\n", " .\n", " Contains public sector information licensed under the Open Government\n", " Licence v3.0.\n", "- **Boundaries:** ONS, Local Authority Districts (December 2020) Boundaries UK\n", " BUC. Source: Office for National Statistics licensed under the Open\n", " Government Licence v3.0. Contains OS data © Crown copyright and database\n", " right 2020.\n", "- **Population:** ONS mid-2020 population estimates. Source: Office for\n", " National Statistics licensed under the Open Government Licence v3.0.\n", "\n", "To match the three sources, the Isles of Scilly are joined with Cornwall and the\n", "City of London with Hackney (UKHSA reported their cases together), and the four\n", "former Buckinghamshire districts are combined. The script that prepared the\n", "data, with notes on every change, is in the\n", "[data folder on GitHub](https://github.com/leehart3000/epiplot/tree/main/docs/case-studies/data)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }