Core

Core provides the basic class framework to build a population

Overview:

class pyEpiabm.Cell(loc: Tuple[float, float] = (0, 0))[source]

Class representing a Cell (Subset of Population). Collection of Microcell s and Person s.

add_microcells(n)[source]

Add n empty Microcell s to Cell.

Parameters:

n (int) – Number of empty Microcell s to add

enqueue_LFT_testing(person: Person)[source]
Add person to LFT testing queue for processing in testing

sweep.

Detailed description of the implementation can be found in github wiki: https://github.com/SABS-R3-Epidemiology/epiabm/wiki/Interventions#testing

Parameters:

person (Person) – Person to enqueue.

enqueue_PCR_testing(person: Person)[source]
Add person to PCR testing queue for processing in testing

sweep.

Detailed description of the implementation can be found in github wiki: https://github.com/SABS-R3-Epidemiology/epiabm/wiki/Interventions#testing

Parameters:

person (Person) – Person to enqueue.

enqueue_person(person: Person)[source]

Add person to queue for processing at end of iteration, provided they are not already recovered (and so may be infected).

Parameters:

person (Person) – Person to enqueue

find_nearby_cells(other_cells)[source]

Helper function which takes in a given cell and the list of all cells and generates a list of nearby cells which are closer than the cutoff for cross-cell infection.

Populates: self.find_nearby_cells Dictionary of all cells with distance below cutoff. Dictionary stores cell.id and distance between the 2 cells These are stored in the form: cell.id: distance

Parameters:

other_cells (List[Cell]) – List of all cells except cell

notify_person_status_change(old_status: InfectionStatus, new_status: InfectionStatus, age_group) None[source]

Notify Cell that a person’s status has changed.

Parameters:
  • old_status (InfectionStatus) – Person’s old infection status

  • new_status (InfectionStatus) – Person’s new infection status

  • age_group (Age group index) – Person’s associated age group

number_infectious()[source]
Returns the total number of infectious people in each

cell, all ages combined.

Returns:

Total infectors in cell

Return type:

int

set_id(id: str, cells: List)[source]

Updates id of current cell (i.e. for input from file).

Parameters:
  • id (str) – Identity of cell

  • cells (list) – List of all current cells

set_location(loc: Tuple[float, float])[source]

Method to set or change the location of a cell.

Parameters:

loc (Tuple[float, float]) – (x,y) coordinates of the place

class pyEpiabm._CompartmentCounter(identifier: str)[source]

Class Component which maintains count of people in each compartment, according to their age group.

clear_counter()[source]

Method to clear and reset compartment counter to zero.

property identifier

Get identifier.

report(old_status: InfectionStatus, new_status: InfectionStatus, age_group=0) None[source]

Report Person has changed state. Update internal compartments state.

Parameters:
  • old_status (InfectionStatus) – Person’s previous infection state

  • new_status (InfectionStatus) – Person’s new infection state

  • age_group (Age group index) – Person’s associated age group, defaults to 0 if age not implemented

retrieve() Dict[InfectionStatus, array][source]

Get Compartment Counts. Returns dictionary of compartment counts, in which each entry is an array containing the number of people by age group. If age is not used then there is only one age group and the array length is 1.

Returns:

Dictionary of compartments

Return type:

dict

class pyEpiabm.Household(microcell, loc: Tuple[float, float], susceptibility=0, infectiousness=0)[source]

Class representing a household, a group of people (family or otherwise) who live together and share living spaces. This group will have a combined susceptibility and infectiousness different to that of the individuals.

add_person(person)[source]

Adds a person to this household.

Parameters:

person (Person) – Person to be added

add_susceptible_person(susceptible_person)[source]

Adds a person to the list of susceptible people in the household.

Parameters:

susceptible_person (Person) – Person to be added

remove_household()[source]

Method to remove Household object from population. Used to remove household in which a traveller was hotel isolating.

remove_susceptible_person(non_susceptible_person)[source]

Removes a susceptible person from the list of susceptible people in the household.

Parameters:

non_susceptible_person (Person) – Person to be removed

set_id(id: str)[source]

