tlo.test.random_birth module

A simple test module for demonstration purposes.

It polls the population each month, randomly making non-pregnant people pregnant with a fixed probability, set as a module parameter. Nine months after becoming pregnant (assuming the mother does not die) a new person is born.

This is not intended to be realistic - there are no sexes, and newborn infants may become pregnant!

class RandomBirth(name=None)[source]

Bases: tlo.core.Module

Randomly become pregnant with fixed probability.

All disease modules need to be implemented as a class inheriting from Module. They need to provide several methods which will be called by the simulation framework: * read_parameters(data_folder) * initialise_population(population) * initialise_simulation(sim) * on_birth(mother, child)

PARAMETERS = {'pregnancy_probability': REAL === Fixed probability of pregnancy each month (if not already pregnant)}
PROPERTIES = {'children': LIST === The children born to this individual, in birth order, 'date_of_birth': DATE === When the individual was born, 'is_pregnant': BOOL === Whether this individual is currently pregnant}
read_parameters(data_folder)[source]

Read parameter values from file, if required.

Here we do nothing.

Parameters

data_folder – path of a folder supplied to the Simulation containing data files. Typically modules would read a particular file within here.

initialise_population(population)[source]

Set our property values for the initial population.

This method is called by the simulation when creating the initial population, and is responsible for assigning initial values, for every individual, of those properties ‘owned’ by this module, i.e. those declared in the PROPERTIES dictionary above.

Parameters

population – the population of individuals

initialise_simulation(sim)[source]

Get ready for simulation start.

This method is called just before the main simulation loop begins, and after all modules have read their parameters and the initial population has been created. It is a good place to add initial events to the event queue.

Here we add our monthly event to poll the population for deaths.

on_birth(mother_id, child_id)[source]

Initialise our properties for a newborn individual.

This is called by the simulation whenever a new person is born.

Parameters
  • mother_id – the mother for this child

  • child_id – the new child

parameters
class RandomPregnancyEvent(module, pregnancy_probability)[source]

Bases: tlo.events.RegularEvent, tlo.events.PopulationScopeEventMixin

The regular event that actually makes people pregnant.

Regular events automatically reschedule themselves at a fixed frequency, and thus implement discrete timestep type behaviour. The frequency is specified when calling the base class constructor in our __init__ method.

apply(population)[source]

Apply this event to the population.

For efficiency, we use pandas operations to scan the entire population and initiate pregnancies at random.

Parameters

population – the current population

class DelayedBirthEvent(module, mother_id)[source]

Bases: tlo.events.Event, tlo.events.IndividualScopeEventMixin

A one-off event in which a pregnant mother gives birth.

For an individual-scoped event we need to specify the person it applies to in the constructor.

apply(mother_id)[source]

Apply this event to the given person.

Assuming the person is still alive, we ask the simulation to create a new offspring.

Parameters

mother_id – the person the event happens to, i.e. the mother giving birth