def test_two_step():
    """The max tracing index is a function of whether or not we are doing two step tracing
    """


    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        do_2_step=True
    )

    assert model.max_tracing_index == 2

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
    )

    assert model.max_tracing_index == 1
def test_household_propensity_app():

    simulation = hct.household_sim_contact_tracing(
    haz_rate_scale=0.2,
    household_haz_rate_scale=0.8,
    overdispersion=0.32,
    contact_tracing_success_prob=0.9,
    contact_trace_delay_par=1.5,
    infection_reporting_prob=0.2,
    contact_trace=True,
    starting_infections=1,
    prob_has_trace_app=1,
    hh_propensity_to_use_trace_app=0)

    # No households have the propensity to use the trace app
    assert simulation.nodes.node(1).has_contact_tracing_app is False

    simulation = hct.household_sim_contact_tracing(
    haz_rate_scale=0.2,
    household_haz_rate_scale=0.8,
    overdispersion=0.32,
    contact_tracing_success_prob=0.9,
    contact_trace_delay_par=1.5,
    infection_reporting_prob=0.2,
    contact_trace=True,
    starting_infections=1,
    prob_has_trace_app=1,
    hh_propensity_to_use_trace_app=1)

    # No households have the propensity to use the trace app
    assert simulation.nodes.node(1).has_contact_tracing_app is True
Esempio n. 3
0
def test_colour_edges_between_houses():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        prob_has_trace_app=1)

    model.new_household(new_household_number=1,
                        generation=1,
                        infected_by=None,
                        infected_by_node=None)

    node1 = model.nodes.node(1)

    model.new_infection(node_count=1, generation=1, household_id=1)

    model.node_count = 2

    model.new_outside_household_infection(infecting_node=node1,
                                          serial_interval=10)

    house1 = model.houses.household(1)
    house2 = model.houses.household(2)
    model.colour_node_edges_between_houses(house1, house2, "yellow")
    assert model.nodes.G.edges[1, 2]["colour"] == "yellow"
Esempio n. 4
0
def test_within_household_infection():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        prob_has_trace_app=1)

    model.new_household(new_household_number=1,
                        generation=1,
                        infected_by=None,
                        infected_by_node=None)

    model.new_infection(node_count=1, generation=1, household_id=1)

    node1 = model.nodes.node(1)
    house = model.houses.household(1)
    house.house_size = 2
    house.susceptibles = 1

    model.new_within_household_infection(infecting_node=node1,
                                         serial_interval=10)

    node2 = model.nodes.node(2)

    assert house.susceptibles == 0
    assert node1.spread_to == [2]
    assert node2.household_id == 1
    assert node2.serial_interval == 10
    assert node2.generation == 2
    assert model.nodes.G.edges[1, 2]["colour"] == "black"
    assert house.within_house_edges == [(1, 2)]
Esempio n. 5
0
def run_simulation(pars):

    # Unpack the parameters
    global_contact_reduction, infection_reporting_prob = pars

    # Get the corresponding hazard rate scale from the calibration dictionary
    haz_rate_scale = pairs_dict[infection_reporting_prob]

    # Configure the simulation
    simulation = hct.household_sim_contact_tracing(haz_rate_scale=haz_rate_scale,
                                                   household_haz_rate_scale=0.832824527,
                                                   contact_tracing_success_prob=0,
                                                   contact_trace_delay_par=0,
                                                   overdispersion=0.36,
                                                   infection_reporting_prob=infection_reporting_prob,
                                                   contact_trace=False,
                                                   reduce_contacts_by=global_contact_reduction,
                                                   starting_infections=5000)

    simulation.run_simulation(days_to_simulate)

    parameters = [
        infection_reporting_prob,
        global_contact_reduction
    ]
    return(parameters + simulation.inf_counts)
Esempio n. 6
0
def test_new_outside_household_infection():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        prob_has_trace_app=1)

    # household 1
    model.new_household(new_household_number=1,
                        generation=1,
                        infected_by=None,
                        infected_by_node=None)

    node1 = model.nodes.node(1)

    # infection 1
    model.new_infection(node_count=1, generation=1, household_id=1)

    model.new_outside_household_infection(infecting_node=node1,
                                          serial_interval=1)

    assert model.house_count == 2
    assert node1.spread_to == [2]
    assert model.nodes.G.has_edge(1, 2)
