rsvsim.population module¶
Defines functions for making the population.
-
rsvsim.population.
make_people
(sim, popdict=None, save_pop=False, popfile=None, die=True, reset=False, verbose=None, **kwargs)[source]¶ Make the actual people for the simulation. Usually called via sim.initialize(), but can be called directly by the user.
- Parameters
sim (Sim) – the simulation object; population parameters are taken from the sim object
popdict (dict) – if supplied, use this population dictionary instead of generating a new one
save_pop (bool) – whether to save the population to disk
popfile (bool) – if so, the filename to save to
die (bool) – whether or not to fail if synthetic populations are requested but not available
reset (bool) – whether to force population creation even if self.popdict/self.people exists
verbose (bool) – level of detail to print
kwargs (dict) – passed to make_randpop() or make_synthpop()
- Returns
people
- Return type
people (People)
-
rsvsim.population.
make_randpop
(pars, use_age_data=True, use_household_data=True, microstructure='random', **kwargs)[source]¶ Make a random population, with contacts.
This function returns a “popdict” dictionary, which has the following (required) keys:
uid: an array of (usually consecutive) integers of length N, uniquely identifying each agent
age: an array of floats of length N, the age in years of each agent
sex: an array of integers of length N (not currently used, so does not have to be binary)
contacts: list of length N listing the contacts; see make_random_contacts() for details
layer_keys: a list of strings representing the different contact layers in the population; see make_random_contacts() for details
- Parameters
pars (dict) – the parameter dictionary or simulation object
use_age_data (bool) – whether to use location-specific age data
use_household_data (bool) – whether to use location-specific household size data
microstructure (bool) – whether or not to use the microstructuring algorithm to group contacts
kwargs (dict) – passed to contact creation method (e.g., make_hybrid_contacts)
- Returns
a dictionary representing the population, with the following keys for a population of N agents with M contacts between them:
- Return type
popdict (dict)
-
rsvsim.population.
make_random_contacts
(pop_size, contacts, overshoot=1.2, dispersion=None)[source]¶ Make random static contacts.
- Parameters
pop_size (int) – number of agents to create contacts between (N)
contacts (dict) – a dictionary with one entry per layer describing the average number of contacts per person for that layer
overshoot (float) – to avoid needing to take multiple Poisson draws
dispersion (float) – if not None, use a negative binomial distribution with this dispersion parameter instead of Poisson to make the contacts
- Returns
a list of length N, where each entry is a dictionary by layer, and each dictionary entry is the UIDs of the agent’s contacts layer_keys (list): a list of layer keys, which is the same as the keys of the input “contacts” dictionary
- Return type
contacts_list (list)
-
rsvsim.population.
make_microstructured_contacts
(pop_size, contacts)[source]¶ Create microstructured contacts – i.e. for households
-
rsvsim.population.
make_hybrid_contacts
(pop_size, ages, contacts, school_ages=None)[source]¶ Create “hybrid” contacts – microstructured contacts for households and random contacts for schools, both of which have extremely basic age structure. A combination of both make_random_contacts() and make_microstructured_contacts().
-
rsvsim.population.
make_synthpop
(sim=None, population=None, layer_mapping=None, community_contacts=None, **kwargs)[source]¶ Make a population using SynthPops, including contacts. Usually called automatically, but can also be called manually. Either a simulation object or a population must be supplied; if a population is supplied, transform it into the correct format; otherwise, create the population and then transform it.
- Parameters
sim (Sim) – a rsvsim simulation object
population (list) – a pre-generated SynthPops population (otherwise, create a new one)
layer_mapping (dict) – a custom mapping from SynthPops layers to rsvsim layers
community_contacts (int) – if a simulation is not supplied, create this many community contacts on average
kwargs (dict) – passed to sp.make_population()
Example:
sim = cv.Sim(pop_type='synthpops') sim.popdict = cv.make_synthpop(sim) sim.run()