Updates id of current household (i.e. for input from file). Format of id - for example 3.1.2 represents household 2 within microcell 1 within cell 3. The id will only be changed if it has the correct expression.

Parameters:

id (str) – Identity of household

class pyEpiabm.Microcell(cell)[source]

Class representing a Microcell (Group of people and places). Collection of Person s.

Parameters:

cell (Cell) – An instance of Cell

add_household(people: list, update_person_id: bool = True)[source]

Adds a default Household to Microcell and fills it with a number of Person s.

Parameters:
  • people (list) – List of People to add to household

  • update_person_id (bool) – Boolean representing whether we wish to update the id of the people of the household when the function is called or not

add_people(n, status=InfectionStatus.Susceptible, age_group=None)[source]

Adds n default Person of given status to Microcell.

Parameters:
  • n (int) – Number of default Person s to add

  • status (InfectionStatus) – Status of persons to add to cell

  • age_group (Age group index) – Person’s associated age group

add_person(person)[source]

Adds Person with given InfectionStatus and given age group to Microcell.

Parameters:

person (Person) – Newly instantiated person with InfectionStatus and associated age group

add_place(n: int, loc: Tuple[float, float], place_type)[source]

Adds n default Place to Microcell.

Parameters:

n (int) – Number of default Place s to add

notify_person_status_change(old_status: InfectionStatus, new_status: InfectionStatus, age_group) None[source]

Notify Microcell that a person’s status has changed.

Parameters:
  • old_status (InfectionStatus) – Person’s old infection status

  • new_status (InfectionStatus) – Person’s new infection status

  • age_group (Age group index) – Person’s associated age group

set_id(id)[source]

Updates id of current microcell (i.e. for input from file).

Parameters:

id (str) – Identity of microcell

set_location(loc: Tuple[float, float])[source]

Method to set or change the location of a microcell.

Parameters:

loc (Tuple[float, float]) – (x,y) coordinates of the microcell

class pyEpiabm.Parameters[source]

Class for global parameters.

Following a singleton Pattern.

static instance()[source]

Creates singleton instance of __Parameters under _instance if one doesn’t already exist.

Returns:

An instance of the __Parameters class

Return type:

__Parameters

static set_file(file_path)[source]

Loads file

class pyEpiabm.Person(microcell, age_group=None)[source]

Class to represent each person in a population.

Parameters:

microcell (Microcell) – An instance of an Microcell

Variables:
  • infection_status (InfectionStatus) – Person’s current infection status

  • next_infection_status (InfectionStatus) – Person’s next infection status after current one

  • time_of_status_change (int) – Time when person’s infection status is updated

add_place(place, person_group: int = 0)[source]

Method adds a place to the place list if the person visits or is associated with this place. Places are saved as a tuple with the place as the first entry and the group the person is associated with as the second.

Parameters:
  • place (Place) – Place person should be added to

  • person_group (int) – Key for the person group dictionary

increment_num_times_infected()[source]

Increments the number of times the person has been Infected as a useful parameter to keep track of.

increment_secondary_infections()[source]

Increments the number of secondary infections the given person has for this specific infection period (i.e. if the given person has been infected multiple times, then we only increment the current secondary infection count).

is_infectious()[source]

Query if the person is currently infectious.

Returns:

Whether person is currently infectious

Return type:

bool

is_place_closed(closure_place_type)[source]

Method to check if any of the place in the person’s place list will be closed based on the place type, to be used when place closure intervention is active.

Parameters:

closure_place_type (a list of PlaceType) – PlaceType should be closed if in place closure intervention

is_susceptible()[source]

Query if the person is currently susceptible.

Returns:

Whether person is currently susceptible

Return type:

bool

is_symptomatic()[source]

Query if the person is currently symptomatic.

Returns:

Whether person is currently symptomatic

Return type:

bool

remove_person()[source]

Method to remove Person object from population. Used to remove travellers from the population.

remove_place(place)[source]

Method to remove person for each associated place, to be used when updating places.

Parameters:

place (Place) – Place person should be removed from

set_exposure_period(exposure_period: float)[source]

Sets the exposure period (we define here as the time between a primary case infection and a secondary case exposure, with the current Person being the secondary case). We store this to be added to the latent period of the infection to give a serial interval.

Parameters:

exposure_period (float) – The time between the infector’s time of infection and the time of exposure to the current Person

set_id(id: str)[source]

Updates id of current person (i.e. for input from file). id format: 4.3.2.1 represents cell 4, microcell 3 within this cell, household 2 within this microcell, and person 1 within this household. The id will only be changed if it is of the correct format.

Parameters:

id (str) – Identity of person

set_infector_latent_period(latent_period: float)[source]

Sets the latent period of the primary infector of this Person. We store this in order to calculate the generation_time of the interaction between infector and infectee.

Parameters:

latent_period (float) – The latency period of the primary infector (the individual who infected the current Person).

set_latent_period(latent_period: float)[source]

Sets the latent period of the current Person.

Parameters:

latent_period (float) – The time between the exposure and infection onset of the current Person.

set_random_age(age_group=None)[source]

Set random age of person, and save index of their age group. Note that the max age in the 80+ group is 84 here, however the precise age of 80+ people is never used (exact ages are only used to assign school/workplaces) so this does not cause any issues.

set_time_of_recovery(time: float)[source]

Records the time at which a person enters the Recovered compartment.

Parameters:

time (float) – Current simulation time

store_generation_time()[source]

Adds the infector_latent_period to the current exposure_period to give a generation_time, which will be stored in the generation_time_dict. The generation time is the time between a primary case exposure and a secondary case exposure. This method is called immediately after the infectee becomes exposed.

store_serial_interval()[source]

Adds the latent_period to the current exposure_period to give a serial_interval, which will be stored in the serial_interval_dict. The serial interval is the time between a primary case infection and a secondary case infection. This method is called immediately after a person becomes exposed.

update_age_group()[source]

Update the age_group attribute based on the current age value. This should be called after the age is set directly (e.g., in household age assignment) to ensure the age_group is consistent with the age.

update_status(new_status: InfectionStatus) None[source]

Update Person’s Infection Status.

Parameters:

new_status (InfectionStatus) – Person’s new status

vaccinate(time)[source]

Used to set a persons vaccination status to vaccinated if they are drawn from the vaccine queue.

class pyEpiabm.Place(loc: Tuple[float, float], place_type: PlaceType, cell, microcell)[source]

Creates a place class which represents spaces such as cafes, restaurants and hotels where people may come into contact with others outside their household. People can be stratified in this place into different groups which may interact differently (ie workers and visitors).

add_person(person: Person, person_group: int = 0)[source]

Add a person into the place.

Parameters:
  • person (Person) – Person to add

  • person_group (int) – Key for the person group dictionary

empty_place(groups_to_empty: list = [])[source]

Remove all people from place who are in a specific person group. For example a restaurant or park might regularly change all occupants each timestep, but workers at the restaurant will be present each timestep. Defaults to emptying the whole place.

Parameters:

person_groups (list) – List of person_group indicies to be removed

get_group_index(person)[source]

Get the group of a person in the place.

Parameters:

person (Person) – Person associated with group

remove_person(person: Person)[source]

Remove a person from place.

Parameters:

person (Person) – Person to remove from place

set_infectiousness(infectiousness: float)[source]

Sets a baseline infectiousness for the place.

Parameters:

infectiousness (float) – Baseline infectiousness

set_susceptibility(susceptibility: float)[source]

Sets a baseline susceptibility for the place.

Parameters:

susceptibility (float) – Baseline susceptibility

class pyEpiabm.Population[source]

Class representing a Population. Collection of Cell s.

add_cells(n)[source]

Adds n default Cell s to the population.

Parameters:

n (int) – Number of empty Cell s to add

enqueue_vaccine(priority, counter, person: Person)[source]

Add person to queue for processing when mass vaccination begins.

Parameters:
  • priority (int) – Priority level of 1, 2, 3, or 4 to prioritise by age and whether carehome resident. 1 being highest priority and 4 being lowest.

  • counter (int) – Counter to prioritise by order of addition within each priority group. Generated successively on addition of individuals to the queue.

  • person (Person) – Person to enqueue

total_people()[source]

Returns the total number of people in the population. Will obviously match the configuration parameter, but useful in various sweeps to have this attached.