Skip to main content

Pyncov-19 is a tiny probabilistic simulator for SARS-CoV-2

Project description

Pyncov-19: Learn and predict the spread of COVID-19

Open In Colab

Pyncov-19 is a tiny probabilistic simulator for SARS-CoV-2 implemented in Python 3, whose only dependency is Numpy 1.18. This simulator is used to learn and predict the temporal dynamics of COVID-19 that are shown in https://covid19-modeling.github.io. It implements a probabilistic compartmental model at the individual level using a Markov Chain model with temporal transitions that were adjusted using the most recent scientific evidence.

Quick Start

Basic installation using pip with minimal dependencies:

pip install pyncov

In order to install pyncov with the additional features (progress bar, plotting) use:

pip install pyncov[all]

Sampling 100 simulated trajectories of the SARS-CoV-2 spread in Madrid:

import pyncov as nc
import pyncov.io
# Requires pandas
import pyncov.plot

susceptible = 6680000
infected = 1
num_days = 80

infection_rates = nc.infection_rates(nc.io.get_trained_params('ESP-MD'), num_days=60)
# Instantiate the model with the default parameters and sample 100 chains
# NOTE: show_progress requires the TQDM library not installed by default.
m = nc.build_markovchain(nc.MARKOV_DEFAULT_PARAMS)
simulations = nc.sample_chains(susceptible, infected, m, infection_rates, 
                               num_chains=100, show_progress=True)

You can visualizate the trajectories and the average trajectory matching the observed values in Madrid using pyncov.plot:

import matplotlib.pyplot as plt

# Load the dataset with pandas
df = pd.read_csv(...)

fig, ax = plt.subplots(1, 3, figsize=(16, 4))
nc.plot.plot_state(simulations, nc.S.I1, ax=ax[0], index=df.index, title="New infections over time")
nc.plot.plot_state(simulations, nc.S.M0, diff=True, ax=ax[1], index=df.index, title="Daily fatalities")
nc.plot.plot_state(simulations, nc.S.M0, ax=ax[2], index=df.index, title="Total fatalities")
df.diff().plot(ax=ax[1]);
df.plot(ax=ax[2]);

A more detailed explanation can be found in the notebook included in the repository https://github.com/covid19-modeling/pyncov-19/blob/master/notebooks/basics.ipynb

About

This library is still a proof-of-concept and it's inteded only to be used for research and experimentation. For more information please read our preprint:

Matabuena, M., Meijide-García, C., Rodríguez-Mier, P., & Leborán, V. (2020). COVID-19: Estimating spread in Spain solving an inverse problem with a probabilistic model. arXiv preprint arXiv:2004.13695.

This model's main goal is to estimate the levels of infections (or the seroprevalence) of the population, using only data from the registered deaths caused by COVID-19. Although the model can be used to make future predictions (evolution of infections, fatalities, etc.), that's not the primary purpose of the model. Given the uncertainty about essential events that alter the course and dynamics of the spread (for example, the use of masks, lockdowns, social distance, etc.), it is tough to make accurate predictions, so we limit ourselves to use the model to reveal more information about what happened before (backcasting).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyncov-0.1.6.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

pyncov-0.1.6-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file pyncov-0.1.6.tar.gz.

File metadata

  • Download URL: pyncov-0.1.6.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.6.13 Windows/10

File hashes

Hashes for pyncov-0.1.6.tar.gz
Algorithm Hash digest
SHA256 eae45bc05438da9416106d8db498a87239236e8061883abe2b318b11a2bd2828
MD5 a6758ad912d9e5a3eeedad77139205d4
BLAKE2b-256 e6fa0f2ecbe6f8bf16caf22b0b7331a30cc04dda02064f16ca69545b94ecb8db

See more details on using hashes here.

File details

Details for the file pyncov-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pyncov-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.6.13 Windows/10

File hashes

Hashes for pyncov-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b9b8128c1b6a9905d723ab11a76c24b15d941d38814975ab911b21e73ade80d3
MD5 c28324428ec489fd9472c547662b580f
BLAKE2b-256 0e1cb696c9604401f3d122611dc6fe983b4824bda84aa03b30e6415a0322953f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page