atomica.model.TimedCompartment

class atomica.model.TimedCompartment(pop, name, parameter)[source]

Bases: Compartment

Instantiate the TimedCompartment

Preallocation takes place before the compartment values are initialized. Therefore, we need to calculate the duration here, hence there is a need to take in the parset here.

Parameters:
  • pop – A Population instance (the instance that will store this compartment)

  • name (str) – The name of the compartment

  • parameter (Parameter) – The parameter that will supply the duration (to be read after the parameter function is evaluated, if applicable)

Attributes

duration_group

name

Variable code name

outflow

Return the outflow at all times

vals

Compartment size

parameter

The parameter to read the duration from - this needs to be done after parameters are precomputed though, in case the duration is coming from a (constant) function

flush_link

Reference to the timed outflow link that flushes the compartment.

id

Unique identifier for the integration object

units

The units for the quantity, used for plotting and for validation.

pop

Reference back to the Population containing this object

Methods

connect

Construct link out of this compartment

expected_duration

expected_outflow

plot

Produce a time series plot

preallocate

Preallocate data storage

relink

resolve_outflows

Resolve outgoing links

set_dynamic

Make the variable a dependency

unlink

update

Update compartment value

connect(dest, par)[source]

Construct link out of this compartment

For TimedCompartments, outgoing links are TimedLinks if the downstream compartment belongs to the same duration group. For this purpose, a junction can be part of a duration group if all of the downstream junction outputs are in this compartment’s duration group.

Parameters:
  • dest – A Compartment instance

  • par – The parameter that the Link will be associated with

Return type:

None

Reference to the timed outflow link that flushes the compartment. Note that this needs to be set externally because Links are instantiated after Compartments

id

Unique identifier for the integration object

property name: str

Variable code name

This is implemented as a property method because the id of the Variable is a tuple containing the population name and the variable code name, so this property method returns just the variable code name portion. That way, storage does not need to be duplicated.

Returns:

A code name

property outflow: array

Return the outflow at all times

Returns:

The sum of outgoing links at all time indices

parameter

The parameter to read the duration from - this needs to be done after parameters are precomputed though, in case the duration is coming from a (constant) function

plot()

Produce a time series plot

This is a quick function to make a basic line plot of this Variable. Mainly intended for debugging. Production-ready plots should be generated using the plotting library functions instead

Return type:

None

pop

Reference back to the Population containing this object

preallocate(tvec, dt)[source]

Preallocate data storage

Parameters:
  • tvec (array) – An array of time values

  • dt (float) – Time step size

Return type:

None

resolve_outflows(ti)[source]

Resolve outgoing links

At this point, all links going out of the compartment would have had their ._cache value set to the fraction to transfer. This method converts them to numbers, taking into account the fact that only certain subcompartments are eligible for timed links within the same duration group

Parameters:

ti (int) – Time index at which to update link outflows

Return type:

None

set_dynamic(**kwargs)

Make the variable a dependency

For Compartments and Links, this does nothing. For Characteristics and Parameters, it will set the dynamic flag, but in addition, any validation constraints e.g. a Parameter that depends on Links cannot itself be dynamic, will be enforced.

This method generally must be overloaded in derived classes e.g. Parameter.set_dynamic()

Return type:

None

units

The units for the quantity, used for plotting and for validation. Note that the default 'unknown' units are distinct to dimensionless units, which have value ''

update(ti)[source]

Update compartment value

This compartment update goes from ti-1 to ti. As part of this, the counts for each duration are rolled over.

Parameters:

ti (int) – Time index to step to

Return type:

None

property vals: array

Compartment size

This returns the compartment size at all times, obtained by summing over the people in each time bin

Returns:

A numpy array with the compartment size