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 populationlabel (
str
) – The full name of the populationprogset (
ProgramSet
) – A ProgramSet instance
Attributes
The code name of the population
The full name/label of the population
The population's type
List of Compartment objects
List of Characteristic objects
List of Link objects
List of Parameter objects
Maps name of a compartment to a Compartment
Maps name of a compartment to a Characteristic
Maps name of a parameter to a Parameter
Maps name of link to a list of Links with that name
Methods
Generate a compartmental cascade as defined in a settings object.
Allow dependencies to be retrieved by name rather than index.
Allow compartments to be retrieved by name rather than index.
Retrieve Links.
Allow dependencies to be retrieved by name rather than index.
Return list of variables given code name
Set compartment sizes
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.
- 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’)
- 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/characteristicsframework – 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:
- label¶
The full name/label of the population
- link_lookup¶
Maps name of link to a list of Links with that name
- links¶
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 (
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. Ifti
isNone
, return a numpy array the same size as the simulation time vector
- type¶
The population’s type