{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bird flu in China, 2013: an epicurve\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/h7n9-china-2013.ipynb)\n", "\n", "In spring 2013, a new bird flu virus, influenza A(H7N9), began infecting people\n", "in eastern China. Most people who fell ill had been in contact with live poultry,\n", "often at markets. This case study draws an **epidemic curve** (epicurve) of the\n", "first wave, using a public line list of 136 cases.\n", "\n", "An epicurve answers the first questions about any outbreak: *when did people\n", "fall ill, and how many?* Its shape gives clues about how the disease is spreading\n", "and whether control measures are working." ], "id": "cell-00" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set up\n", "\n", "If you are running this notebook in Google Colab, the next cell installs\n", "**epiplot** 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." ], "id": "cell-01" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "if \"google.colab\" in sys.modules:\n", " %pip install --quiet epiplot" ], "id": "cell-02" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "\n", "import epiplot" ], "id": "cell-03" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load the line list\n", "\n", "A **line list** has one row per case. This one was collated by Kucharski and\n", "colleagues from WHO reports, ProMED, FluTrackers and news reports. Our copy keeps\n", "only the columns needed here: see the data notes at the end." ], "id": "cell-04" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "DATA = Path(\"data/h7n9_china_2013.csv\")\n", "if not DATA.exists(): # for example in Colab: read the copy on GitHub instead\n", " DATA = (\n", " \"https://raw.githubusercontent.com/leehart3000/epiplot/main/\"\n", " \"docs/case-studies/data/h7n9_china_2013.csv\"\n", " )\n", "\n", "cases = pd.read_csv(DATA)\n", "cases.head()" ], "id": "cell-05" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Real data are rarely complete. It is worth checking how many values are missing\n", "before plotting:" ], "id": "cell-06" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cases.isna().sum()" ], "id": "cell-07" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ten cases have no date of symptom onset. They can't be placed on the curve, but\n", "they shouldn't silently disappear either: **epiplot** will say how many were left\n", "out, under the plot.\n", "\n", "Most cases were in three places: the provinces of Zhejiang and Jiangsu, and the\n", "city of Shanghai (which is counted as a province here)." ], "id": "cell-08" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cases[\"province\"].value_counts().head(6)" ], "id": "cell-09" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Group the provinces\n", "\n", "Colours are easiest to tell apart when there are only a few. So we keep the three\n", "most affected areas and combine the rest as \"Other\". Making the groups a\n", "*categorical* column fixes their order: the first group sits at the bottom of each\n", "bar, on the flat baseline, where its rise and fall is easiest to read." ], "id": "cell-10" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "top3 = [\"Zhejiang\", \"Shanghai\", \"Jiangsu\"]\n", "cases[\"province_group\"] = pd.Categorical(\n", " cases[\"province\"].where(cases[\"province\"].isin(top3), \"Other\"),\n", " categories=[*top3, \"Other\"],\n", ")" ], "id": "cell-11" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Draw the epicurve" ], "id": "cell-12" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = epiplot.epicurve(\n", " cases,\n", " \"onset_date\",\n", " date_type=\"onset\",\n", " group_col=\"province_group\",\n", ")\n", "ax.set_title(\"Human cases of influenza A(H7N9), China, 2013\")\n", "plt.show()" ], "id": "cell-13" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What the curve shows\n", "\n", "- **A sharp spring wave.** Cases rose quickly through March, peaked in the week\n", " starting 8 April, then fell away by early May.\n", "- **The decline came soon after action at the source.** In early April, several\n", " affected cities closed their live poultry markets. A later study estimated\n", " that these closures greatly reduced the risk of infection (Yu et al., 2014).\n", " An epicurve alone can't prove cause and effect, but it is where such questions\n", " start.\n", "- **A few later cases.** Scattered cases in May and July show the virus had not\n", " gone away, which matched what happened next: H7N9 returned in later winters.\n", "\n", "## Good practice, built in\n", "\n", "Notice what **epiplot** did without being asked:\n", "\n", "- **The x axis says what the dates mean:** \"Week of symptom onset\". Onset and\n", " report dates tell different stories, so the axis label must say which is used.\n", "- **Empty weeks are shown as gaps at zero,** so the quiet weeks between the main\n", " wave and the later cases stay visible.\n", "- **The 10 cases without an onset date are reported** under the plot, rather than\n", " quietly dropped.\n", "- **Colours are colour-blind-safe,** and the week start (Monday) is stated.\n", "\n", "## Try it yourself\n", "\n", "- Group by `outcome` instead of province, to see whether deaths cluster in time.\n", "- Use `interval=\"day\"` to see the same outbreak in more detail.\n", "- Call `epiplot.count_cases(...)` with the same options to get the numbers behind\n", " the plot as a table.\n", "\n", "## Data source and licence\n", "\n", "Kucharski A, Mills HL, Pinsent A, Fraser C, Van Kerkhove M, Donnelly CA, Riley S\n", "(2015). Data from: Distinguishing between reservoir exposure and human-to-human\n", "transmission for emerging pathogens using case onset data. Dryad.\n", ". Released under CC0 1.0.\n", "\n", "Our copy keeps only the case ID, sex, province, onset date and outcome. Free-text\n", "notes, ages and other details about individual patients were left out. The\n", "script that made our copy, and notes on every change, are in the\n", "[data folder on GitHub](https://github.com/leehart3000/epiplot/tree/main/docs/case-studies/data).\n", "\n", "Yu H, Wu JT, Cowling BJ, et al. (2014). Effect of closure of live poultry markets\n", "on poultry-to-person transmission of avian influenza A H7N9 virus: an ecological\n", "study. *The Lancet* 383(9916): 541–548." ], "id": "cell-14" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }