Пример #1
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
Пример #2
0
def test__generate_leisure_from_world():
    geography = Geography.from_file({"super_area": ["E02002135"]})
    world = generate_world_from_geography(geography,
                                          include_households=True,
                                          include_commute=False)
    world.pubs = Pubs.for_geography(geography)
    world.cinemas = Cinemas.for_geography(geography)
    world.groceries = Groceries.for_geography(geography)
    person = Person.from_attributes(sex="m", age=27)
    household = Household()
    household.area = world.areas[0]
    household.add(person)
    person.area = geography.areas[0]
    leisure = generate_leisure_for_world(
        list_of_leisure_groups=["pubs", "cinemas", "groceries"], world=world)
    leisure.distribute_social_venues_to_households([household])
    leisure.generate_leisure_probabilities_for_timestep(0.1, False)
    n_pubs = 0
    n_cinemas = 0
    n_groceries = 0
    for _ in range(0, 1000):
        subgroup = leisure.get_subgroup_for_person_and_housemates(person)
        if subgroup is not None:
            if subgroup.group.spec == "pub":
                n_pubs += 1
            elif subgroup.group.spec == "cinema":
                n_cinemas += 1
            elif subgroup.group.spec == "grocery":
                n_groceries += 1
    assert 0 < n_pubs < 100
    assert 0 < n_cinemas < 100
    assert 0 < n_groceries < 107
Пример #3
0
def test__teacher_distribution(geography_school):
    geography_school.schools = Schools.for_geography(geography_school)
    world = generate_world_from_geography(geography_school, include_households=False)
    for school in world.schools:
        students = len(school.students)
        teachers = len(school.teachers.people)
        ratio = students / teachers
        assert ratio < 40
Пример #4
0
def create_world(geography):
    geography.hospitals = Hospitals.for_geography(geography)
    geography.companies = Companies.for_geography(geography)
    geography.schools = Schools.for_geography(geography)
    geography.care_homes = CareHomes.for_geography(geography)
    geography.cemeteries = Cemeteries()
    geography.companies = Companies.for_geography(geography)
    world = generate_world_from_geography(geography, include_households=True)
    return world
Пример #5
0
def test__onearea_world(geography):
    geography = Geography.from_file(filter_key={"area": ["E00088544"]})
    world = generate_world_from_geography(geography)
    assert hasattr(world, "households")
    assert isinstance(world.households, Households)
    assert len(world.areas) == 1
    assert len(world.super_areas) == 1
    assert world.super_areas.members[0].name == "E02003616"
    assert len(world.areas.members[0].people) == 362
    assert len(world.households) <= 148
def make_world(geography):
    geography.hospitals = Hospitals.for_geography(geography)
    geography.schools = Schools.for_geography(geography)
    geography.companies = Companies.for_geography(geography)
    geography.care_homes = CareHomes.for_geography(geography)
    geography.universities = Universities.for_super_areas(
        geography.super_areas)
    world = generate_world_from_geography(geography,
                                          include_households=False,
                                          include_commute=False)
    return world
Пример #7
0
    def create_world_nc(self, geography_commute_nc):
        world = generate_world_from_geography(
            geography_commute_nc, include_commute=False, include_households=False
        )
        worker_distr = WorkerDistributor.for_geography(geography_commute_nc)
        worker_distr.distribute(geography_commute_nc.areas, geography_commute_nc.super_areas, world.people)
        commute_generator = CommuteGenerator.from_file()

        for area in world.areas:
            commute_gen = commute_generator.regional_gen_from_msoarea(area.name)
            for person in area.people:
                person.mode_of_transport = commute_gen.weighted_random_choice()

        return world
def create_world():
    geography = Geography.from_file({"area": ["E00003282"]})
    demography = Demography.for_geography(geography)
    geography.hospitals = Hospitals(
        [
            Hospital(
                n_beds=1000,
                n_icu_beds=1000,
                super_area=geography.super_areas[0],
                coordinates=geography.areas[0].coordinates,
            )
        ]
    )
    world = generate_world_from_geography(
        geography=geography, include_households=True, include_commute=False
    )
    return world
Пример #9
0
def create_world(geography_h5):
    with h5py.File("test.hdf5", "w"):
        pass  # reset file
    geography = geography_h5
    geography.hospitals = Hospitals.for_geography(geography)
    geography.schools = Schools.for_geography(geography)
    geography.companies = Companies.for_geography(geography)
    geography.care_homes = CareHomes.for_geography(geography)
    geography.universities = Universities.for_super_areas(geography.super_areas)
    world = generate_world_from_geography(
        geography=geography, include_households=True, include_commute=True
    )
    world.pubs = Pubs.for_geography(geography)
    world.cinemas = Cinemas.for_geography(geography)
    world.groceries = Groceries.for_geography(geography)
    leisure = generate_leisure_for_world(
        ["pubs", "cinemas", "groceries", "household_visits", "care_home_vists"], world
    )
    leisure.distribute_social_venues_to_households(world.households)
    return world
Пример #10
0
    "super_area": [
        "E02003282",
        "E02001720",
        "E00088544",
        "E02002560",
        "E02002559",
        "E02004314",
    ]
})
geography.hospitals = Hospitals.for_geography(geography)
geography.schools = Schools.for_geography(geography)
geography.companies = Companies.for_geography(geography)
geography.care_homes = CareHomes.for_geography(geography)
geography.universities = Universities.for_super_areas(geography.super_areas)
world = generate_world_from_geography(geography,
                                      include_households=True,
                                      include_commute=True)

print("World length", len(world.people))
world.to_hdf5("world.hdf5")

world = generate_world_from_hdf5("world.hdf5")

# leisure
geography = load_geography_from_hdf5("world.hdf5")
world.cinemas = Cinemas.for_geography(geography)
world.pubs = Pubs.for_geography(geography)
world.groceries = Groceries.for_super_areas(world.super_areas,
                                            venues_per_capita=1 / 500)
world.cemeteries = Cemeteries()
selector = InfectionSelector.from_file()
Пример #11
0
def create_area():
    g = Geography.from_file(filter_key={"super_area": ["E02003353"]}, )
    world = generate_world_from_geography(g)
    return world
Пример #12
0
def make_super_areas():
    geo = Geography.from_file({"super_area": ["E02003353"]})
    geo.care_homes = CareHomes.for_geography(geo)
    world = generate_world_from_geography(geo, include_households=True)
    return world
Пример #13
0
def create_box_world():
    geography = Geography.from_file({"area": ["E00000697"]})
    return generate_world_from_geography(geography, box_mode=True)
Пример #14
0
    def create_world_nc(self, geography_commute_nc):
        world = generate_world_from_geography(geography_commute_nc,
                                              include_households=False,
                                              include_commute=False)

        return world