def test_two_step_index():

    simulation = hct.household_sim_contact_tracing(
    haz_rate_scale=0.2,
    household_haz_rate_scale=0.8,
    overdispersion=0.32,
    contact_tracing_success_prob=1,
    contact_trace_delay_par=0,
    infection_reporting_prob=0.2,
    contact_trace=True,
    reduce_contacts_by=[0, 0.1, 0.2, 0.3, 0.4, 0.5],
    starting_infections=1,
    prob_has_trace_app=1,
    hh_propensity_to_use_trace_app=1)

    simulation.run_simulation(0)

    simulation.new_outside_household_infection(
        infecting_node=simulation.nodes.node(1),
        serial_interval=0
        )
    simulation.new_outside_household_infection(
        infecting_node=simulation.nodes.node(2),
        serial_interval=0
        )

    simulation.isolate_household(simulation.houses.household(1))

    simulation.propagate_contact_tracing(simulation.houses.household(1))
    simulation.propagate_contact_tracing(simulation.houses.household(2))

    assert simulation.houses.household(1).contact_tracing_index == 0
    assert simulation.houses.household(2).contact_tracing_index == 1
    assert simulation.houses.household(3).contact_tracing_index == 2
def test_household_not_uptake_isolation():
    """Sets up a model where the households will not uptake isolation, attempts to isolate a household
    and checks that the household does not uptake the isolation
    """

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.8,
        household_haz_rate_scale=1,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=10,
        hh_prob_will_take_up_isolation=0
    )

    model.isolate_household(model.houses.household(1))

    assert model.houses.household(1).isolated is False
    assert model.houses.household(1).contact_traced is True
    
    # unpack the generator
    hh_node_list = [node for node in model.houses.household(1).nodes()]
    
    assert hh_node_list[0].isolated is False
Esempio n. 9
0
def test_new_household():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
    )

    model.time = 100

    model.new_household(new_household_number=10,
                        generation=5,
                        infected_by=6,
                        infected_by_node=3)

    house = model.houses.household(10)

    assert house.size in [1, 2, 3, 4, 5, 6]
    assert house.time == 100
    assert house.size - 1 == house.susceptibles
    assert house.generation == 5
    assert house.infected_by_id == 6
    assert house.infected_by_node == 3
def test_default_uptake_isolation():
    # tests that the default value for uptake isolation is 1, otherwise households never uptake isolation

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.8,
        household_haz_rate_scale=1,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        hh_prob_propensity_to_leave_isolation=0,
        prob_has_trace_app=0.0,
        starting_infections=1,
    )

    model.isolate_household(model.houses.household(1))

    assert model.houses.household(1).isolated is True
    assert model.houses.household(1).isolated is True

    nodes_in_hh = [node for node in model.houses.household(1).nodes()]
    node0 = nodes_in_hh[0]

    assert node0.isolated is True
    assert node0.contact_traced is True
def test_update_adherence_to_isolation_manually():
    """Isolates a household, checks the nodes are isolated, runs the update adherence
    method with prob 1 and checks that the nodes are not adhering
    """

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.803782,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=10,
        hh_prob_propensity_to_leave_isolation=1,
        leave_isolation_prob=0
    )

    # isolate a household
    # current leave isolation prob is 0, so it shouldn't have left
    model.isolate_household(model.houses.household(1))

    assert model.nodes.node(1).isolated is True

    # set the leave isolation probability to 1
    model.leave_isolation_prob = 1

    model.update_adherence_to_isolation()

    assert model.nodes.node(1).isolated is False
def test_nodes_inherit_contact_traced_status():
    # If a household has been contact traced nodes should inherit this status
    # new household, contact trace it, new infection, assert new infection has contact traced status

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.8,
        household_haz_rate_scale=1,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=1,
    )

    # Give the household a size of at least 2
    model.houses.household(1).house_size = 6

    model.isolate_household(model.houses.household(1))

    model.new_within_household_infection(model.nodes.node(1), serial_interval = 2)

    assert model.nodes.node(2).contact_traced == True
