class Analyzer(label=None)[source]#

Bases: prettyobj

Base class for analyzers. Based on the Intervention class. Analyzers are used to provide more detailed information about a simulation than is available by default – for example, pulling states out of sim.people on a particular timestep before it gets updated in the next timestep.

To retrieve a particular analyzer from a sim, use sim.get_analyzer().


label (str) – a label for the Analyzer (used for ease of identification)



Initialize the analyzer, e.g. convert date strings to integers.


Finalize analyzer

This method is run once as part of sim.finalize() enabling the analyzer to perform any final operations after the simulation is complete (e.g. rescaling)


Apply analyzer at each time point. The analyzer has full access to the sim object, and typically stores data/results in itself. This is the core method which each analyzer object needs to implement.


sim – the Sim instance


Remove any excess stored data from the intervention; for use with sim.shrink().


in_place (bool) – whether to shrink the intervention (else shrink a copy)

static reduce(analyzers, use_mean=False)[source]#

Create a reduced analyzer from a list of analyzers, using

  • analyzers – list of analyzers

  • use_mean (bool) – whether to use medians (the default) or means to create the reduced analyzer


Return JSON-compatible representation

Custom classes can’t be directly represented in JSON. This method is a one-way export to produce a JSON-compatible representation of the intervention. This method will attempt to JSONify each attribute of the intervention, skipping any that fail.


JSON-serializable representation