コード例 #1
0
def test__seed_with_age_profile(selector, ):
    geography = Geography.from_file(filter_key={"super_area": ["E02004940"]})
    demography = Demography.for_geography(geography)
    for area in geography.areas:
        area.populate(demography)

    seed = InfectionSeed(super_areas=geography.super_areas,
                         selector=selector,
                         age_profile={
                             '0-9': 0.,
                             '10-39': 1.,
                             '40-100': 0.
                         })

    seed.unleash_virus(100)

    should_not_infected = [
        person for super_area in geography.super_areas
        for person in super_area.people
        if person.infected and (person.age < 10 or person.age >= 40)
    ]

    assert len(should_not_infected) == 0

    should_infected = [
        person for super_area in geography.super_areas
        for person in super_area.people
        if person.infected and (person.age >= 10 and person.age < 40)
    ]

    assert len(should_infected) == 100
コード例 #2
0
def test_box_full_run(simulator_box, selector):
    seed = InfectionSeed(
        simulator_box.world.boxes,
        selector,
    )
    seed.unleash_virus(10, box_mode=True)
    simulator_box.run()
コード例 #3
0
def test__full_run(dummy_world, selector):
    world = dummy_world
    # restore health status of people
    for person in world.people:
        person.health_information = None
        person.susceptibility = 1.0
        person.dead = False
    leisure_instance = leisure.generate_leisure_for_world(
        world=world,
        list_of_leisure_groups=[
            "pubs",
            "cinemas",
            "groceries",
            "household_visits",
            "care_home_visits",
        ],
    )
    leisure_instance.distribute_social_venues_to_households(world.households)
    interaction = Interaction.from_file()
    policies = Policies.from_file()
    sim = Simulator.from_file(
        world=world,
        interaction=interaction,
        infection_selector=selector,
        config_filename=test_config,
        leisure=leisure_instance,
        policies=policies,
        save_path=None,
    )
    seed = InfectionSeed(sim.world.super_areas, selector)
    seed.unleash_virus(1)
    sim.run()
コード例 #4
0
def test__infection_is_isolated(selector):
    geography = Geography.from_file({"area": ["E00002559"]})
    world = generate_world_from_geography(geography, include_households=True)
    interaction = Interaction.from_file()
    infection_seed = InfectionSeed(world.super_areas, selector)
    n_cases = 5
    infection_seed.unleash_virus(
        n_cases)  # play around with the initial number of cases
    policies = Policies([])
    simulator = Simulator.from_file(
        world=world,
        interaction=interaction,
        infection_selector=selector,
        config_filename=pathlib.Path(__file__).parent.absolute() /
        "interaction_test_config.yaml",
        leisure=None,
        policies=policies,
        save_path=None,
    )
    infected_people = [person for person in world.people if person.infected]
    assert len(infected_people) == 5
    infected_households = []
    for household in world.households:
        infected = False
        for person in household.people:
            if person.infected:
                infected = True
                break
        if infected:
            infected_households.append(household)
    assert len(infected_households) <= 5
    simulator.run()
    for person in world.people:
        if not (person.residence.group in infected_households):
            assert not person.infected and person.susceptible
コード例 #5
0
def run_simulator(selector):
    world = create_world()
    world.to_hdf5("./checkpoint_world.hdf5")
    # restore health status of people
    for person in world.people:
        person.health_information = None
        person.susceptibility = 1.0
        person.dead = False
    interaction = Interaction.from_file()
    policies = Policies([])
    sim = Simulator.from_file(
        world=world,
        interaction=interaction,
        infection_selector=selector,
        config_filename=test_config,
        leisure=None,
        policies=policies,
        save_path="tests",
    )
    seed = InfectionSeed(sim.world.super_areas, selector)
    seed.unleash_virus(20)
    sim.run()
    return sim
コード例 #6
0
ファイル: test_logger.py プロジェクト: sadielbartholomew/JUNE
def create_sim(world, interaction, selector):

    leisure_instance = leisure.generate_leisure_for_config(
        world=world, config_filename=test_config)
    leisure_instance.distribute_social_venues_to_households(world.households)
    policies = Policies([
        Quarantine(n_days=5),
        Quarantine(n_days=10),
        CloseLeisureVenue(start_time="2020-3-1",
                          end_time="2020-3-30",
                          venues_to_close=['pub', 'cinema'])
    ])
    infection_seed = InfectionSeed(super_areas=world.super_areas,
                                   selector=selector)
    n_cases = 2
    infection_seed.unleash_virus(n_cases)

    sim = Simulator.from_file(world=world,
                              interaction=interaction,
                              infection_selector=selector,
                              config_filename=test_config,
                              leisure=leisure_instance,
                              policies=policies)
    return sim
