Example #1
0
    def __init__(self,
                 npts,
                 symptomatic_prob=0.9,
                 asymptomatic_prob=0.01,
                 trace_prob=1.0,
                 test_sensitivity=1.0):
        """

        Args:
            self:
            symptomatic_prob:
            trace_prob:

        Returns:

        """
        super().__init__()
        self.symptomatic_prob = symptomatic_prob
        self.asymptomatic_prob = asymptomatic_prob
        self.trace_prob = trace_prob  # Probability that identified contacts get tested
        self.test_sensitivity = test_sensitivity

        # Instantiate the results to track
        self.results['n_tested'] = cv.Result('Number tested', npts=npts)
        self.results['n_diagnosed'] = cv.Result('Number diagnosed', npts=npts)
        self.results['cum_tested'] = cv.Result('Cumulative number tested',
                                               npts=npts)
        self.results['cum_diagnosed'] = cv.Result(
            'Cumulative number diagnosed', npts=npts)

        self.scheduled_tests = set(
        )  # Track UIDs of people that are guaranteed to be tested at the next step
        return
Example #2
0
 def finalize(self, sim, *args, **kwargs):
     self.results['cum_tested'] = cv.Result(
         'Cumulative number tested',
         values=pl.cumsum(self.results['n_tested'].values))
     self.results['cum_diagnosed'] = cv.Result(
         'Cumulative number diagnosed',
         values=pl.cumsum(self.results['n_diagnosed'].values))
     sim.results.update(self.results)
     return
Example #3
0
    def __init__(self, npts, n_tests, n_positive):
        """

        Args:
            npts: Number of simulation timepoints
            n_tests: Number of tests per day. If this is a scalar or an array with length less than npts, it will be zero-padded
            n_positive: Number of positive tests (confirmed cases) per day. If this is a scalar or an array with length less than npts, it will be zero-padded
        """

        super().__init__()
        self.n_tests = np.pad(sc.promotetoarray(n_tests),
                              (0, max(0, npts - len(n_tests))))
        self.n_positive = np.pad(sc.promotetoarray(n_positive),
                                 (0, max(0, npts - len(n_positive))))
        self.results['n_tested'] = cv.Result('Number tested', npts=npts)
        self.results['n_diagnosed'] = cv.Result('Number diagnosed', npts=npts)
Example #4
0
    def __init__(self,
                 npts,
                 daily_tests,
                 sympt_test=100.0,
                 trace_test=1.0,
                 sensitivity=1.0):
        super().__init__()

        self.daily_tests = daily_tests  #: Should be a list of length matching time
        self.sympt_test = sympt_test
        self.trace_test = trace_test
        self.sensitivity = sensitivity

        self.results['n_diagnosed'] = cv.Result('Number diagnosed', npts=npts)
        self.results['cum_diagnosed'] = cv.Result(
            'Cumulative number diagnosed', npts=npts)

        return
Example #5
0
def test_base():
    sc.heading('Testing base.py sim...')

    json_path = 'base_tests.json'
    sim_path = 'base_tests.sim'

    # Create a small sim for later use
    sim = cv.Sim(pop_size=100, verbose=verbose)
    sim.run()

    # Check setting invalid key
    with pytest.raises(sc.KeyNotFoundError):
        po = cv.ParsObj(pars={'a': 2, 'b': 3})
        po.update_pars({'c': 4})

    # Printing result
    r = cv.Result()
    print(r)
    print(r.npts)

    # Day and date conversion
    daystr = '2020-04-04'
    sim.day(daystr)
    sim.day(sc.readdate(daystr))
    with pytest.raises(ValueError):
        sim.day('not a date')
    sim.date(34)
    sim.date([34, 54])
    sim.date(34, 54, as_date=True)

    # BaseSim methods
    sim.copy()
    sim.export_results(filename=json_path)
    sim.export_pars(filename=json_path)
    sim.shrink(in_place=False)
    for keep_people in [True, False]:
        sim.save(filename=sim_path, keep_people=keep_people)
    cv.Sim.load(sim_path)

    # Tidy up
    remove_files(json_path, sim_path)

    return
Example #6
0
def test_base():
    sc.heading('Testing base.py...')

    json_path = 'base_tests.json'
    sim_path = 'base_tests.sim'

    # Create a small sim for later use
    sim = cv.Sim(pop_size=100, verbose=verbose)
    sim.run()

    # Check setting invalid key
    with pytest.raises(sc.KeyNotFoundError):
        po = cv.ParsObj(pars={'a': 2, 'b': 3})
        po.update_pars({'c': 4})

    # Printing result
    r = cv.Result()
    print(r)
    print(r.npts)

    # Day and date conversion
    daystr = '2020-04-04'
    sim.day(daystr)
    sim.day(sc.readdate(daystr))
    with pytest.raises(ValueError):
        sim.day('not a date')
    sim.date(34)
    sim.date([34, 54])
    sim.date(34, 54, as_date=True)

    # BaseSim methods
    sim.copy()
    sim.export_results(filename=json_path)
    sim.export_pars(filename=json_path)
    sim.shrink(in_place=False)
    for keep_people in [True, False]:
        sim.save(filename=sim_path, keep_people=keep_people)
    cv.Sim.load(sim_path)

    # BasePeople methods
    ppl = sim.people
    ppl.get(['susceptible', 'infectious'])
    ppl.keys(which='all_states')
    ppl.index()
    ppl.resize(pop_size=200)
    ppl.to_df()
    ppl.to_arr()
    ppl.person(50)
    people = ppl.to_people()
    ppl.from_people(people)
    with pytest.raises(sc.KeyNotFoundError):
        ppl.make_edgelist([{'invalid_key': [0, 1, 2]}])

    # Contacts methods
    contacts = ppl.contacts
    df = contacts['a'].to_df()
    ppl.remove_duplicates(df)
    with pytest.raises(sc.KeyNotFoundError):
        contacts['invalid_key']
    contacts.values()
    len(contacts)

    # Transmission tree methods
    ppl.transtree.make_targets()
    ppl.make_detailed_transtree()
    ppl.transtree.plot()
    ppl.transtree.animate(animate=False)

    # Tidy up
    remove_files(json_path, sim_path)

    return
Example #7
0
def test_base():
    sc.heading('Testing base.py...')

    json_path = 'base_tests.json'
    sim_path  = 'base_tests.sim'

    # Create a small sim for later use
    sim = cv.Sim(pop_size=100, verbose=verbose)
    sim.run()

    # Check setting invalid key
    with pytest.raises(sc.KeyNotFoundError):
        po = cv.ParsObj(pars={'a':2, 'b':3})
        po.update_pars({'c':4})

    # Printing result
    r = cv.Result()
    print(r)
    print(r.npts)

    # Day and date conversion
    daystr = '2020-04-04'
    sim.day(daystr)
    sim.day(sc.readdate(daystr))
    with pytest.raises(ValueError):
        sim.day('not a date')
    sim.date(34)
    sim.date([34, 54])
    sim.date(34, 54, as_date=True)

    # BaseSim methods
    sim.copy()
    sim.export_results(filename=json_path)
    sim.export_pars(filename=json_path)
    sim.shrink(in_place=False)
    for keep_people in [True, False]:
        sim.save(filename=sim_path, keep_people=keep_people)
    cv.Sim.load(sim_path)

    # BasePeople methods
    ppl = sim.people
    ppl.get(['susceptible', 'infectious'])
    ppl.keys()
    ppl.person_keys()
    ppl.state_keys()
    ppl.date_keys()
    ppl.dur_keys()
    ppl.indices()
    ppl._resize_arrays(pop_size=200) # This only resizes the arrays, not actually create new people
    ppl._resize_arrays(pop_size=100) # Change back
    ppl.to_df()
    ppl.to_arr()
    ppl.person(50)
    people = ppl.to_people()
    ppl.from_people(people)
    ppl.make_edgelist([{'new_key':[0,1,2]}])
    ppl.brief()

    # Contacts methods
    contacts = ppl.contacts
    df = contacts['a'].to_df()
    ppl.remove_duplicates(df)
    with pytest.raises(sc.KeyNotFoundError):
        contacts['invalid_key']
    contacts.values()
    len(contacts)
    print(contacts)
    print(contacts['a'])

    # Layer methods
    hospitals_layer = cv.Layer()
    contacts.add_layer(hospitals=hospitals_layer)
    contacts.pop_layer('hospitals')
    df = hospitals_layer.to_df()
    hospitals_layer.from_df(df)

    # Tidy up
    remove_files(json_path, sim_path)

    return