interventions

interventions

Specify the core interventions available in Covasim: testing, contact tracing, vaccination, prior immunity, and changes to transmission and parameters. Other interventions can be defined by the user by inheriting from these classes.

Classes

Name Description
BaseVaccination Apply a vaccine to a subset of the population.
Intervention Base class for interventions. A custom intervention defines step(self) (or, as in v3,
change_beta The most basic intervention – change beta (transmission) by a certain amount
clip_edges Isolate contacts by removing them from the simulation. Contacts are treated as
contact_tracing Contact tracing of people who are diagnosed. When a person is diagnosed positive
dynamic_pars A generic intervention that modifies a set of parameters at specified points
historical_vaccinate_prob Probability-based historical vaccination
historical_wave Imprint a historical (pre t=0) wave of infections in the population.
sequence This is an example of a meta-intervention which switches between a sequence of interventions.
simple_vaccine Apply a simple vaccine to a subset of the population. Rather than conferring neutralizing
test_num Test the specified number of people per day. Useful for including historical
test_prob Assign each person a probability of being tested for COVID based on their
vaccinate_num This vaccine intervention allocates vaccines in a pre-computed order of
vaccinate_prob Probability-based vaccination

BaseVaccination

interventions.BaseVaccination(
    vaccine,
    label=None,
    booster=False,
    subtarget=None,
    **kwargs,
)

Apply a vaccine to a subset of the population.

This base class implements the mechanism of vaccinating people to modify their immunity (through neutralizing antibodies, so it requires use_waning=True; otherwise, use cv.simple_vaccine). It does not implement allocation of the vaccines, which is implemented by derived classes such as cv.vaccinate_prob and cv.vaccinate_num. Custom vaccine allocations can be implemented by a derived class overriding select_people(sim), which returns the UIDs of the people to vaccinate on the current timestep.

The number of doses of this vaccine given to each person (indexed by UID) is stored in doses.

Parameters

Name Type Description Default
vaccine (dict/str) which vaccine to use; see below for dict parameters required
label (str) if vaccine is supplied as a dict, the name of the vaccine required
booster (bool) whether the vaccine is a booster, i.e. whether vaccinated people are eligible required
subtarget (dict) subtarget intervention to people with particular indices (see test_num() for details) required
kwargs (dict) passed to Intervention() required

If vaccine is supplied as a dictionary, it must have the following parameters:

EITHER
- ``nab_init``:  the initial antibody level (higher = more protection)
- ``nab_boost``: how much of a boost being vaccinated on top of a previous dose or natural infection provides
OR
- ``target_eff``: the target efficacy from which to calculate initial antibody and boosting; must be supplied as a list, where the length of the list is equal to the number of doses
AND
- ``doses``:     the number of doses required to be fully vaccinated with this vaccine
- ``interval``:  the interval between doses (integer)
- entries for efficacy against each of the variants (e.g. ``b117``)

See parameters.py for additional examples of these parameters.

Example::

class vaccinate_over_70(cv.BaseVaccination):
    def select_people(self, sim):
        if sim.ti == 5:
            return cv.true(sim.people.age > 70)
        return np.array([], dtype=int)

sim = cv.Sim(interventions=vaccinate_over_70('pfizer'), use_waning=True).run()

Methods

Name Description
register_vaccine Populate missing dose/variant pars, back-calculate target_eff, and register in the module.
select_people Return the UIDs of the people to vaccinate on this timestep. Derived classes must
vaccinate Vaccinate people.
register_vaccine
interventions.BaseVaccination.register_vaccine(covid)

Populate missing dose/variant pars, back-calculate target_eff, and register in the module.

select_people
interventions.BaseVaccination.select_people(sim)

Return the UIDs of the people to vaccinate on this timestep. Derived classes must implement this method to determine who to vaccinate.

Parameters
Name Type Description Default
sim the simulation object required
vaccinate
interventions.BaseVaccination.vaccinate(sim, vacc_inds, t=None)

Vaccinate people.

This applies the vaccine to the requested people, and returns the UIDs of the people vaccinated. These may be fewer than were requested, since anyone who is dead, or who has already had all the doses of this vaccine, is skipped.

Parameters
Name Type Description Default
sim the simulation object required
vacc_inds the UIDs of the people to vaccinate required
t the day of vaccination, if before the start of the sim (for historical vaccination) None

Intervention

interventions.Intervention(
    *args,
    do_plot=None,
    show_label=None,
    line_args=None,
    **kwargs,
)

Base class for interventions. A custom intervention defines step(self) (or, as in v3, apply(self, sim)), which is called on each timestep, and optionally init_post(self) (or initialize(self, sim)).

Parameters

Name Type Description Default
label str a label for the intervention (used for plotting, and for ease of identification) required
show_label bool whether to include the label in the legend None
do_plot bool whether to plot the intervention None
line_args dict arguments passed to ax.axvline() when plotting None

Example::

class halve_beta(cv.Intervention):
    def step(self):
        if self.ti == 30:
            self.sim['beta'] = self.sim['beta']/2

sim = cv.Sim(interventions=halve_beta()).run()

Methods

Name Description
is_active Whether the intervention is active on day index ti (within [start_day, end_day]).
is_active
interventions.Intervention.is_active(ti)

Whether the intervention is active on day index ti (within [start_day, end_day]).

change_beta

interventions.change_beta(days, changes, layers=None, **kwargs)

The most basic intervention – change beta (transmission) by a certain amount on a given day or days. This can be used to represent physical distancing (although clip_edges() is more appropriate for overall changes in mobility, e.g. school or workplace closures), as well as hand-washing, masks, and other behavioral changes that affect transmission rates. Each change is relative to the original beta, not cumulative.

Parameters

Name Type Description Default
days int / arr / str / function the day or array of days to apply the interventions, or a function days(interv, sim) returning them required
changes float / arr the changes in beta (1 = no change, 0 = no transmission) required
layers str / list the layers in which to change beta (default: all, by changing the overall beta) None
kwargs dict passed to Intervention() {}

Examples::

interv = cv.change_beta(25, 0.3) # On day 25, reduce overall beta by 70% to 0.3
interv = cv.change_beta([14, 28], [0.7, 1], layers='s') # On day 14, reduce beta by 30%, and on day 28, return to 1 for schools

clip_edges

interventions.clip_edges(days, changes, layers=None, **kwargs)

Isolate contacts by removing them from the simulation. Contacts are treated as “edges”, and this intervention works by removing them from the networks. When the intervention is over, they are restored. This intervention has quite similar effects as change_beta(), but is more appropriate for modeling the effects of mobility reductions such as school and workplace closures. The main difference is that since clip_edges() actually removes contacts, it affects the number of people who would be traced and placed in quarantine if an individual tests positive. It also alters the structure of the network – i.e., compared to a baseline case of 20 contacts and a 2% chance of infecting each, there are slightly different statistics for a beta reduction (i.e., 20 contacts and a 1% chance of infecting each) versus an edge clipping (i.e., 10 contacts and a 2% chance of infecting each).

Each change is the fraction of the original edges to keep, not cumulative. For a dynamic layer (see dynam_layer), which is recreated on each timestep, that fraction of the edges is kept on every timestep until the next change.

Parameters

Name Type Description Default
days int / arr / str / function the day or array of days to isolate contacts, or a function days(interv, sim) returning them required
changes float / arr the changes in the number of contacts (1 = no change, 0 = no contacts) required
layers str / list the layers in which to isolate contacts (if None, then all layers) None
kwargs dict passed to Intervention() {}

Examples::

interv = cv.clip_edges(25, 0.3) # On day 25, reduce overall contacts by 70% to 0.3
interv = cv.clip_edges([14, 28], [0.7, 1], layers='s') # On day 14, remove 30% of school contacts, and on day 28, restore them

Methods

Name Description
shrink Remove the copies of the original edges, for saving
shrink
interventions.clip_edges.shrink()

Remove the copies of the original edges, for saving

contact_tracing

interventions.contact_tracing(
    trace_probs=None,
    trace_time=None,
    start_day=0,
    end_day=None,
    presumptive=False,
    quar_period=None,
    capacity=None,
    **kwargs,
)

Contact tracing of people who are diagnosed. When a person is diagnosed positive (by either test_num() or test_prob(); this intervention has no effect if there is not also a testing intervention active), a certain proportion of the index case’s contacts (defined by trace_probs) are contacted after a certain number of days (defined by trace_time). After they are contacted, they are placed into quarantine (with effectiveness quar_factor, a simulation parameter) for a certain period (defined by quar_period). They may also change their testing probability, if test_prob() is defined.

Tracing involves three steps that can independently be overridden or extended by derived classes: select_cases(), identify_contacts(), and notify_contacts().

Parameters

Name Type Description Default
trace_probs float / dict probability of tracing, per layer (default: 100%, i.e. everyone is traced); a layer not in the dict is not traced None
trace_time float / dict days required to trace, per layer (default: 0, i.e. no delay); rounded to a whole number of days None
start_day int / str intervention start day (default: 0, i.e. the start of the simulation) 0
end_day int / str intervention end day (default: no end) None
presumptive bool whether or not to begin isolation and contact tracing on the presumption of a positive diagnosis (default: no) False
quar_period int number of days to quarantine when notified as a known contact (default: the sim’s quar_period) None
capacity int optionally specify a maximum number of newly diagnosed people to trace each day None
kwargs dict passed to Intervention() {}

Example::

tp = cv.test_prob(symp_prob=0.1, asymp_prob=0.01)
ct = cv.contact_tracing(trace_probs=0.5, trace_time=2)
sim = cv.Sim(interventions=[tp, ct]) # Note that without testing, contact tracing has no effect

Methods

Name Description
identify_contacts Return the contacts to notify, by trace time.
init_post Fill in the defaults, and expand trace_probs and trace_time into dicts with a value for each layer
notify_contacts Notify people that they have had contact with a confirmed case: set their
select_cases Return the people to be traced on this timestep: those diagnosed today or, if
step Trace and notify contacts
identify_contacts
interventions.contact_tracing.identify_contacts(sim, trace_inds)

Return the contacts to notify, by trace time.

In the base class, the trace time is the same for everyone in a layer, but derived classes might provide different functionality, e.g. sampling the trace time from a distribution.

Parameters
Name Type Description Default
sim the simulation object required
trace_inds the UIDs of the people to trace required
Returns
Name Type Description
a dict {trace_time: uids} of the people to notify
init_post
interventions.contact_tracing.init_post()

Fill in the defaults, and expand trace_probs and trace_time into dicts with a value for each layer

notify_contacts
interventions.contact_tracing.notify_contacts(sim, contacts)

Notify people that they have had contact with a confirmed case: set their known_contact flag, and schedule their quarantine to start on the day they are notified.

Parameters
Name Type Description Default
sim the simulation object required
contacts a dict {trace_time: uids} of the people to notify required
select_cases
interventions.contact_tracing.select_cases(sim)

Return the people to be traced on this timestep: those diagnosed today or, if presumptive, those tested today who are infected

step
interventions.contact_tracing.step()

Trace and notify contacts

dynamic_pars

interventions.dynamic_pars(pars=None, **kwargs)

A generic intervention that modifies a set of parameters at specified points in time.

The intervention takes a single argument, pars, which is a dictionary of which parameters to change, with following structure: keys are the parameters to change, then subkeys ‘days’ and ‘vals’ are either a scalar or list of when the change(s) should take effect and what the new value should be, respectively. If a value is a dict (e.g. for beta_layer), it updates the parameter rather than replacing it.

You can also pass parameters to change directly as keyword arguments.

Parameters

Name Type Description Default
pars dict described above None
kwargs dict parameters to change, or else passed to Intervention() {}

Examples::

interv = cv.dynamic_pars(n_imports=dict(days=10, vals=100))
interv = cv.dynamic_pars({'beta':{'days':[14, 28], 'vals':[0.005, 0.015]}, 'rel_death_prob':{'days':30, 'vals':2.0}}) # Change beta, and make death more likely
interv = cv.dynamic_pars(beta_layer=dict(days=20, vals=dict(s=0))) # Close schools on day 20

Methods

Name Description
init_post Convert any dates to days
step Loop over the parameters, and then loop over the days, applying them if any are found
init_post
interventions.dynamic_pars.init_post()

Convert any dates to days

step
interventions.dynamic_pars.step()

Loop over the parameters, and then loop over the days, applying them if any are found

historical_vaccinate_prob

interventions.historical_vaccinate_prob(
    vaccine,
    days,
    label=None,
    prob=None,
    subtarget=None,
    compliance=1.0,
    **kwargs,
)

Probability-based historical vaccination

This vaccine intervention allocates vaccines parametrized by the daily probability of being vaccinated. Unlike cv.vaccinate_prob, this allows vaccination before the start of the sim (negative days), continuing into the simulation. The days before the start are stepped through when the sim is initialized, giving first doses and any second doses that are due, so people start the sim with waned NAbs; second doses due on or after the start are given during the sim. The doses given before the start are counted in the results on day 0. Requires use_waning=True.

Parameters

Name Type Description Default
vaccine (dict/str) which vaccine to use; see BaseVaccination for dict parameters required
days (int/arr) the day or array of days to apply the interventions; negative days are before the start of the sim (so -1 is the day before the start) required
label (str) if vaccine is supplied as a dict, the name of the vaccine required
prob (float) probability of being vaccinated (i.e., fraction of the population); default 1 with no subtarget, or 0 with one required
subtarget (dict) subtarget intervention to people with particular indices (see test_num() for details) required
compliance (float/arr) probability of a person taking each dose; a single number applies to both doses, or give two numbers for the first and second required
kwargs (dict) passed to Intervention() required

Example::

pfizer = cv.historical_vaccinate_prob(vaccine='pfizer', days=np.arange(-30,0), prob=0.007) # 30-day vaccination campaign
cv.Sim(interventions=pfizer, use_waning=True).run().plot()

Methods

Name Description
filter_compliance Keep the people who comply with this dose (0 for the first, 1 for the second)
schedule_second_doses Schedule the second dose for people given a first dose on day t, allowing for compliance
select_first_doses Choose the people to give a first dose to on day t, allowing for compliance
update_historical_nab Step the NAbs of the people vaccinated by this intervention forward a day, on day t before the start of the sim
filter_compliance
interventions.historical_vaccinate_prob.filter_compliance(uids, dose)

Keep the people who comply with this dose (0 for the first, 1 for the second)

schedule_second_doses
interventions.historical_vaccinate_prob.schedule_second_doses(t, uids)

Schedule the second dose for people given a first dose on day t, allowing for compliance

select_first_doses
interventions.historical_vaccinate_prob.select_first_doses(sim, t)

Choose the people to give a first dose to on day t, allowing for compliance

update_historical_nab
interventions.historical_vaccinate_prob.update_historical_nab(covid, t)

Step the NAbs of the people vaccinated by this intervention forward a day, on day t before the start of the sim

historical_wave

interventions.historical_wave(
    days_prior,
    prob,
    dist=None,
    subtarget=None,
    variant=None,
    **kwargs,
)

Imprint a historical (pre t=0) wave of infections in the population.

At the start of the first timestep, agents are infected as if on a day before the start of the sim, with the usual prognoses, so by day 0 most have recovered (with waned NAbs), some have died, and any infected shortly before the start are still infectious. As in v3, the infections, recoveries, deaths etc. before the start are counted in the results on day 0. Requires use_waning=True.

Parameters

Name Type Description Default
days_prior int / str / list offset relative to t=0 for the wave (the median of the default distribution), or the median date if a string like “2021-11-15” required
prob float / list probability of infection during the wave required
dist dict / list the shape of the wave, as a v3 distribution, e.g. dict(dist=‘normal’, par1=0, par2=15) (default: normal with a full width at half maximum of 5 weeks) None
subtarget dict / list subtarget the wave to people with particular indices (see test_num() for details) None
variant str / list name of the variant associated with the wave (default wild) None
kwargs dict passed to Intervention() {}

For multiple waves, supply lists; a single value applies to every wave.

Examples::

cv.Sim(interventions=cv.historical_wave(120, 0.30)).run().plot()
cv.Sim(interventions=cv.historical_wave(days_prior=[300, 120], prob=[0.1, 0.3])).run().plot()

Methods

Name Description
per_wave A list is one value per wave; otherwise, use the same value for every wave
start_step Infect the people in each wave, before the COVID module updates the states on the first timestep (which applies the recoveries, deaths, etc.)
step As in v3, count the infections before the start of the sim in the results on day 0
per_wave
interventions.historical_wave.per_wave(val, n_waves)

A list is one value per wave; otherwise, use the same value for every wave

start_step
interventions.historical_wave.start_step()

Infect the people in each wave, before the COVID module updates the states on the first timestep (which applies the recoveries, deaths, etc.)

step
interventions.historical_wave.step()

As in v3, count the infections before the start of the sim in the results on day 0

sequence

interventions.sequence(days, interventions, **kwargs)

This is an example of a meta-intervention which switches between a sequence of interventions.

Parameters

Name Type Description Default
days list the days on which to start applying each intervention required
interventions list the interventions to apply on those days required
kwargs dict passed to Intervention() {}

Example::

interv = cv.sequence(days=[10, 51], interventions=[
            cv.test_num(daily_tests=100),
            cv.test_prob(symp_prob=0.2, asymp_prob=0.002),
        ])

simple_vaccine

interventions.simple_vaccine(
    days,
    prob=1.0,
    rel_sus=0.0,
    rel_symp=0.0,
    subtarget=None,
    cumulative=False,
    **kwargs,
)

Apply a simple vaccine to a subset of the population. Rather than conferring neutralizing antibodies, this directly changes the relative susceptibility and the probability of developing symptoms if still infected. The number of doses given to each person (indexed by UID) is stored in doses.

Parameters

Name Type Description Default
days int / arr / str the day or array of days to apply the interventions required
prob float probability of being vaccinated (i.e., fraction of the population) 1.0
rel_sus float relative change in susceptibility; 0 = perfect, 1 = no effect 0.0
rel_symp float relative change in symptom probability for people who still get infected; 0 = perfect, 1 = no effect 0.0
subtarget dict subtarget intervention to people with particular indices (see test_num() for details) None
cumulative bool whether cumulative doses have cumulative effects (default false); can also be an array for efficacy per dose, with the last entry used for multiple doses; thus True = [1] and False = [1,0] False
kwargs dict passed to Intervention() {}

Note: this intervention is intended for use with use_waning=False.

Examples::

interv = cv.simple_vaccine(days=50, prob=0.3, rel_sus=0.5, rel_symp=0.1)
interv = cv.simple_vaccine(days=[10,20,30,40], prob=0.8, rel_sus=0.5, cumulative=[1, 0.3, 0.1, 0]) # A vaccine with efficacy up to the 3rd dose

test_num

interventions.test_num(
    daily_tests,
    symp_test=100.0,
    quar_test=1.0,
    quar_policy=None,
    subtarget=None,
    ili_prev=None,
    sensitivity=1.0,
    loss_prob=0.0,
    test_delay=0,
    start_day=0,
    end_day=None,
    swab_delay=None,
    **kwargs,
)

Test the specified number of people per day. Useful for including historical testing data. The probability of a given person getting a test is dependent on the total number of tests, population size, and odds ratios. Compare this intervention with cv.test_prob().

Parameters

Name Type Description Default
daily_tests (arr) number of tests per day, can be int, array, or dataframe/series; if integer, use that number every day; if ‘data’ or another string, use loaded data required
symp_test (float) odds ratio of a symptomatic person testing (default: 100x more likely) required
quar_test (float) probability of a person in quarantine testing (default: no more likely) required
quar_policy (str) policy for testing in quarantine: options are ‘start’ (default), ‘end’, ‘both’ (start and end), ‘daily’; can also be a number or a function, see get_quar_inds() required
subtarget (dict) subtarget intervention to people with particular indices (format: {‘inds’: array of indices, or function to return indices from the sim, ‘vals’: value(s) to apply}) required
ili_prev (arr) prevalence of influenza-like-illness symptoms in the population; can be float, array, or dataframe/series required
sensitivity (float) test sensitivity (default 100%, i.e. no false negatives) required
loss_prob (float) probability of the person being lost-to-follow-up (default 0%, i.e. no one lost to follow-up) required
test_delay (int) days for test result to be known (default 0, i.e. results available instantly) required
start_day (int/str) day the intervention starts (default: 0, i.e. first day of the simulation) required
end_day (int/str) day the intervention ends (default: no end) required
swab_delay (dict) distribution for the delay from onset to swab, e.g. dict(dist=‘lognormal’, par1=10, par2=170); if this is present, it is used instead of test_delay. For ‘lognormal’, par2 is the variance, not the standard deviation (see cv.utils.get_pdf()) required
kwargs (dict) passed to Intervention() required

Examples::

interv = cv.test_num(daily_tests=[0.10*n_people]*npts)
interv = cv.test_num(daily_tests=[0.10*n_people]*npts, subtarget={'inds': cv.true(sim.people.age>50), 'vals': 1.2}) # People over 50 are 20% more likely to test
interv = cv.test_num(daily_tests=[0.10*n_people]*npts, subtarget={'inds': lambda sim: cv.true(sim.people.age>50), 'vals': 1.2}) # People over 50 are 20% more likely to test
interv = cv.test_num(daily_tests='data') # Take number of tests from loaded data using default column name (new_tests)
interv = cv.test_num(daily_tests='swabs_per_day') # Take number of tests from loaded data using a custom column name

test_prob

interventions.test_prob(
    symp_prob,
    asymp_prob=0.0,
    symp_quar_prob=None,
    asymp_quar_prob=None,
    quar_policy=None,
    subtarget=None,
    ili_prev=None,
    sensitivity=1.0,
    loss_prob=0.0,
    test_delay=0,
    start_day=0,
    end_day=None,
    swab_delay=None,
    **kwargs,
)

Assign each person a probability of being tested for COVID based on their symptom state, quarantine state, and other states. Unlike test_num, the total number of tests is not specified, but rather is an output.

Parameters

Name Type Description Default
symp_prob (float) probability of testing a symptomatic (unquarantined) person required
asymp_prob (float) probability of testing an asymptomatic (unquarantined) person (default: 0) required
symp_quar_prob (float) probability of testing a symptomatic quarantined person (default: same as symp_prob) required
asymp_quar_prob (float) probability of testing an asymptomatic quarantined person (default: same as asymp_prob) required
quar_policy (str) policy for testing in quarantine: options are ‘start’ (default), ‘end’, ‘both’ (start and end), ‘daily’; can also be a number or a function, see get_quar_inds() required
subtarget (dict) subtarget intervention to people with particular indices (see test_num() for details) required
ili_prev (float/arr) prevalence of influenza-like-illness symptoms in the population; can be float, array, or dataframe/series required
sensitivity (float) test sensitivity (default 100%, i.e. no false negatives) required
loss_prob (float) probability of the person being lost-to-follow-up (default 0%, i.e. no one lost to follow-up) required
test_delay (int) days for test result to be known (default 0, i.e. results available instantly) required
start_day (int/str) day the intervention starts (default: 0, i.e. first day of the simulation) required
end_day (int/str) day the intervention ends (default: no end) required
swab_delay (dict) distribution for the delay from onset to swab, e.g. dict(dist=‘lognormal’, par1=10, par2=170); if this is present, it is used instead of test_delay. For ‘lognormal’, par2 is the variance, not the standard deviation (see cv.utils.get_pdf()) required
kwargs (dict) passed to Intervention() required

Examples::

interv = cv.test_prob(symp_prob=0.1, asymp_prob=0.01) # Test 10% of symptomatics and 1% of asymptomatics
interv = cv.test_prob(symp_prob=0.1, symp_quar_prob=0.4) # Test 40% of those in quarantine with symptoms

vaccinate_num

interventions.vaccinate_num(
    vaccine,
    num_doses,
    booster=False,
    subtarget=None,
    sequence=None,
    label=None,
    **kwargs,
)

This vaccine intervention allocates vaccines in a pre-computed order of distribution, at a specified rate of doses per day. Second doses are prioritized each day.

Parameters

Name Type Description Default
vaccine dict / str which vaccine to use; see BaseVaccination for dict parameters required
num_doses Specify the number of doses per day. This can take three forms - A scalar number of doses per day - A dict keyed by day/date with the number of doses e.g. {2:10000, '2021-05-01':20000}. Any dates are converted to simulation days when the sim is initialized. - A callable that takes in a cv.Sim and returns a scalar number of doses. For example, def doses(sim): return 100 if sim.ti > 10 else 0 would be suitable required
booster bool whether it’s a booster (i.e. targeted to vaccinated people) or not False
subtarget dict subtarget intervention to people with particular indices (see test_num() for details); the values multiply each person’s chance of being offered a first dose None
sequence Specify the order in which people should get vaccinated. This can be - An array of person indices in order of vaccination priority - A callable that takes in cv.People and returns an ordered sequence. For example, to vaccinate people in descending age order, def age_sequence(people): return np.argsort(-people.age) would be suitable. - The shortcut ‘age’, which does prioritization by age (see below for implementation) If not specified, people will be randomly ordered. None
label str if vaccine is supplied as a dict, the name of the vaccine None
kwargs dict passed to Intervention() {}

Example::

pfizer = cv.vaccinate_num(vaccine='pfizer', sequence='age', num_doses=100)
cv.Sim(interventions=pfizer, use_waning=True).run().plot()

Methods

Name Description
process_sequence Handle the different types of prioritization sequence for vaccination
select_people Return the people due a second dose, then those next in the sequence for a first dose, up to the number of doses today
process_sequence
interventions.vaccinate_num.process_sequence(sequence)

Handle the different types of prioritization sequence for vaccination

select_people
interventions.vaccinate_num.select_people(sim)

Return the people due a second dose, then those next in the sequence for a first dose, up to the number of doses today

vaccinate_prob

interventions.vaccinate_prob(
    vaccine,
    days,
    label=None,
    prob=None,
    subtarget=None,
    booster=False,
    **kwargs,
)

Probability-based vaccination

This vaccine intervention allocates vaccines parametrized by the daily probability of being vaccinated. People given a first dose of a two-dose vaccine are given their second dose after the vaccine’s dosing interval.

Parameters

Name Type Description Default
vaccine dict / str which vaccine to use; see BaseVaccination for dict parameters required
days int / arr the day or array of days to apply the interventions required
label str if vaccine is supplied as a dict, the name of the vaccine None
prob float probability of being vaccinated (i.e., fraction of the population); default 1 with no subtarget, or 0 with one (so only the people subtargeted are vaccinated) None
subtarget dict subtarget intervention to people with particular indices (see test_num() for details) None
booster bool whether it’s a booster (i.e. targeted to vaccinated people) or not False
kwargs dict passed to Intervention() {}

Example::

pfizer = cv.vaccinate_prob(vaccine='pfizer', days=30, prob=0.7)
cv.Sim(interventions=pfizer, use_waning=True).run().plot()

Methods

Name Description
schedule_second_doses Schedule the second dose for people given a first dose on day t
select_first_doses Choose the people to give a first dose to on day t
select_people Return the people to give a first dose to on day t (by default, today), and those due a second dose
schedule_second_doses
interventions.vaccinate_prob.schedule_second_doses(t, uids)

Schedule the second dose for people given a first dose on day t

select_first_doses
interventions.vaccinate_prob.select_first_doses(sim, t)

Choose the people to give a first dose to on day t

select_people
interventions.vaccinate_prob.select_people(sim, t=None)

Return the people to give a first dose to on day t (by default, today), and those due a second dose

Functions

Name Description
InterventionDict Generate an intervention from a dictionary. Although a function, it acts
prior_immunity Wrapper function for historical_wave and historical_vaccinate_prob. If the vaccine keyword is
vaccinate Wrapper function for vaccinate_prob() and vaccinate_num(). If the num_doses

InterventionDict

interventions.InterventionDict(which, pars)

Generate an intervention from a dictionary. Although a function, it acts like a class, since it returns a class instance.

Example::

interv = cv.InterventionDict(which='change_beta', pars={'days': 30, 'changes': 0.5, 'layers': None})

prior_immunity

interventions.prior_immunity(*args, **kwargs)

Wrapper function for historical_wave and historical_vaccinate_prob. If the vaccine keyword is present then historical_vaccinate_prob will be used. Otherwise historical_wave is used.

Examples::

pim1 = cv.prior_immunity(vaccine='pfizer', days=[-30], prob=0.7)
pim2 = cv.prior_immunity(120, 0.05)

vaccinate

interventions.vaccinate(*args, **kwargs)

Wrapper function for vaccinate_prob() and vaccinate_num(). If the num_doses argument is used, will call vaccinate_num(); else, calls vaccinate_prob().

Examples::

vx1 = cv.vaccinate(vaccine='pfizer', days=30, prob=0.7)
vx2 = cv.vaccinate(vaccine='pfizer', num_doses=100)