synthpops.people.makepop module¶
Defines functions for making the population.
-
make_people
(n=None, popdict=None, rand_seed=1, pop_type='synthpops', location=None, save_pop=False, popfile=None, die=True, 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: - n (int) – the number of people to create
- 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
- verbose (bool) – level of detail to print
- kwargs (dict) – passed to make_randpop() or make_synthpop()
Returns: people
Return type: people (People)
New in version 1.10.0.
-
make_randpop
(sim, use_age_data=True, use_household_data=True, sex_ratio=0.5, microstructure=False)[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: - sim (Sim) – the 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
- sex_ratio (float) – proportion of the population that is male (not currently used)
- microstructure (bool) – whether or not to use the microstructuring algorithm to group 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)
New in version 1.10.0.
-
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)
New in version 1.10.0.
-
make_microstructured_contacts
(pop_size, contacts)[source]¶ Create microstructured contacts – i.e. for households
-
make_hybrid_contacts
(pop_size, ages, contacts, school_ages=None, work_ages=None)[source]¶ Create “hybrid” contacts – microstructured contacts for households and random contacts for schools and workplaces, both of which have extremely basic age structure. A combination of both make_random_contacts() and make_microstructured_contacts().
New in version 1.10.0.
-
parse_synthpop
(population, layer_mapping=None, community_contacts=0)[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: - population (list) – a pre-generated SynthPops population
- layer_mapping (dict) – a custom mapping from SynthPops layers to Covasim layers
- community_contacts (int) – create this many community contacts on average
New in version 1.10.0.