dcmri.flux_ncomp#

dcmri.flux_ncomp(J, T, E, t=None, dt=1.0, solver='diag', dt_prop=None)[source]#

Outfluxes out of a linear and stationary n-compartment system.

See section N-compartment system for more detail.

Parameters:
  • J (array_like) – the indicator flux entering the system, as a rectangular 2D array with dimensions (n,k), where n is the number of compartments and k is the number of time points in J.

  • T (array_like) – n-element array with mean transit times of each compartment.

  • E (array_like) – dimensionless and square n x n matrix. An off-diagonal element E[j,i] is the extraction fraction from compartment i to compartment j. A diagonal element E[i,i] is the extraction fraction from compartment i to the outside.

  • t (array_like, optional) – the time points of the indicator flux J, in the same units as T. If t is not provided, the time points are assumed to be uniformly spaced with spacing dt. Defaults to None.

  • dt (float, optional) – spacing between time points for uniformly spaced time points, in the same units as T. This parameter is ignored if t is explicity provided. Defaults to 1.0.

  • solver (str, optional) – A string specifying the numerical method for solving the system. Two options are available: with solver = 'diag' the system is solved by diagonalising the system matrix, with solver = 'prop' the system is solved by forward propagation. The default is 'diag'.

  • dt_prop (float, optional) – internal time resolution for the forward propagation when solver = 'prop'. This must be in the same units as T. If dt_prop is not provided, it defaults to the sampling interval, or the smallest time step needed for stable results (whichever is smaller). This argument is ignored when solver = 'diag'. Defaults to None.

Returns:

Outflux out of each compartment, and at each time point, as a 3D array with dimensions (n,n,k), where n is the number of compartments and k is the number of time points in J. Encoding of the first two indices is the same as for E: J[j,i,:] is the flux from compartment i to j, and J[i,i,:] is the flux from i directly to the outside.

Return type:

numpy.ndarray

Example

>>> import numpy as np
>>> import dcmri as dc

Consider a measurement with 10 time points from 0 to 20s, and a 2-compartment system with a constant influx in each compartment. The influx in compartment 1 is twice a large than in compartment 0:

>>> t = np.linspace(0, 20, 10)
>>> J = np.zeros((2, t.size))
>>> J[0,:] = 1
>>> J[1,:] = 2

The transit times are 6s for compartment 0 and 12s for compartment 1.

>>> T = [6,12]

The extraction fraction from compartment 0 to compartment 1 is 0.3 and the extraction fraction from 1 to 0 is 0.8. These are the off-diagonal elements of E. No indicator is trapped or created inside the system so the extraction fractions for each compartment must add up to 1. The extraction fractions to the outside are therefore 0.7 and 0.2 for compartment 0 and 1, respectively. These are the diagonal elements of E:

>>> E = [
...  [0.7, 0.8],
...  [0.3, 0.2]]

Calculate the outflux out of both compartments:

>>> J = dc.flux_ncomp(J, T, E, t)

The indicator flux out of compartment 0 to the outside is:

>>> J[0,0,:]
array([0.        , 0.25925926, 0.49931413, 0.71731951, 0.91301198,
1.0874238 , 1.24217685, 1.37910125, 1.50003511, 1.60672472])

The indicator flux from compartment 1 to 0 is:

>>> J[1,0,:]
array([0.        , 0.11111111, 0.21399177, 0.30742265, 0.39129085,
0.46603877, 0.53236151, 0.59104339, 0.64287219, 0.68859631])