def test_leave_isolation():
    """Give all household the propensity to not adhere, and sets the probability to not adhere to 1,
    runs the leave isolation method and checks that the node immediately decides to not adhere
    """

    # All households have the propensity
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        test_before_propagate_tracing=False,
        hh_prob_propensity_to_leave_isolation=1,
        leave_isolation_prob=1)

    # set node 1 to the isolation status
    model.nodes.node(1).isolated = True

    # see if the node leaves isolation over the next 50 days
    model.decide_if_leave_isolation(node=model.nodes.node(1))

    assert model.nodes.node(1).isolated is False
Esempio n. 14
0
def test_is_app_traced():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        prob_has_trace_app=1)

    # household 1
    model.new_household(new_household_number=1,
                        generation=1,
                        infected_by=None,
                        infected_by_node=None)

    # infection 1
    model.new_infection(node_count=1, generation=1, household_id=1)

    # household 2
    model.new_household(new_household_number=2,
                        generation=2,
                        infected_by=1,
                        infected_by_node=1)

    # infection 2
    model.new_infection(node_count=2, generation=2, household_id=2)

    # add an edge between the infections
    model.nodes.G.add_edge(1, 2)
    assert model.is_edge_app_traced((1, 2))
Esempio n. 15
0
def run_simulation(repeat):

    npr.seed(None)

    infection_reporting_prob = npr.choice([0.1, 0.2, 0.3, 0.4, 0.5])

    haz_rate_scale = pairs_dict[infection_reporting_prob]

    contact_tracing_success_prob = npr.uniform(0.7, 0.95)

    contact_trace_delay_par = npr.uniform(1.5, 2.5)

    # Select scenario as desired

    # Full prior
    reduce_contacts_by = npr.uniform(0, 0.9)
    # Scenario A
    # reduce_contacts_by=(0.68, 0.83, 0.83, 0.821, 0.846, 0.836)
    # Scenario B
    #reduce_contacts_by=(0.638, 0.786, 0.76, 0.733, 0.765, 0.755)
    # Scenario C
    #reduce_contacts_by=(0.628, 0.76, 0.685, 0.632, 0.668, 0.668)
    # Scenario D
    #reduce_contacts_by=(0.561, 0.698, 0.61, 0.543, 0.589, 0.577)
    # Scenario E
    reduce_contacts_by = (0.413, 0.544, 0.393, 0.278, 0.348, 0.315)

    do_2_step = npr.choice([True, False])

    backwards_trace = npr.choice([True, False])

    prob_has_trace_app = npr.uniform(0, 0.5)

    simulation = hct.household_sim_contact_tracing(
        haz_rate_scale=haz_rate_scale,
        household_haz_rate_scale=0.832824527,
        contact_tracing_success_prob=contact_tracing_success_prob,
        contact_trace_delay_par=contact_trace_delay_par,
        overdispersion=0.36,
        infection_reporting_prob=infection_reporting_prob,
        contact_trace=True,
        reduce_contacts_by=reduce_contacts_by,
        do_2_step=do_2_step,
        backwards_trace=backwards_trace,
        test_before_propagate_tracing=False,
        prob_has_trace_app=prob_has_trace_app,
        starting_infections=starting_infections)

    simulation.run_simulation(days_to_simulate, stop_when_5000_infections=True)

    parameters = [
        haz_rate_scale, infection_reporting_prob, contact_tracing_success_prob,
        contact_trace_delay_par, reduce_contacts_by, do_2_step,
        prob_has_trace_app, backwards_trace
    ]

    return (parameters + [simulation.end_reason, simulation.day_extinct] +
            simulation.inf_counts)
