immunity
Defines classes and methods for calculating immunity
Functions
| Name | Description |
|---|---|
| check_immunity | Calculate people’s immunity on this timestep from prior infections. |
| exp_decay | Returns an array of length t with values for the immunity at each time step after recovery |
| init_immunity | Initialize immunity matrices with all genotypes and vaccines in the sim |
| linear_decay | Calculate linear decay |
| linear_growth | Calculate linear growth |
| precompute_waning | Process functional form and parameters into values: |
| update_peak_immunity | Update immunity level |
check_immunity
immunity.check_immunity(people)Calculate people’s immunity on this timestep from prior infections. As an example, suppose HPV16 and 18 are in the sim, and the cross-immunity matrix is:
pars['immunity'] = np.array([[1., 0.5],
[0.3, 1.]])
This indicates that people who’ve had HPV18 have 50% protection against getting 16, and people who’ve had 16 have 30% protection against getting 18. Now suppose we have 3 people, whose immunity levels are
people.nab_imm = np.array([[0.9, 0.0, 0.0],
[0.0, 0.7, 0.0]])
This indicates that person 1 has a prior HPV16 infection, person 2 has a prior HPV18 infection, and person 3 has no history of infection.
In this function, we take the dot product of pars[‘immunity’] and people.nab_imm to get:
people.sus_imm = np.array([[0.9 , 0.35, 0. ],
[0.27, 0.7 , 0. ]])
This indicates that the person 1 has high protection against reinfection with HPV16, and some (30% of 90%) protection against infection with HPV18, and so on.
exp_decay
immunity.exp_decay(t, init_val, half_life)Returns an array of length t with values for the immunity at each time step after recovery
init_immunity
immunity.init_immunity(sim, create=True)Initialize immunity matrices with all genotypes and vaccines in the sim
linear_decay
immunity.linear_decay(length, init_val, slope)Calculate linear decay
linear_growth
immunity.linear_growth(length, slope)Calculate linear growth
precompute_waning
immunity.precompute_waning(t, pars=None)Process functional form and parameters into values:
- 'exp_decay' : exponential decay. Parameters should be init_val and half_life (half_life can be None/nan)
- 'linear_decay': linear decay
A custom function can also be supplied.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| length | float | length of array to return, i.e., for how long waning is calculated | required |
| pars | dict | passed to individual immunity functions | None |
Returns
| Name | Type | Description |
|---|---|---|
| array of length ‘length’ of values |
update_peak_immunity
immunity.update_peak_immunity(
people,
inds,
imm_pars,
imm_source,
offset=None,
infection=True,
)Update immunity level
This function updates the immunity for individuals when an infection is cleared or vaccination occurs. - individuals that are infected and already have immunity from a previous vaccination/infection have their immunity level; - individuals without prior immunity are assigned an initial level drawn from a distribution. This level depends on whether the immunity is from a natural infection or from a vaccination (and if so, on the type of vaccine).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| people | A people object | required | |
| inds | Array of people indices | required | |
| imm_pars | Parameters from which to draw values for quantities like [‘imm_init’] - either sim pars (for natural immunity) or vaccine pars | required | |
| imm_source | index of either genotype or vaccine where immunity is coming from | required |
Returns: None