tlo.methods.record_summary_stats module
Record Summary Statistics Module
This module collects and logs the number of individuals in each age group for each disease
- class RecordSummaryStats(name=None)
Module to collect summary statistics from each disease module.
Construct a new disease module ready to be included in a simulation.
Initialises an empty parameters dictionary and module-specific random number generator.
- Parameters:
name – the name to use for this module. Defaults to the concrete subclass’ name.
Bases:
tlo.core.ModulePARAMETERS:
Item
Type
Description
logging_frequency
STRING
Frequency at which to collect numbers: “day”, “month”, or “year”
do_checks
BOOL
Whether to check that the collected statistics are valid
Class attributes:
INIT_DEPENDENCIES : {‘Demography’}
METADATA : {}
__annotations__ : {}
Functions (defined or overridden in class RecordSummaryStats):
- __init__(name=None)
Construct a new disease module ready to be included in a simulation.
Initialises an empty parameters dictionary and module-specific random number generator.
- Parameters:
name – the name to use for this module. Defaults to the concrete subclass’ name.
- read_parameters(resourcefilepath: Path | None = None)
Read parameters for the module.
- initialise_population(population)
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 its PROPERTIES dictionary.
By default, all
Property``s in ``self.PROPERTIESwill have their columns in the population dataframe set to the default value.Modules that wish to implement this behaviour do not need to implement this method, it will be inherited automatically. Modules that wish to perform additional steps during the initialise_population stage should reimplement this method and call
`python super().initialise_population(population=population) `at the beginning of the method, then proceed with their additional steps. Modules that do not wish to inherit this default behaviour should re-implement initialise_population without the call to
super()above.TODO: We probably need to declare somehow which properties we ‘read’ here, so the simulation knows what order to initialise modules in!
- Parameters:
population – The population of individuals in the simulation.
- initialise_simulation(sim)
Do before simulation starts: 1) Collect modules that will report disease numbers 2) Schedule the logging event based on the configured frequency (if any models will do reporting)
- on_birth(mother_id, child_id)
Initialise our properties for a newborn individual.
Must be implemented by subclasses.
This is called by the simulation whenever a new person is born.
- Parameters:
mother_id – the person id for the mother of this child (can be -1 if the mother is not identified).
child_id – the person id of new child
- _check_stats(d: Dict) None
Validate that a statistic value is in an acceptable format for logging.
This should be a dict of the form {statistic: value}, where statistic is a string and value can be a numerical value (including numpy types) or a dict (or nested dict).
Returns nothing, but raises Error if any problem
- collect_stats_and_write_to_log()
Write disease numbers to the log.
- class DiseasenumbersLoggingEvent(module, frequency: DateOffset)
Event that collects disease numbers from registered modules and logs them. Runs at regular intervals (daily, monthly, or yearly) based on module configuration.
Create a new regular event.
- Parameters:
module – the module that created this event
frequency (pandas.tseries.offsets.DateOffset) – the interval from one occurrence to the next (must be supplied as a keyword argument)
Bases:
tlo.events.RegularEvent,tlo.events.Event,tlo.events.PopulationScopeEventMixinClass attributes:
__annotations__ : {}
Functions (defined or overridden in class DiseasenumbersLoggingEvent):
- __init__(module, frequency: DateOffset)
Create a new regular event.
- Parameters:
module – the module that created this event
frequency (pandas.tseries.offsets.DateOffset) – the interval from one occurrence to the next (must be supplied as a keyword argument)
- apply(population)
Collect numbers from all registered modules and log them.