Esempio n. 16
0
def run_simulation(repeat):

    infection_reporting_prob = npr.choice([0.1, 0.2, 0.3, 0.4, 0.5])

    haz_rate_scale = pairs_dict[infection_reporting_prob]

    contact_tracing_success_prob = npr.uniform(0.7, 0.95)

    contact_trace_delay_par = npr.uniform(1.5, 2.5)

    reduce_contacts_by = npr.uniform(0.0, 0.9)

    # Scenario A
    # reduce_contacts_by=(0.68, 0.83, 0.83, 0.821, 0.846, 0.836)
    # Scenario B
    # reduce_contacts_by=(0.638, 0.786, 0.76, 0.733, 0.765, 0.755)
    # Scenario C
    # reduce_contacts_by=(0.628, 0.76, 0.685, 0.632, 0.668, 0.668)
    #Scenario D
    # reduce_contacts_by=(0.561, 0.698, 0.61, 0.543, 0.589, 0.577)
    # Scenario E
    # reduce_contacts_by = (0.413, 0.544, 0.393, 0.278, 0.348, 0.315)

    #do_2_step = npr.choice([True, False])

    prob_has_trace_app = npr.uniform(0, 0.5)

    backwards_trace = True

    probable_infections_need_test = True

    backwards_tracing_time_limit = npr.choice(list(range(7, 22)))

    simulation = hct.uk_model(
        haz_rate_scale=haz_rate_scale,
        household_haz_rate_scale=0.77729,
        contact_tracing_success_prob=contact_tracing_success_prob,
        contact_trace_delay_par=contact_trace_delay_par,
        overdispersion=0.36,
        infection_reporting_prob=infection_reporting_prob,
        contact_trace=True,
        reduce_contacts_by=reduce_contacts_by,
        test_before_propagate_tracing=True,
        probable_infections_need_test=probable_infections_need_test,
        backwards_trace=backwards_trace,
        backwards_tracing_time_limit=backwards_tracing_time_limit,
        prob_has_trace_app=prob_has_trace_app,
        starting_infections=starting_infections)

    simulation.run_simulation(days_to_simulate)

    parameters = [
        haz_rate_scale, infection_reporting_prob, contact_tracing_success_prob,
        contact_trace_delay_par, reduce_contacts_by, prob_has_trace_app,
        backwards_trace, probable_infections_need_test
    ]
    return (parameters + simulation.inf_counts)
def app_based_tracing_model():
    return hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        prob_has_trace_app=1)
Esempio n. 18
0
def test_hh_prob_leave_iso_default():
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        test_before_propagate_tracing=False)
    assert model.hh_propensity_to_leave_isolation() == 0
Esempio n. 19
0
def test_overide_testing_delay():

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        test_before_propagate_tracing=False)

    assert model.testing_delay() == 0
def basic_model():
    return hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        do_2_step=True,
        test_before_propagate_tracing=True
    )
def run_simulation(repeat):

    infection_reporting_prob = npr.choice([0.1, 0.2, 0.3, 0.4, 0.5])

    haz_rate_scale = pairs_dict[infection_reporting_prob]

    contact_tracing_success_prob = npr.uniform(0.7, 0.95)

    contact_trace_delay_par = npr.uniform(1.5, 2.5)

    reduce_contacts_by = npr.uniform(0.0, 0.9)

    do_2_step = npr.choice([True, False])

    prob_has_trace_app = npr.uniform(0, 0.5)
    
    hh_prob_will_take_up_isolation = npr.uniform(0.5, 1)

    prob_household_prop_not_adhere = npr.uniform(0.0, 0.5)

    prob_not_adhere = npr.uniform(0.01, 0.05)

    simulation = hct.household_sim_contact_tracing(haz_rate_scale=haz_rate_scale,
                                                    household_haz_rate_scale=0.832824527,
                                                     contact_tracing_success_prob=contact_tracing_success_prob,
                                                     contact_trace_delay_par=contact_trace_delay_par,
                                                     overdispersion=0.36,
                                                     infection_reporting_prob=infection_reporting_prob,
                                                     contact_trace=True,
                                                     reduce_contacts_by=reduce_contacts_by,
                                                     do_2_step=do_2_step,
                                                     test_before_propagate_tracing=False,
                                                     prob_has_trace_app=prob_has_trace_app,
                                                     starting_infections=starting_infections,
                                                     hh_prob_will_take_up_isolation=hh_prob_will_take_up_isolation,
                                                     hh_prob_propensity_to_leave_isolation=prob_household_prop_not_adhere,
                                                     leave_isolation_prob=prob_not_adhere)

    simulation.run_simulation(days_to_simulate)

    parameters = [
        haz_rate_scale,
        infection_reporting_prob,
        contact_tracing_success_prob,
        contact_trace_delay_par,
        reduce_contacts_by,
        do_2_step,
        prob_has_trace_app,
        hh_prob_will_take_up_isolation,
        prob_household_prop_not_adhere,
        prob_not_adhere
    ]
    return(parameters + simulation.inf_counts)
Esempio n. 22
0
def run_simulation(repeat):

    infection_reporting_prob = npr.choice([0.1, 0.2, 0.3, 0.4, 0.5])

    haz_rate_scale = pairs_dict[infection_reporting_prob]

    contact_tracing_success_prob = npr.uniform(0.7, 0.95)

    contact_trace_delay_par = npr.uniform(1.5, 2.5)

    reduce_contacts_by = npr.uniform(0.0, 0.9)

    test_delay_mean = npr.uniform(1, 2)

    # Scenario A
    # reduce_contacts_by=(0.68, 0.83, 0.83, 0.821, 0.846, 0.836)
    # Scenario B
    reduce_contacts_by = (0.638, 0.786, 0.76, 0.733, 0.765, 0.755)
    # Scenario C
    # reduce_contacts_by=(0.628, 0.76, 0.685, 0.632, 0.668, 0.668)
    #Scenario D
    # reduce_contacts_by=(0.561, 0.698, 0.61, 0.543, 0.589, 0.577)
    # Scenario E
    # reduce_contacts_by = (0.413, 0.544, 0.393, 0.278, 0.348, 0.315)

    do_2_step = npr.choice([True, False])

    prob_has_trace_app = npr.uniform(0, 0.5)

    simulation = hct.household_sim_contact_tracing(
        haz_rate_scale=haz_rate_scale,
        household_haz_rate_scale=0.832824527,
        contact_tracing_success_prob=contact_tracing_success_prob,
        contact_trace_delay_par=contact_trace_delay_par,
        overdispersion=0.36,
        infection_reporting_prob=infection_reporting_prob,
        contact_trace=True,
        reduce_contacts_by=reduce_contacts_by,
        do_2_step=do_2_step,
        test_before_propagate_tracing=True,
        test_delay_mean=test_delay_mean,
        prob_has_trace_app=prob_has_trace_app,
        starting_infections=starting_infections)

    simulation.run_simulation(days_to_simulate)

    parameters = [
        haz_rate_scale, infection_reporting_prob, contact_tracing_success_prob,
        contact_trace_delay_par, reduce_contacts_by, do_2_step,
        prob_has_trace_app, test_delay_mean
    ]
    return (parameters + simulation.inf_counts)
Esempio n. 23
0
def test_two_step():
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        do_2_step=True)

    assert model.max_tracing_index == 2

    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
    )

    assert model.max_tracing_index == 1
Esempio n. 24
0
def test_household_haz_rate_scale():

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.8,
        # household_haz_rate_scale=0
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=10,
        hh_prob_propensity_to_leave_isolation=1)

    # check the default value which is 0.77729
    assert model.household_haz_rate_scale == 0.77729

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.8,
        household_haz_rate_scale=1,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=10,
        hh_prob_propensity_to_leave_isolation=1)

    assert model.household_haz_rate_scale == 1
def test_hh_prob_leave_iso():
    """Tests that the values are correctly assigned
    """
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        test_before_propagate_tracing=False,
        hh_prob_propensity_to_leave_isolation=1)
    assert model.hh_propensity_to_leave_isolation() == True
Esempio n. 26
0
def simple_model():
    simulation = hct.uk_model(haz_rate_scale=0.2,
                              household_haz_rate_scale=0.8,
                              overdispersion=0.32,
                              contact_tracing_success_prob=1,
                              contact_trace_delay_par=0,
                              infection_reporting_prob=0.2,
                              contact_trace=True,
                              reduce_contacts_by=[0, 0.1, 0.2, 0.3, 0.4, 0.5],
                              starting_infections=1,
                              test_before_propagate_tracing=False,
                              prob_has_trace_app=1,
                              hh_propensity_to_use_trace_app=1)
    return simulation
