People#

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)

Attributes

abnormal

Boolean array of everyone with abnormal cells.

alive_inds

Indices of everyone alive

alive_level0

Indices of everyone alive who is a level 0 agent

alive_level0_inds

Indices of everyone alive who is a level 0 agent

dt_age

Return ages rounded to the nearest whole timestep

f_inds

Indices of everyone female

infected

Boolean array of everyone infected.

int_age

Return ages as an integer

is_active

Boolean array of everyone sexually active i.e. past debut.

is_female

Boolean array of everyone female

is_female_adult

Boolean array of everyone eligible for screening

is_female_alive

Boolean array of everyone female and alive

is_male

Boolean array of everyone male

is_male_alive

Boolean array of everyone male and alive

is_virgin

Boolean array of everyone not yet sexually active i.e. pre debut.

latent

Boolean array of everyone with latent infection.

m_inds

Indices of everyone male

n_alive

Number of people alive

n_alive_level0

Number of people alive

precin

Boolean array of females with HPV whose disease severity level does not meet the threshold for detectable cell changes

round_age

Rounds age up to the next highest integer

Methods

init_flows()[source]#

Initialize flows to be zero

scale_flows(inds)[source]#

Return the scaled versions of the flows – replacement for len(inds) followed by scale factor multiplication

increment_age()[source]#

Let people age by one timestep

initialize(sim_pars=None)[source]#

Perform initializations

update_states_pre(t, year=None)[source]#

Perform all state updates at the current timestep

update_states_post(t, year=None)[source]#

State updates at the end of the current timestep

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

dissolve_partnerships(t=None)[source]#

Dissolve partnerships

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

check_progress(what, genotype)[source]#

Wrapper function for all the new progression checks

check_cin(genotype)[source]#

Check for new progressions to CIN

check_cancer(genotype)[source]#

Check for new progressions to cancer

check_cancer_deaths()[source]#

Check for new deaths from cancer

check_clearance(genotype)[source]#

Check for HPV clearance.

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)[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)

remove_people(inds, cause=None)[source]#

Remove people - used for death and migration

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)