immunity
immunity
Variants and immunity for Covasim on the Starsim base.
cv.variant adds a co-circulating variant to a sim. Since there is a single cv.COVID module with an internal variant axis, cv.variant is not a module: as in v3, it registers the variant’s parameters with the COVID module and seeds infections with it on the days it is introduced. cv.Sim(variants=[...]) registers each into the module before the states are allocated. The cross-immunity matrix builder (build_immunity_matrix) and the neutralizing antibody (NAb) waning functions live here too, and are used by cv.COVID and cv.CrossImmunity (connectors.py). As in v3 unless noted.
Classes
| Name | Description |
|---|---|
| variant | Add a new variant to the sim. |
variant
immunity.variant(variant, days, label=None, n_imports=1, rescale=True)Add a new variant to the sim.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| variant | str / dict | name of a predefined variant ('alpha', 'delta', …), or a dict of the per-variant parameters (rel_beta/rel_symp_prob/ rel_severe_prob/rel_crit_prob/rel_death_prob). |
required |
| days | int / str / list | day(s) on which the variant is introduced, as day indices or dates (e.g. '2020-03-15'). |
required |
| label | str | if variant is a dict, the variant’s name (dict key). |
None |
| n_imports | int | number of infections to import on each introduction day. | 1 |
| rescale | bool | whether to scale n_imports down by pop_scale (so the number of real introductions is preserved under population scaling). |
True |
Examples::
alpha = cv.variant('alpha', days=10, n_imports=20)
delta = cv.variant('delta', days='2020-04-01', n_imports=20)
sim = cv.Sim(variants=[alpha, delta]).run()
my_var = cv.variant(variant={'rel_beta': 2.5}, label='My variant', days=20) # A custom variant
Methods
| Name | Description |
|---|---|
| apply | On a matched introduction day, seed n_imports susceptibles with this variant. |
| initialize | Register this variant into the single COVID module’s variant axis (grow nv). |
| parse | Unpack the variant info, given as either a predefined-name string or a pars dict. |
| process_days | Convert the days (day indices or dates) to day indices, as for interventions; called by cv.COVID.init_pre() |
apply
immunity.variant.apply(covid)On a matched introduction day, seed n_imports susceptibles with this variant.
initialize
immunity.variant.initialize(covid)Register this variant into the single COVID module’s variant axis (grow nv).
parse
immunity.variant.parse(variant=None, label=None)Unpack the variant info, given as either a predefined-name string or a pars dict.
process_days
immunity.variant.process_days(sim)Convert the days (day indices or dates) to day indices, as for interventions; called by cv.COVID.init_pre()
Functions
| Name | Description |
|---|---|
| build_immunity_matrix | Build the asymmetric nv x nv cross-immunity matrix (v3 init_immunity). |
build_immunity_matrix
immunity.build_immunity_matrix(variant_map, override=None)Build the asymmetric nv x nv cross-immunity matrix (v3 init_immunity).
matrix[target, source] is the protection a prior source infection confers against a target challenge (diagonal 1.0 = full homologous protection). Start from np.ones((nv,nv)) and overwrite known pairs from get_cross_immunity() (a dict-of-dicts keyed by variant label).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| variant_map | dict | {index: label} for the variants in the sim. |
required |
| override | array | an explicit nv x nv matrix to use instead of the defaults. |
None |
Returns
| Name | Type | Description |
|---|---|---|
an nv x nv float ndarray. |