Disease#

class Disease(pars=None, *args, **kwargs)[source]#

Bases: Module

Base module class for diseases

Attributes

now

Shortcut to self.t.now()

states

Return a flat list of all states

statesdict

Return a flat dictionary (objdict) of all states

ti

Get the current module timestep

timevec

Shortcut to self.t.timevec

Methods

init_pre(sim)[source]#

Link the disease to the sim, create objects, and initialize results; see Module.init_pre() for details

init_results()[source]#

Initialize results

By default, diseases all report on counts for any explicitly defined “States”, e.g. if a disease contains a boolean state ‘susceptible’ it will automatically contain a Result for ‘n_susceptible’.

step_state()[source]#

Carry out updates at the start of the timestep (prior to transmission); these are typically state changes

step_die(uids)[source]#

Carry out state changes upon death

This function is triggered after deaths are resolved, and before analyzers are run. See the SIR example model for a typical use case - deaths are requested as an autonomous update, to take effect after transmission on the same timestep. State changes that occur upon death (e.g., clearing an infected flag) are executed in this function. That also allows an intervention to avert a death scheduled on the same timestep, without having to undo any state changes that have already been applied (because they only run via this function if the death actually occurs).

Unlike other methods during the integration loop, this method is not called directly by the sim; instead, it is called by people.step_die(), which reconciles the UIDs of the agents who will die.

Depending on the module and the results it produces, it may or may not be necessary to implement this.

step()[source]#

Handle the main disease updates, e.g. add new cases

This method is agnostic as to the mechanism by which new cases occur. This could be through transmission (parametrized in different ways, which may or may not use the contact networks) or it may be based on risk factors/seeding, as may be the case for non-communicable diseases.

It is expected that this method will internally call Disease.set_prognoses() at some point.

set_prognoses(uids, sources=None)[source]#

Set prognoses upon infection/acquisition

This function assigns state values upon infection or acquisition of the disease. It would normally be called somewhere towards the end of Disease.make_new_cases(). Infections will optionally be added to the log as part of this operation if logging is enabled (in the Disease parameters)

The sources are relevant for infectious diseases, but would be left as None for NCDs.

Parameters:
  • sim (Sim) – the STarsim simulation object

  • uids (array) – UIDs for agents to assign disease progoses to

  • from_uids (array) – Optionally specify the infecting agent

update_results()[source]#

Update results

This function is executed after transmission in all modules has been resolved. This allows result updates at this point to capture outcomes dependent on multiple modules, where relevant.