atomica.model.Population

class atomica.model.Population(framework, name, label, progset, pop_type)[source]

Bases: object

A class to wrap up data for one population within model. Each model population must contain a set of compartments with equivalent names.

Construct a Population

This function constructs a population instance. Aside from creating the Population, it also instantiates all of the integration objects defined in the Framework. Note that transfers and interactions aren’t added at this point - because they transcend populations, they are instantiated one level higher up, in model.build()

Parameters
  • framework – A ProjectFramework

  • name (str) – The code name of the population

  • label (str) – The full name of the population

  • progset (ProgramSet) – A ProgramSet instance

Attributes

name

The code name of the population

label

The full name/label of the population

type

The population's type

comps

List of Compartment objects

characs

List of Characteristic objects

links

List of Link objects

pars

List of Parameter objects

comp_lookup

Maps name of a compartment to a Compartment

charac_lookup

Maps name of a compartment to a Characteristic

par_lookup

Maps name of a parameter to a Parameter

link_lookup

Maps name of link to a list of Links with that name

Methods

build

Generate a compartmental cascade as defined in a settings object.

get_charac

Allow dependencies to be retrieved by name rather than index.

get_comp

Allow compartments to be retrieved by name rather than index.

get_links

Retrieve Links.

get_par

Allow dependencies to be retrieved by name rather than index.

get_variable

Return list of variables given code name

initialize_compartments

Set compartment sizes

popsize

Return population size

relink

unlink

build(framework, progset)[source]

Generate a compartmental cascade as defined in a settings object. Fill out the compartment, transition and dependency lists within the model population object. Maintaining order as defined in a cascade workbook is crucial due to cross-referencing.

The progset is required so that Parameter instances with functions can correctly identify dynamic quantities if they are only dynamic due to program overwrites.

charac_lookup

Maps name of a compartment to a Characteristic

characs

List of Characteristic objects

comp_lookup

Maps name of a compartment to a Compartment

comps

List of Compartment objects

get_charac(charac_name)[source]

Allow dependencies to be retrieved by name rather than index. Returns a Variable.

get_comp(comp_name)[source]

Allow compartments to be retrieved by name rather than index. Returns a Compartment.

Retrieve Links.

Return type

list

get_par(par_name)[source]

Allow dependencies to be retrieved by name rather than index. Returns a Variable.

get_variable(name)[source]

Return list of variables given code name

At the moment, names are unique across object types and within object types except for links, but if that logic changes, simple modifications can be made here

Link names in Atomica end in ‘par_name:flow’ so passing in a code name of this form will return links. Links can also be identified by the compartments that they connect. Allowed syntax is: - ‘source_name:’ - All links going out from source - ‘:dest_name’ - All links going into destination - ‘source_name:dest_name’ - All links from Source to Dest - ‘source_name:dest_name:par_name’ - All links from Source to Dest belonging to a given Parameter - ‘:dest:par_name’ - ‘source::par_name’ - As per above - ‘::par_name’ - All links with specified par_name (less efficient than ‘par_name:flow’)

Parameters

name (str) – Code name to search for

Return type

list

Returns

A list of Variables

initialize_compartments(parset, framework, t_init)[source]

Set compartment sizes

This method takes the databook values for compartments and characteristics, and uses them to compute the initial compartment sizes at ti=0. The computation is carried out by solving the linear matrix equation mapping characteristics to compartments. For this purpose, both compartments and characteristics in the databook are treated in the same way i.e. a databook compartment is treated like a characteristic containing only that compartment.

Parameters
  • parset (ParameterSet) – A py:class:ParameterSet instance with initial values for compartments/characteristics

  • framework – A py:class:ProjectFramework instance, used to identify and retrieve interaction terms

  • t_init (float) – The year to use for initialization. This should generally be set to the sim start year

Return type

None

label

The full name/label of the population

Maps name of link to a list of Links with that name

List of Link objects

name

The code name of the population

par_lookup

Maps name of a parameter to a Parameter

pars

List of Parameter objects

popsize(ti=None)[source]

Return population size

A population’s size is the sum of all of the people in its compartments, excluding birth and death compartments

Parameters

ti (Optional[int]) – Optionally specify a scalar time index to retrieve popsize for. `None corresponds to all times

Returns

If ti is specified, returns a scalar population size. If ti is None, return a numpy array the same size as the simulation time vector

type

The population’s type