コード例 #7
0
ファイル: quickstart.py プロジェクト: valeriupredoi/june
# modify interactions (example x 2)
interaction.beta['household'] *= 2
print(interaction.beta)
interaction.alpha_physical
interaction.alpha_physical /= 2
interaction.alpha_physical

# # Seed the disease
# There are two options implemented in the seed at the moment, either you specify the number of cases and these are then homogeneously distributed by population to the different areas, or you use UK data on cases per region. For now use the first case.
seed = InfectionSeed(
    world.super_areas,
    selector,
)

n_cases = 50
seed.unleash_virus(n_cases)  # play around with the initial number of cases

# # Set policies
policies = Policies.from_file()

# # Run the simulation
# Since the timer configuration is a bit cumbersome, it is read from the config file at ``configs/config_example.yml
CONFIG_PATH = "configs/config_example.yaml"
leisure = generate_leisure_for_config(world=world, config_filename=CONFIG_PATH)
simulator = Simulator.from_file(world,
                                interaction,
                                selector,
                                config_filename=CONFIG_PATH,
                                leisure=leisure,
                                policies=policies)
コード例 #8
0
# health index and infection selecctor
health_index_generator = HealthIndexGenerator.from_file(asymptomatic_ratio=0.2)
infection_selector = InfectionSelector.from_file(
    health_index_generator=health_index_generator)

# interaction
interaction = Interaction.from_file()

# initial infection seeding
infection_seed = InfectionSeed(
    world.super_areas,
    infection_selector,
)

infection_seed.unleash_virus(50)  # number of initial cases

# policies
policies = Policies.from_file()

# create simulator

simulator = Simulator.from_file(
    world=world,
    policies=policies,
    interaction=interaction,
    leisure=leisure,
    infection_selector=infection_selector,
    config_filename=config_path,
    save_path="results",
)
コード例 #9
0
    "CXB-207": 2,
    "CXB-213": 2,
}  # By the 24th May

print("Detected cases = ", sum(cases_detected.values()))

msoa_region_filename = camp_data_path / "input/geography/area_super_area_region.csv"
msoa_region = pd.read_csv(msoa_region_filename)[["super_area", "region"]]
infection_seed = InfectionSeed(
    super_areas=world.super_areas, selector=selector, msoa_region=msoa_region
)

for key, n_cases in cases_detected.items():
    infection_seed.unleash_virus_regional_cases(key, n_cases * 10)
# Add some extra random cases
infection_seed.unleash_virus(n_cases=100)

print("Infected people in seed = ", len(world.people.infected))

CONFIG_PATH = camp_configs_path / "learning_center_config.yaml"

# ==================================================================================#

# =================================== leisure config ===============================#
leisure_instance = generate_leisure_for_config(world=world, config_filename=CONFIG_PATH)
leisure_instance.leisure_distributors = {}
leisure_instance.leisure_distributors[
    "pump_latrines"
] = PumpLatrineDistributor.from_config(pump_latrines=world.pump_latrines)
leisure_instance.leisure_distributors[
    "play_groups"
コード例 #10
0
    "CXB-207": 2,
    "CXB-213": 2,
}  # By the 24th May

print("Detected cases = ", sum(cases_detected.values()))

super_region_filename = camp_data_path / "input/geography/area_super_area_region.csv"
super_region_df = pd.read_csv(super_region_filename)[["super_area", "region"]]
infection_seed = InfectionSeed(
    world=world,
    infection_selector=selector,
)
for region in world.regions:
    if region.name in cases_detected.keys():
        infection_seed.unleash_virus(
            n_cases=2 * cases_detected[region.name],
            population=Population(region.people),
        )
# Add some extra random cases
infection_seed.unleash_virus(n_cases=44, population=world.people)

print("Infected people in seed = ", len(world.people.infected))

# ==================================================================================#

# =================================== leisure config ===============================#
leisure = generate_leisure_for_config(world=world, config_filename=CONFIG_PATH)
leisure.leisure_distributors = {}
leisure.leisure_distributors[
    "pump_latrines"] = PumpLatrineDistributor.from_config(world.pump_latrines)
leisure.leisure_distributors["play_groups"] = PlayGroupDistributor.from_config(
    world.play_groups)