atomica.model.Compartment

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

Bases: Variable

A class to wrap up data for one compartment within a cascade network.

Attributes

name

Variable code name

outflow

Return the outflow at all times

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 and convert to number

set_dynamic

Make the variable a dependency

unlink

update

Update compartment value

connect(dest, par)[source]

Construct link out of this compartment

Parameters:
  • dest – A Compartment instance

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

Return type:

None

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

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)

Preallocate data storage

This method gets called just before integration, once the final sizes of the arrays are known. Performance is improved by preallocating the arrays. The tvec attribute is assigned as-is, so it is typically a reference to the array stored in the parent Model object. Thus, there is no duplication of storage there, and Variable.tvec is mainly for convenience when interpolating or plotting.

This method may be overloaded in derived classes to preallocate other variables specific to those classes.

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

  • dt (float) – Time step size

Return type:

None

resolve_outflows(ti)[source]

Resolve outgoing links and convert to number

For the base class, rescale outgoing links so that the compartment won’t go negative

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

A compartment update passes in the time to assign (ti). We have

x(ti) = x(ti-1) + inflow(ti-1) - outflow(ti-1)

Thus, need to initialize the value and then resolve all inflows and outflows Junctions have already been flushed and thus do not need to be updated in this step

Parameters:

ti (int)

Return type:

None

Returns: