Ejemplo n.º 1
0
def test_snapshot():
    sc.heading('Testing snapshot analyzer')
    sim = cv.Sim(pars, analyzers=cv.snapshot('2020-04-04', '2020-04-14'))
    sim.run()
    snapshot = sim.get_analyzer()
    people1 = snapshot.snapshots[0]  # Option 1
    people2 = snapshot.snapshots['2020-04-04']  # Option 2
    people3 = snapshot.get('2020-04-14')  # Option 3
    people4 = snapshot.get(34)  # Option 4
    people5 = snapshot.get()  # Option 5

    assert people1 == people2, 'Snapshot options should match but do not'
    assert people3 != people4, 'Snapshot options should not match but do'
    return people5
Ejemplo n.º 2
0
def test_import1variant(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test introducing a new variant partway through a sim')

    variant_pars = {
        'rel_beta': 1.5,
    }
    pars = {'beta': 0.01}
    variant = cv.variant(variant_pars,
                         days=1,
                         n_imports=20,
                         label='Variant 2: 1.5x more transmissible')
    sim = cv.Sim(use_waning=True,
                 pars=pars,
                 variants=variant,
                 analyzers=cv.snapshot(30, 60),
                 **pars,
                 **base_pars)
    sim.run()

    return sim
Ejemplo n.º 3
0
def test_import1strain(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test introducing a new strain partway through a sim')

    strain_pars = {
        'rel_beta': 1.5,
    }
    pars = {'beta': 0.01}
    strain = cv.strain(strain_pars,
                       days=1,
                       n_imports=20,
                       label='Strain 2: 1.5x more transmissible')
    sim = cv.Sim(use_waning=True,
                 pars=pars,
                 strains=strain,
                 analyzers=cv.snapshot(30, 60),
                 **pars,
                 **base_pars)
    sim.run()

    return sim
Ejemplo n.º 4
0
'''
Test the people snapshot analyzer.
'''

import covasim as cv

sim = cv.Sim(analyzers=cv.snapshot('2020-04-04', '2020-04-14'))
sim.run()
snapshot = sim['analyzers'][0]
people = snapshot.snapshots[0]  # Option 1
people = snapshot.snapshots['2020-04-04']  # Option 2
people = snapshot.get('2020-04-14')  # Option 3
people = snapshot.get(34)  # Option 4
Ejemplo n.º 5
0
    return sim


def test_efficacy(do_plot=False, do_show=True, do_save=False):
    sc.heading('Test the efficacy of infection against reinfection')

    pars = sc.mergedicts(base_pars, {
        'beta': 0.015,
        'pop_infected': 100,
        'pop_size': 50_000,
        'n_days': 180,
    })
    interventions = [cv.change_beta([30, 90], [0.3, 1])]
    sim = cv.Sim(
        use_waning=True,
        analyzers=cv.snapshot(90),
        pars=pars,
        interventions=interventions,
    )
    sim.run()

    # Number of people exposed during the first wave:
    snap = sim.get_analyzer()
    d1 = 90
    people0 = snap.get(d1)
    people1 = sim.people

    trial_arm_size = len(cvu.true(people0.n_infections > 0))
    control_arm_size = len(cvu.true(people0.n_infections == 0))

    trial_not_infected = len(
Ejemplo n.º 6
0
'''
Confirm that with default settings, all analyzers can be exported as JSONs.
'''

import sciris as sc
import covasim as cv

datafile = sc.thisdir(__file__, aspath=True).parent / 'example_data.csv'

# Create and runt he sim
sim = cv.Sim(analyzers=[
    cv.snapshot(days='2020-04-04'),
    cv.age_histogram(),
    cv.daily_age_stats(),
    cv.daily_stats()
],
             datafile=datafile)
sim.run()

# Compute extra analyzers
tt = sim.make_transtree()
fit = sim.compute_fit()

# Construct list of all analyzers
analyzers = sim['analyzers'] + [tt, fit]

# Make jsons
jsons = {}
for an in analyzers:
    print(f'Working on analyzer {an.label}...')
    jsons[an.label] = an.to_json()