People#
- class People(pars, strict=True, pop_trend=None, pop_age_trend=None, **kwargs)[source]#
Bases:
BasePeopleA 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.BasePeopletakes 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)
Attributes
abnormalBoolean array of everyone with abnormal cells.
alive_indsIndices of everyone alive
alive_level0Indices of everyone alive who is a level 0 agent
alive_level0_indsIndices of everyone alive who is a level 0 agent
dt_ageReturn ages rounded to the nearest whole timestep
f_indsIndices of everyone female
infectedBoolean array of everyone infected.
int_ageReturn ages as an integer
is_activeBoolean array of everyone sexually active i.e. past debut.
is_femaleBoolean array of everyone female
is_female_adultBoolean array of everyone eligible for screening
is_female_aliveBoolean array of everyone female and alive
is_maleBoolean array of everyone male
is_male_aliveBoolean array of everyone male and alive
is_virginBoolean array of everyone not yet sexually active i.e. pre debut.
latentBoolean array of everyone with latent infection.
m_indsIndices of everyone male
n_aliveNumber of people alive
n_alive_level0Number of people alive
precinBoolean array of females with HPV whose disease severity level does not meet the threshold for detectable cell changes
round_ageRounds age up to the next highest integer
Methods
- 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 :type inds: :param inds: indices of women to set severity for :type g: :param g: genotype index :type dt: :param dt: timestep :type set_sev: :param set_sev: whether or not to set initial severity
- create_partnerships(tind, mixing, layer_probs, f_cross_layer, m_cross_layer, dur_pship, acts, age_act_pars)[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, sex_ratio=0.5, hiv_prevalence=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)