tlo.events module

Support for creating different kinds of events.

class Priority(value)[source]

Bases: Enum

Enumeration for the Priority, which is used in sorting the events in the simulation queue.

START_OF_DAY = 0
FIRST_HALF_OF_DAY = 25
LAST_HALF_OF_DAY = 75
END_OF_DAY = 100
class Event(module, *args, priority=Priority.FIRST_HALF_OF_DAY, **kwargs)[source]

Bases: object

Base event class, from which all others inherit.

Concrete subclasses should also inherit from one of the EventMixin classes defined below, and implement at least an apply method.

post_apply_hook()[source]

Do any required processing after apply() completes.

run()[source]

Make the event happen.

class RegularEvent(module, *, frequency, end_date=None, **kwargs)[source]

Bases: Event

An event that automatically reschedules itself at a fixed frequency.

post_apply_hook()[source]

Schedule the next occurrence of this event.

class PopulationScopeEventMixin(*args, **kwargs)[source]

Bases: object

Makes an event operate on the entire population.

This class is designed to be used via multiple inheritance along with one of the main event classes. It indicates that when an event happens, it is applied to the entire population, rather than a single individual. Contrast IndividualScopeEventMixin.

Subclasses should implement apply(self, population) to contain their behaviour.

apply(population)[source]

Apply this event to the population.

Must be implemented by subclasses.

Parameters

population – the current population

class IndividualScopeEventMixin(*args, person_id, **kwargs)[source]

Bases: object

Makes an event operate on a single individual.

This class is designed to be used via multiple inheritance along with one of the main event classes. It indicates that when an event happens, it is applied to a single individual, rather than the entire population. Contrast PopulationScopeEventMixin.

Subclasses should implement apply(self, person) to contain their behaviour.

apply(person_id)[source]

Apply this event to the given person.

Must be implemented by subclasses.

Parameters

person_id – the person the event happens to