atomica.model.Link¶
- class atomica.model.Link(pop, parameter, source, dest)[source]¶
Bases:
Variable
A Link is a Variable that maps to a transition between compartments. As such, it contains an inflow and outflow compartment. A Link’s value is generally derived from a Parameter, and there may be multiple links that draw values from the same parameter. The value corresponds to the number transferred from the source compartment to the destination compartment in the subsequent timestep.
Some links do not have an associated Parameter object because their values are calculated by means other than parameters. For example
Flush links have their values calculated from the source timed compartment
Junction residual links have their values calculated by junction balancing
Attributes
Variable code name
Unique identifier for the integration object
The units for the quantity, used for plotting and for validation.
Reference back to the Population containing this object
Methods
Create and wire up a new link
Produce a time series plot
Preallocate data storage
relink
Make the variable a dependency
unlink
Update the value of the link
- classmethod create(pop, parameter, source, dest)[source]¶
Create and wire up a new link
This method instantiates a Link (including of derived types) and also wires it up to the population, parameter, source, and destination compartments. This allows the
Link
constructor to be used without needing the entire population infrastructure- Parameters:
pop – A
Population
instance that will contain the newLink
parameter – A
Parameter
instance that will supply values for the newLink
source – A
Compartment
instance to transfer fromdest – A
Compartment
instance to transfer to
- Returns:
The newly created
Link
instance
- id¶
Unique identifier for the integration object
- property name: str¶
Variable code name
This is implemented as a property method because the
id
of theVariable
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
- plot()[source]¶
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
- 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 parentModel
object. Thus, there is no duplication of storage there, andVariable.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.
- 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:
- 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, converted_frac)[source]¶
Update the value of the link
This method takes in the fraction of the source compartment to move, and updates the value of the link accordingly. In update_links, parameters are first all converted into timestep-based fractions. These fractions are then used to update the links. However, depending on whether the link stores compartment duration information, this update may or may not require the use of TimedCompartment properties. Therefore, updating the link is delegated to this Link method that can be overloaded in derived classes.