{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# T1 - Getting Started " ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "To install just type `pip install emodlib`. If it worked, you should be able to call `import emodlib`.\n", "\n", "In this first tutorial, we'll introduce the basics of:\n", "\n", "- Setting parameters\n", "- Simulating an infected individual\n", "- Inspecting individual model state" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Defining simulation parameters" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": "First let's create a configuration instance with default malaria intra-host model parameters and look at them..." }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "from emodlib.malaria import IntrahostComponent, create_config\n\nconfig = create_config()\nprint(config.yaml)" }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": "We can create a new configuration with modifications to arbitrary parameters (on top of existing defaults) by passing a dictionary to `create_config` function..." }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "config2 = create_config({'Run_Number': 6789, 'susceptibility_params': {'Antibody_CSP_Decay_Days': 99}})\nprint(config2.yaml)" }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": "Each config instance is independent. Note that `config` above still has its original defaults (Run_Number=12345), while `config2` has our modified values. Creating a new config always starts from defaults..." }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "config3 = create_config({'Run_Number': 99999})\nprint(f\"config.random_seed = {config.random_seed}\")\nprint(f\"config2.random_seed = {config2.random_seed}\")\nprint(f\"config3.random_seed = {config3.random_seed}\")" }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Simulating an infection in a naive host" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": "Now let's create a naive host using one of our configs..." }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "ic = IntrahostComponent.create(config)" }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Let's subject our naive host to an infectious challenge..." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "ic.challenge()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Now let's define a little helper function to print a descriptive line for the model state..." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def describe(c, t=None):\n", " \"\"\" Helper function to print a description of the intra-host model state \"\"\"\n", " s = 't=%d: ' % t if t is not None else ''\n", " s += '(asexual, mature gametocyte, fever, infectiousness) = (%0.2f, %0.3f, %0.1f %0.2f)' % \\\n", " (c.parasite_density, c.gametocyte_density, c.fever_temperature, c.infectiousness)\n", " print(s)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Let's do enough timestep updates to see the emergence of asexual-stage parasites from the liver, the onset of fever with high parasite density, and the progression of differentiated gametocytes to mature gametocytes..." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "t=0: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=1: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=2: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=3: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=4: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=5: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=6: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=7: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)\n", "t=8: (asexual, mature gametocyte, fever, infectiousness) = (0.05, 0.000, 37.0 0.00)\n", "t=9: (asexual, mature gametocyte, fever, infectiousness) = (0.05, 0.000, 37.0 0.00)\n", "t=10: (asexual, mature gametocyte, fever, infectiousness) = (0.71, 0.000, 37.0 0.00)\n", "t=11: (asexual, mature gametocyte, fever, infectiousness) = (0.71, 0.000, 37.0 0.00)\n", "t=12: (asexual, mature gametocyte, fever, infectiousness) = (10.61, 0.000, 37.0 0.00)\n", "t=13: (asexual, mature gametocyte, fever, infectiousness) = (10.61, 0.000, 37.0 0.00)\n", "t=14: (asexual, mature gametocyte, fever, infectiousness) = (158.18, 0.000, 37.0 0.00)\n", "t=15: (asexual, mature gametocyte, fever, infectiousness) = (158.18, 0.000, 37.1 0.00)\n", "t=16: (asexual, mature gametocyte, fever, infectiousness) = (2359.20, 0.000, 37.1 0.00)\n", "t=17: (asexual, mature gametocyte, fever, infectiousness) = (2359.20, 0.000, 38.1 0.00)\n", "t=18: (asexual, mature gametocyte, fever, infectiousness) = (35184.98, 0.000, 38.1 0.00)\n", "t=19: (asexual, mature gametocyte, fever, infectiousness) = (6473.13, 0.000, 43.2 0.00)\n", "t=20: (asexual, mature gametocyte, fever, infectiousness) = (17369.77, 0.002, 41.9 0.00)\n", "t=21: (asexual, mature gametocyte, fever, infectiousness) = (2538.02, 0.002, 44.6 0.00)\n", "t=22: (asexual, mature gametocyte, fever, infectiousness) = (12189.47, 0.031, 37.0 0.00)\n", "t=23: (asexual, mature gametocyte, fever, infectiousness) = (2932.88, 0.023, 37.6 0.00)\n", "t=24: (asexual, mature gametocyte, fever, infectiousness) = (9026.20, 0.462, 37.0 0.00)\n", "t=25: (asexual, mature gametocyte, fever, infectiousness) = (1683.18, 0.350, 37.7 0.00)\n", "t=26: (asexual, mature gametocyte, fever, infectiousness) = (4068.65, 6.887, 37.0 0.03)\n", "t=27: (asexual, mature gametocyte, fever, infectiousness) = (574.03, 5.221, 37.4 0.00)\n", "t=28: (asexual, mature gametocyte, fever, infectiousness) = (1090.37, 102.722, 37.0 0.34)\n", "t=29: (asexual, mature gametocyte, fever, infectiousness) = (131.97, 77.868, 37.1 0.09)\n" ] } ], "source": [ "for t in range(30):\n", " ic.update(dt=1)\n", " describe(ic, t)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "And finally treat the individual and see their infections are now gone...\n", "\n" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.1 0.00)\n" ] } ], "source": [ "ic.treat()\n", "describe(ic)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 2 }