hpvsim.immunity module

Defines classes and methods for calculating immunity

init_immunity(sim, create=True)[source]

Initialize immunity matrices with all genotypes and vaccines in the sim

update_peak_immunity(people, inds, imm_pars, imm_source, offset=None, infection=True)[source]

Update immunity level

This function updates the immunity for individuals when an infection 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
  • people – A people object

  • inds – Array of people indices

  • imm_pars – Parameters from which to draw values for quantities like [‘imm_init’] - either sim pars (for natural immunity) or vaccine pars

  • imm_source – index of either genotype or vaccine where immunity is coming from

Returns: None

check_immunity(people)[source]

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.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.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.

precompute_waning(t, pars=None)[source]

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
  • length (float) – length of array to return, i.e., for how long waning is calculated

  • pars (dict) – passed to individual immunity functions

Returns

array of length ‘length’ of values

exp_decay(t, init_val, half_life)[source]

Returns an array of length t with values for the immunity at each time step after recovery

linear_decay(length, init_val, slope)[source]

Calculate linear decay

linear_growth(length, slope)[source]

Calculate linear growth