hpvsim.people module¶
Defines the People class and functions associated with making people and handling the transitions between states (e.g., from susceptible to infected).
- class People(pars, strict=True, pop_trend=None, pop_age_trend=None, **kwargs)[source]¶
Bases:
BasePeople
A class to perform all the operations on the people – usually not invoked directly.
This class is usually created automatically by the sim. The only required input argument is the population size, but typically the full parameters dictionary will get passed instead since it will be needed before the People object is initialized. However, ages, contacts, etc. will need to be created separately – see
hpv.make_people()
instead.Note that this class handles the mechanics of updating the actual people, while
hpv.BasePeople
takes care of housekeeping (saving, loading, exporting, etc.). Please see the BasePeople class for additional methods.- Parameters:
pars (dict) – the sim parameters, e.g. sim.pars – alternatively, if a number, interpreted as n_agents
strict (bool) – whether or not to only create keys that are already in self.meta.person; otherwise, let any key be set
pop_trend (dataframe) – a dataframe of years and population sizes, if available
kwargs (dict) – the actual data, e.g. from a popdict, being specified
Examples:
ppl1 = hpv.People(2000) sim = hpv.Sim() ppl2 = hpv.People(sim.pars)
- scale_flows(inds)[source]¶
Return the scaled versions of the flows – replacement for len(inds) followed by scale factor multiplication
- set_prognoses(inds, g, gpars, dt)[source]¶
Assigns prognoses for all infected women on day of infection.
- set_severity(inds, g, gpars, dt, set_sev=True)[source]¶
Set severity levels for individual women :param inds: indices of women to set severity for :param g: genotype index :param dt: timestep :param set_sev: whether or not to set initial severity
- update_severity(genotype)[source]¶
Update disease severity for women with infection and update their current severity
- create_partnerships(tind, mixing, layer_probs, cross_layer, dur_pship, acts, age_act_pars, pref_weight=100)[source]¶
Create partnerships. All the hard work of creating the contacts is done by hppop.make_contacts, which in turn relies on hpu.create_edgelist for creating the edgelist. This method is just a light wrapper that passes in the arguments in the right format and the updates relationship info stored in the People class.
- check_inds(current, date, filter_inds=None)[source]¶
Return indices for which the current state is false and which meet the date criterion
- check_inds_true(current, date, filter_inds=None)[source]¶
Return indices for which the current state is true and which meet the date criterion
- apply_death_rates(year=None)[source]¶
Apply death rates to remove people from the population NB people are not actually removed to avoid issues with indices
- add_births(year=None, new_births=None, ages=0, immunity=None)[source]¶
Add more people to the population
Specify either the year from which to retrieve the birth rate, or the absolute number of new people to add. Must specify one or the other. People are added in-place to the current People instance.
- check_migration(year=None)[source]¶
Check if people need to immigrate/emigrate in order to make the population size correct.
- make_naive(inds)[source]¶
Make a set of people naive. This is used during dynamic resampling.
- Parameters:
inds (array) – list of people to make naive
- infect(inds, g=None, layer=None)[source]¶
Infect people and determine their eventual outcomes. Method also deduplicates input arrays in case one agent is infected many times and stores who infected whom in infection_log list.
- Parameters:
inds (array) – array of people to infect
g (int) – int of genotype to infect people with
layer (str) – contact layer this infection was transmitted on
- Returns:
number of people infected
- Return type:
count (int)
- plot(*args, **kwargs)[source]¶
Plot statistics of the population – age distribution, numbers of contacts, and overall weight of contacts (number of contacts multiplied by beta per layer).
- Parameters:
bins (arr) – age bins to use (default, 0-100 in one-year bins)
width (float) – bar width
font_size (float) – size of font
alpha (float) – transparency of the plots
fig_args (dict) – passed to pl.figure()
axis_args (dict) – passed to pl.subplots_adjust()
plot_args (dict) – passed to pl.plot()
do_show (bool) – whether to show the plot
fig (fig) – handle of existing figure to plot into
- story(uid, *args)[source]¶
Print out a short history of events in the life of the specified individual.
- Parameters:
uid (int/list) – the person or people whose story is being regaled
args (list) – these people will tell their stories too
Example:
sim = hpv.Sim(pop_type='hybrid', verbose=0) sim.run() sim.people.story(12) sim.people.story(795)