def apply(self, sim): ''' Perform vaccination ''' t = sim.t if t < self.start_day: return elif self.end_day is not None and t > self.end_day: return # Check that there are still vaccines rel_t = t - self.start_day if rel_t < len(self.daily_vaccines): n_vaccines = sc.randround(self.daily_vaccines[rel_t] / sim.rescale_vec[t]) else: return vacc_probs = np.ones( sim.n ) # Begin by assigning equal vaccine weight (converted to a probability) to everyone if self.subtarget is not None: subtarget_inds, subtarget_vals = get_subtargets( self.subtarget, sim) vacc_probs[ subtarget_inds] = subtarget_vals # People being explicitly subtargeted # First dose # Don't give dose to people who have had at least one dose vacc_inds = cvu.true(self.vaccinations > 0) vacc_probs[vacc_inds] = 0.0 # Now choose who gets vaccinated and vaccinate them n_vaccines = min(n_vaccines, (vacc_probs != 0).sum()) all_vacc_inds = cvu.choose_w(probs=vacc_probs, n=n_vaccines, unique=True) # Choose who actually tests sim.results['new_doses'][t] += len(all_vacc_inds) self.vaccinations[all_vacc_inds] = 1 self.delay_days[all_vacc_inds] = self.delay self.first_dates[all_vacc_inds] = sim.t # Calculate the effect per person vacc_eff = self.cumulative[0] # Pull out corresponding effect sizes rel_sus_eff = 0.5 + 0.5 * self.rel_sus rel_symp_eff = 0.5 + 0.5 * self.rel_symp # Apply the vaccine to people #sim.people.rel_sus[all_vacc_inds] *= rel_sus_eff #sim.people.symp_prob[all_vacc_inds] *= rel_symp_eff sim.people.rel_sus[ all_vacc_inds] = self.orig_rel_sus[all_vacc_inds] * rel_sus_eff sim.people.symp_prob[ all_vacc_inds] = self.orig_symp_prob[all_vacc_inds] * rel_symp_eff all_vacc_inds2 = cvu.true( (self.vaccinations == 1) * (self.delay_days > 0) * (self.first_dates > 0) * (self.first_dates + self.delay_days == sim.t)) rel_sus_eff2 = self.rel_sus rel_symp_eff2 = self.rel_symp #sim.people.rel_sus[all_vacc_inds2] *= rel_sus_eff2 #sim.people.symp_prob[all_vacc_inds2] *= rel_symp_eff2 sim.people.rel_sus[ all_vacc_inds2] = self.orig_rel_sus[all_vacc_inds2] * rel_sus_eff2 sim.people.symp_prob[all_vacc_inds2] = self.orig_symp_prob[ all_vacc_inds2] * rel_symp_eff2 self.vaccinations[all_vacc_inds2] = 2 sim.results['new_doses'][t] += len(all_vacc_inds2)
def apply(self, sim): ''' Perform vaccination ''' if sim.t >= np.min(self.days): # Vaccinate people with their first dose vacc_inds = np.array( [], dtype=int) # Initialize in case no one gets their first dose for ind in find_day(self.days, sim.t, interv=self, sim=sim): vacc_probs = np.zeros(sim['pop_size']) unvacc_inds = sc.findinds(~sim.people.vaccinated) if self.subtarget is not None: subtarget_inds, subtarget_vals = get_subtargets( self.subtarget, sim) if len(subtarget_vals): vacc_probs[ subtarget_inds] = subtarget_vals # People being explicitly subtargeted else: vacc_probs[ unvacc_inds] = self.prob # Assign equal vaccination probability to everyone vacc_probs[cvu.true( sim.people.dead)] *= 0.0 # Do not vaccinate dead people vacc_inds = cvu.true(cvu.binomial_arr( vacc_probs)) # Calculate who actually gets vaccinated if len(vacc_inds): self.vaccinated[sim.t] = vacc_inds sim.people.flows['new_vaccinations'] += len(vacc_inds) sim.people.flows['new_vaccinated'] += len(vacc_inds) if self.p.interval is not None: next_dose_day = sim.t + self.p.interval if next_dose_day < sim['n_days']: self.second_dose_days[next_dose_day] = vacc_inds next_nab_day = sim.t + self.p.nab_interval if next_nab_day < sim['n_days']: self.first_dose_nab_days[next_nab_day] = vacc_inds else: self.first_dose_nab_days[sim.t] = vacc_inds # Also, if appropriate, vaccinate people with their second dose vacc_inds_dose2 = self.second_dose_days[sim.t] if vacc_inds_dose2 is not None: next_nab_day = sim.t + self.p.nab_interval if next_nab_day < sim['n_days']: self.second_dose_nab_days[next_nab_day] = vacc_inds_dose2 vacc_inds = np.concatenate((vacc_inds, vacc_inds_dose2), axis=None) sim.people.flows['new_vaccinations'] += len(vacc_inds_dose2) # Update vaccine attributes in sim if len(vacc_inds): sim.people.vaccinated[vacc_inds] = True sim.people.vaccine_source[vacc_inds] = self.index self.vaccinations[vacc_inds] += 1 self.vaccination_dates[vacc_inds] = sim.t # Update vaccine attributes in sim sim.people.vaccinations[vacc_inds] = self.vaccinations[ vacc_inds] # check whose nabs kick in today and then init_nabs for them! vaccine_nabs_first_dose_inds = self.first_dose_nab_days[sim.t] vaccine_nabs_second_dose_inds = self.second_dose_nab_days[sim.t] vaccine_nabs_inds = [ vaccine_nabs_first_dose_inds, vaccine_nabs_second_dose_inds ] for vaccinees in vaccine_nabs_inds: if vaccinees is not None: sim.people.date_vaccinated[vaccinees] = sim.t cvi.init_nab(sim.people, vaccinees, prior_inf=False) return