def test_update_adherence_to_isolation():
    """Runs a simulation for a bit, and records the number of nodes in isolation.
    Performs the method that updates whether a node is adhering to isolation, and
    then checks that the number of nodes in isolation has decreased.
    """

    # set up a model
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.803782,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.7,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.5,
        contact_trace=True,
        reduce_contacts_by=0.0,
        do_2_step=False,
        test_before_propagate_tracing=False,
        prob_has_trace_app=0.0,
        starting_infections=10,
        hh_prob_propensity_to_leave_isolation=1,
        leave_isolation_prob=0.1
    )

    # let a simulation run for a bit
    model.run_simulation(20)

    # record how many nodes are currently isolated
    initially_isolated_ids = [
        node.node_id for node in model.nodes.all_nodes()
        if node.isolated
        and not node.recovered
        and node.household().propensity_to_leave_isolation
    ]

    # update the isolation 10 
    for _ in range(10):
        model.update_adherence_to_isolation()

    # get the list of nodes in isolation
    secondary_isolated_ids = [
        node.node_id for node in model.nodes.all_nodes()
        if node.isolated
        and not node.recovered
        and node.household().propensity_to_leave_isolation
    ]

    # check that the number of nodes in isolation has decreased
    assert initially_isolated_ids != secondary_isolated_ids
def test_hh_has_propensity_attr():
    """Checks that some houses have the propensity to not adhere
    """
    model = hct.household_sim_contact_tracing(
        haz_rate_scale=0.805,
        household_haz_rate_scale=0.8,
        contact_tracing_success_prob=0.66,
        contact_trace_delay_par=2,
        overdispersion=0.36,
        infection_reporting_prob=0.8,
        contact_trace=True,
        test_before_propagate_tracing=False,
        hh_prob_propensity_to_leave_isolation=0.5)

    assert model.houses.household(1).propensity_to_leave_isolation in (True, False)
def test_per_household_contact_reductions():

    simulation = hct.household_sim_contact_tracing(
    haz_rate_scale=0.2,
    household_haz_rate_scale=0.8,
    overdispersion=0.32,
    contact_tracing_success_prob=0.9,
    contact_trace_delay_par=1.5,
    infection_reporting_prob=0.2,
    contact_trace=True,
    reduce_contacts_by=[0, 0.1, 0.2, 0.3, 0.4, 0.5],
    starting_infections=1,
    prob_has_trace_app=1,
    hh_propensity_to_use_trace_app=1)

    assert simulation.get_contact_rate_reduction(4) == 0.3
def test_two_step_index_update():

    simulation = hct.household_sim_contact_tracing(
    haz_rate_scale=0.2,
    household_haz_rate_scale=0.8,
    overdispersion=0.32,
    contact_tracing_success_prob=1,
    contact_trace_delay_par=0,
    infection_reporting_prob=0.2,
    contact_trace=True,
    reduce_contacts_by=[0, 0.1, 0.2, 0.3, 0.4, 0.5],
    test_before_propagate_tracing=False,
    starting_infections=1,
    prob_has_trace_app=1,
    hh_propensity_to_use_trace_app=1)

    simulation.run_simulation(0)

    simulation.new_outside_household_infection(
        infecting_node=simulation.nodes.node(1),
        serial_interval=0
        )
    simulation.new_outside_household_infection(
        infecting_node=simulation.nodes.node(2),
        serial_interval=0
        )

    simulation.isolate_household(simulation.houses.household(1))

    simulation.propagate_contact_tracing(simulation.houses.household(1))
    simulation.propagate_contact_tracing(simulation.houses.household(2))

    # Symptom onset has now happened, therefore it should be an index 1 case
    # given there are no teting delays
    simulation.update_isolation()

    simulation.update_contact_tracing_index()

    simulation.nodes.node(2).symptom_onset_time=0

    simulation.update_contact_tracing_index()

    assert simulation.houses.household(1).contact_tracing_index == 0
    assert simulation.houses.household(2).contact_tracing_index == 0
    assert simulation.houses.household(3).contact_tracing_index == 1