T1 - Getting Started
To install just type pip install emodlib. If it worked, you should be able to call import emodlib.
In this first tutorial, we’ll introduce the basics of:
Setting parameters
Simulating an infected individual
Inspecting individual model state
Defining simulation parameters
First let’s create a configuration instance with default malaria intra-host model parameters and look at them…
[ ]:
from emodlib.malaria import IntrahostComponent, create_config
config = create_config()
print(config.yaml)
We can create a new configuration with modifications to arbitrary parameters (on top of existing defaults) by passing a dictionary to create_config function…
[ ]:
config2 = create_config({'Run_Number': 6789, 'susceptibility_params': {'Antibody_CSP_Decay_Days': 99}})
print(config2.yaml)
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…
[ ]:
config3 = create_config({'Run_Number': 99999})
print(f"config.random_seed = {config.random_seed}")
print(f"config2.random_seed = {config2.random_seed}")
print(f"config3.random_seed = {config3.random_seed}")
Simulating an infection in a naive host
Now let’s create a naive host using one of our configs…
[ ]:
ic = IntrahostComponent.create(config)
Let’s subject our naive host to an infectious challenge…
[13]:
ic.challenge()
Now let’s define a little helper function to print a descriptive line for the model state…
[14]:
def describe(c, t=None):
""" Helper function to print a description of the intra-host model state """
s = 't=%d: ' % t if t is not None else ''
s += '(asexual, mature gametocyte, fever, infectiousness) = (%0.2f, %0.3f, %0.1f %0.2f)' % \
(c.parasite_density, c.gametocyte_density, c.fever_temperature, c.infectiousness)
print(s)
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…
[15]:
for t in range(30):
ic.update(dt=1)
describe(ic, t)
t=0: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=1: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=2: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=3: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=4: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=5: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=6: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=7: (asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.0 0.00)
t=8: (asexual, mature gametocyte, fever, infectiousness) = (0.05, 0.000, 37.0 0.00)
t=9: (asexual, mature gametocyte, fever, infectiousness) = (0.05, 0.000, 37.0 0.00)
t=10: (asexual, mature gametocyte, fever, infectiousness) = (0.71, 0.000, 37.0 0.00)
t=11: (asexual, mature gametocyte, fever, infectiousness) = (0.71, 0.000, 37.0 0.00)
t=12: (asexual, mature gametocyte, fever, infectiousness) = (10.61, 0.000, 37.0 0.00)
t=13: (asexual, mature gametocyte, fever, infectiousness) = (10.61, 0.000, 37.0 0.00)
t=14: (asexual, mature gametocyte, fever, infectiousness) = (158.18, 0.000, 37.0 0.00)
t=15: (asexual, mature gametocyte, fever, infectiousness) = (158.18, 0.000, 37.1 0.00)
t=16: (asexual, mature gametocyte, fever, infectiousness) = (2359.20, 0.000, 37.1 0.00)
t=17: (asexual, mature gametocyte, fever, infectiousness) = (2359.20, 0.000, 38.1 0.00)
t=18: (asexual, mature gametocyte, fever, infectiousness) = (35184.98, 0.000, 38.1 0.00)
t=19: (asexual, mature gametocyte, fever, infectiousness) = (6473.13, 0.000, 43.2 0.00)
t=20: (asexual, mature gametocyte, fever, infectiousness) = (17369.77, 0.002, 41.9 0.00)
t=21: (asexual, mature gametocyte, fever, infectiousness) = (2538.02, 0.002, 44.6 0.00)
t=22: (asexual, mature gametocyte, fever, infectiousness) = (12189.47, 0.031, 37.0 0.00)
t=23: (asexual, mature gametocyte, fever, infectiousness) = (2932.88, 0.023, 37.6 0.00)
t=24: (asexual, mature gametocyte, fever, infectiousness) = (9026.20, 0.462, 37.0 0.00)
t=25: (asexual, mature gametocyte, fever, infectiousness) = (1683.18, 0.350, 37.7 0.00)
t=26: (asexual, mature gametocyte, fever, infectiousness) = (4068.65, 6.887, 37.0 0.03)
t=27: (asexual, mature gametocyte, fever, infectiousness) = (574.03, 5.221, 37.4 0.00)
t=28: (asexual, mature gametocyte, fever, infectiousness) = (1090.37, 102.722, 37.0 0.34)
t=29: (asexual, mature gametocyte, fever, infectiousness) = (131.97, 77.868, 37.1 0.09)
And finally treat the individual and see their infections are now gone…
[16]:
ic.treat()
describe(ic)
(asexual, mature gametocyte, fever, infectiousness) = (0.00, 0.000, 37.1 0.00)