Skip to content

Service and Services Infrastructure Objects

Info

service and services_infrastructure objects are implemented on services.py

The service object models any service of the community that may influence the infection spread, and the services_infrastructure object initializes and stores the service objects.

Services are configured with the services parameters (see configuration examples bellow).

Service visitors, workers and guests

Services discriminate particles among three categories: visitors, guests and workers. Visitors are particles that eventually visit the service, stay there during a certain period of time, and then go somewhere else. Guests are particles that stay at a service for a longer period of time, but that eventually go somewhere else as well. Finally, workers are particles that stay at a service during a limited period of time, every day the service is open. These three categories of particles may have different meanings depending on the type of service. For example, when the service is a hospital, workers are doctors, nurses, etc., visitors are people that eventually need to see a doctor, and guests are people that are admitted to the hospital. On the other hand, if the service is a school, there are a few workers with a longer shift, which corresponds to teachers, office people, etc., and a lot of workers with smaller shifts, which correspond to the students. In the case of schools, there is no visitors and no guests.

Services configuration

Default configuration

Services configuration is done using the services parameter:

from comorbuss import community, services

parameters = dict()

parameters["services"] = [
    (services.MARKETS, dict(number=253)),
    (services.HOSPITALS, dict(number=16)),
    (services.SCHOOLS, dict(number=160)),
    (services.RESTAURANTS, dict(number=740)),
]

comm = community(**parameters)
comm.simulate()

Important

The number of each service is always normalized with the proportion between the total population on the city and the number of particles in the simulation, but there will always be at least one instance of each selected service on the simulation.

services parameter

The services parameter is a list of dictionaries containing the configuration to create each service, the user can manually create dictionaries for the desired services or use the predefined ones on the services module inside comorbuss.

Seealso

For more information on how to create custom services see services reference and the custom_services.ipynb file inside the jupyter-examples folder.

Each element of the services list can be a dictionary or a tuple of two dictionaries, where the contents of the second dictionary will be overwritten on the first dictionary, allowing the user to load a predefined service and customize it without having to rewrite the whole dictionary:

from comorbuss import community, services

parameters = dict()

nursery = {
    "name": "Nursery",
    "number": 40,
    "workers": 0.72,
    "workers_age_groups": [0],
    "workers_per_room": 10,
}
parameters["services"] = [
    (services.MARKETS, dict(number=253)),
    (services.HOSPITALS, dict(number=16)),
    (services.SCHOOLS, dict(number=160)),
    (services.RESTAURANTS, dict(number=740)),
]
parameters["services"].append((services.GENERIC, {"number": 3700}))
parameters["services"].append((services.SCHOOLS, nursery))

comm = community(**parameters)
comm.simulate()

In the example above we first set the services parameters with some common services and then append first a generic service (used to simulate offices) and set the number of instances of this service as 3700 ((services.GENERIC, {"number": 3700})), lastly we create a new service called Nursery service using as base the service.SCHOOLS services overwriting some parameters with the nursery dictionary ((services.SCHOOLS, nursery)).

Predefined services

services.MARKETS

Markets services, opens from Monday to Saturday, all adults visits with a mean period of 5 days.

MARKETS = {
    "name": "Markets",
    "number": -1,
    "hours": [7, 19],
    "days": [0, 1, 1, 1, 1, 1, 1],
    "age_groups": np.arange(4, 21),
    "visitation_period": 5,
    "workers": 3,
    "shifts": [[7, 19]],
    "workers_age_groups": np.arange(4, 12),
    "close": False,
    "indoor": True
}

services.HOSPITALS

Hospitals service, opens everyday, 24 hours per day, all particles visits with a mean period of 90 days.

HOSPITALS = {
    "name": "Hospitals",
    "number": -1,
    "hours": [0, 24],
    "days": [1, 1, 1, 1, 1, 1, 1],
    "age_groups": ALL_AGES,
    "visitation_period": 90,
    "workers": 60,
    "shifts": [[0, 6], [6, 18], [18, 0]],
    "workers_age_groups": np.arange(4, 12),
    "close": False,
    "indoor": True
}

services.SCHOOLS

Schools service, opens from Monday to Friday, all particles between 5 and 19 years old (age groups 1, 2 and 3) are workers in this service, there is no visitation.

SCHOOLS = {
    "name": "Schools",
    "number": -1,
    "hours": [7, 12],
    "days": [0, 1, 1, 1, 1, 1, 0],
    "age_groups": [],
    "visitation_period": 1,
    "workers": 1.0,
    "workers_as_pop_frac": True,
    "shifts": [[7, 12]],
    "workers_age_groups": [1, 2, 3],
    "workers_per_room": 20,
    "close": True,
    "indoor": True
}

services.RESTAURANTS

Restaurants service, opens everyday from Noon to 10 p.m., all adults visits with a mean period of 7 days.

RESTAURANTS = {
    "name": "Restaurants",
    "number": -1,
    "hours": [12, 22],
    "days": [1, 1, 1, 1, 1, 1, 1],
    "age_groups": np.arange(4, 21),
    "visitation_period": 7,
    "workers": 5,
    "shifts": [[12, 22]],
    "workers_age_groups": np.arange(4, 12),
    "close": True,
    "indoor": True
}

services.STREET_MARKETS

Street markets services, opens once a week (on Saturday morning), all adults visits with a mean period of 30 days.

STREET_MARKETS = {
    "name": "Street Markets",
    "number": -1,
    "hours": [7, 13],
    "days": [0, 0, 0, 0, 0, 0, 1],
    "age_groups": np.arange(4, 21),
    "visitation_period": 30,
    "workers": 185,
    "shifts": [[7, 13]],
    "workers_age_groups": np.arange(5, 18),
    "close": True,
    "indoor": False
}

services.GENERIC

Generic services, used to simulate offices and other small services, opens from Monday to Friday, 59% of adults in working age (age groups 7 to 16) will work on this service, there is no visitation.

GENERIC = {
    "name": "Generic Services",
    "number": -1,
    "hours": [7, 16],
    "days": [0, 1, 1, 1, 1, 1, 0-],
    "age_groups": [],
    "visitation_period": np.inf,
    "workers": 0.59,
    "workers_as_pop_frac": True,
    "shifts": [[7, 16]],
    "workers_age_groups": np.arange(4, 12),
    "close": True,
    "indoor": True
}