コード例 #1
0
    def apply(self, sim):
        t = sim.t
        if t < self.start_day:
            return
        elif self.end_day is not None and t > self.end_day:
            return

        adults = sim.people.age > 18
        adults_inds = sc.findinds(adults)
        screen_inds = cvu.choose(
            len(adults_inds),
            self.daily_screens)  # Who will we screen today - untargeted
        screen_inds = np.unique(screen_inds)

        screened_adult_inds = adults_inds[screen_inds]
        is_symptomatic = cvu.itruei(sim.people.symptomatic,
                                    screened_adult_inds)
        pos_screen = cvu.n_binomial(self.sensitivity, len(is_symptomatic))
        is_sym_pos = is_symptomatic[pos_screen]

        not_diagnosed = is_sym_pos[np.isnan(
            sim.people.date_diagnosed[is_sym_pos])]
        will_quar = cvu.n_binomial(self.prob_quar_after_fever,
                                   len(not_diagnosed))
        final_inds = not_diagnosed[will_quar]

        sim.people.quarantine(final_inds)
        sim.results['new_quarantined'][t] += len(final_inds)

        #print(f'{final_inds} put into quarantine by screening.')

        return
コード例 #2
0
    def apply(self, sim):
        '''Some of this code is also borrowed from interventions.test_prob'''
        t = sim.t
        if t < self.start_day:
            return
        elif self.end_day is not None and t > self.end_day:
            return

        #Find all agents that display COVID-like symptoms
        symp_notMitigate = sim.people.symptomatic * ~sim.people.diagnosed
        testRecorded = cvu.false(np.isnan(sim.people.date_tested))
        pendingTest = testRecorded[
            sim.t - sim.people.date_tested[testRecorded] < self.test_delay]
        symp_notMitigate[pendingTest] = False
        if self.ili_prev is None:
            covidLikeInds = cvu.true(symp_notMitigate)
        else:
            rel_t = t - self.start_day
            ili_indices = cvu.n_binomial(self.ili_prev[rel_t], sim['pop_size'])
            covidLikeInds = cvu.true(
                np.logical_or(ili_indices, symp_notMitigate))

        reportedInds = cvu.binomial_filter(self.symp_prob, covidLikeInds)

        #Quarantine and test the selected indices
        sim.people.quarantine(reportedInds)
        sim.people.test(reportedInds, self.test_sensitivity, 0.0,
                        self.test_delay, True)

        sim.results['new_tests'][t] += int(
            len(reportedInds) * sim['pop_scale'] / sim.rescale_vec[t]
        )  # If we're using dynamic scaling, we have to scale by pop_scale, not rescale_vec

        return
コード例 #3
0
    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]) # Correct for scaling that may be applied by rounding to the nearest number of tests
            if not (n_vaccines and np.isfinite(n_vaccines)): # If there are no doses today, abort early
                return
            else:
                if sim.rescale_vec[t] != sim['pop_scale']:
                    raise RuntimeError('bad rescale time')
        else:
            return

        vacc_probs = np.ones(sim.n) # Begin by assigning equal vaccine weight (converted to a probability) to everyone

        # Remove minors
        ppl = sim.people
        inds0 = cv.true(ppl.age <= 18)
        vacc_probs[inds0] *= 0

        # add age priority
        inds1 = cv.true(ppl.age >= self.age_priority)
        vacc_probs[inds1] *= 10

        # Handle scheduling
        # first dose:
        vacc_probs[self.vaccinations == 0] *= self.dose_priority[0]
        # time between first and second dose:
        no_dose = [sim.t < (d[0] + self.delay) if len(d) > 0 else False for d in self.vaccination_dates]
        vacc_probs[no_dose] *= 0
        # time available for second dose:
        second_dose = [sim.t >= (d[0] + self.delay) if len(d) > 0 else False for d in self.vaccination_dates]
        vacc_probs[second_dose] *= self.dose_priority[1]

        # Don't give dose 2 people who have had more than 1
        vacc_inds = cvu.true(self.vaccinations > 1)
        vacc_probs[vacc_inds] = 0.0

        # Now choose who gets vaccinated and vaccinate them
        n_vaccines = min(n_vaccines, (vacc_probs!=0).sum()) # Don't try to vaccinate more people than have nonzero vaccination probability
        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)

        # Did the vaccine take?
        vacc_take_inds = all_vacc_inds[np.logical_or(cvu.n_binomial(self.take_prob, len(all_vacc_inds)) & (self.vaccinations[all_vacc_inds] == 0),
                                           self.vaccine_take[all_vacc_inds] & (self.vaccinations[all_vacc_inds] == 1))]
        self.vaccine_take[vacc_take_inds] = True

        # Calculate the effect per person
        vacc_doses = self.vaccinations[vacc_take_inds]  # Calculate current doses
        eff_doses = np.minimum(vacc_doses, len(self.cumulative) - 1)  # Convert to a valid index
        vacc_eff = self.cumulative[eff_doses]  # Pull out corresponding effect sizes
        rel_trans_eff = (1.0 - vacc_eff) + vacc_eff * self.rel_trans
        rel_symp_eff = (1.0 - vacc_eff) + vacc_eff * self.rel_symp

        # Apply the vaccine to people
        sim.people.rel_trans[vacc_take_inds] = self.orig_rel_trans[vacc_take_inds]*rel_trans_eff
        sim.people.symp_prob[vacc_take_inds] = self.orig_symp_prob[vacc_take_inds]*rel_symp_eff

        self.vaccinations[all_vacc_inds] += 1
        for v_ind in all_vacc_inds:
            self.vaccination_dates[v_ind].append(sim.t)

        return