sarpy.PKanalysis package

Submodules

sarpy.PKanalysis.PKModels module

sarpy.PKanalysis.PKfitlib module

Functions around modelling of contrast agent uptiake in tissue mostly inspired by the 2-Comparment eXchange Model (2CXM) paper by Sourbron and Buckley paper.

sarpy.PKanalysis.PKfitlib.AIC_from_SSE(SSE=None, k=None, N=None)[source]

AIC is formally defined as 2k - 2ln(L)

Assumption of gaussian noise around measured values leads to minimizing SSE as the best strategy to maximize the likelihood of obtaining the optimal parameters in nonlinear regression.

Hence, AIC becomes:

AIC = N ln (SSE/N) + 2k N … number of data points SSE … sum square of errors k … number of fit parameters + 1 (since you’re also estimating SSE)

Note: this seems to imply that L = (SSE/N)^(-N/2) for Gaussian error

The 2nd-order corrected AIC (for finite sample sizes)

AICc= AIC + 2K(K+1) / (N-K-1)

Note: You need at least 3 more data points than parameters.

sarpy.PKanalysis.PKfitlib.AIF_factory(model='Lyng')[source]

Arterial Input Function factory

Sets up a function that will correspond to one of several possible (literature) AIFs. Model (default=’Lyng’) determines the choice of AIF:

ModelString

‘Lyng’ … from Lyng 1998 - mice, same Gd

‘Checkley’ … from Checkley ???

‘Pickup’ … from Pickup 2004 - mice

‘Fritz-Hansen’ … not sure and hence not implemented FIXME

(f, vfunc)2-tupel of functions

A function that accepts 1D float parameters (time). and a function that accepts a vector of floats

Will raise a TypeError exception on unkown AIFs

>>> a=AIF_factory(model='Lyng')
choosing Lyng AIF    
>>> a[0](0)
6.5
>>> a[1](array([0,1,2])
array([ 6.5       ,  6.0893048 ,  5.70760869])
sarpy.PKanalysis.PKfitlib.AIF_model(parms, time)[source]

Create AIF with linear upslope and single exponential decay.

sarpy.PKanalysis.PKfitlib.TwoCXM_factory(time_axis, t0, AIFmodel=None)[source]

2CXM

Sourbron provides an analytical solution in Quantification of cerebral blood flow, cerebral blood volume, and blood-brain-barrier leakage with DCE-MRI Sourbron et al, Magnetic Resonance in Medicine Volume 62, Issue 1, pp 205

time_axis: float array

time points for which to calculate concentrations

t0: int

time of contrast arrival - AIF needs to be shifted by that much

AIFmodel: string(None)

used by AIF_factory

params: 4-element float array

[Em, Kp, Km, Fp]

!! not supplied to this factory function but needed in calls to the returned function handle - just thought we should mention this here

conc: function handle

2XCM function evaluated at the locations of time_axis, t, with params as parameters (see comment above):

conc(params, t) = Fp * numpy.convolve(res(t), AIF(t), mode=’valid’)

sarpy.PKanalysis.PKfitlib.aif(t, t0=0, aifchoice=None, zeropad=False)[source]

arterial input function by Lyng

t: scalar or vector

time in min

t0: scalar (default = 0)

shift (+ to the left) of start, units of t

aifchoiceString

‘Lyng’ … from Lyng 1998 - mice, same Gd

‘Checkley’ … from Checkley D et al “Use of dynamic contrast-enhanced MRI to evaluate acute treatment with ZD6474, a VEGF signalling inhibitor, in PC-3 prostate tumours. Br J Cancer, 89(10), 1889–1895. Retrieved from http://dx.doi.org/10.1038/sj.bjc.6601386

‘Pickup’ … from Pickup 2004 - mice

‘Fritz-Hansen’ … not sure and hence not implemented FIXME

zeropad: boolean (default = False)

return zero-padded AIF to the left with len(t)-1 zeros

returns a tupel of the AIF and (if requested) a zeropadded AIF

sarpy.PKanalysis.PKfitlib.bounds_penalty(parms, bounds)[source]

implementation of a check to see whether a list of parameters is within the given bounds. A bound is a 2D array

Interesting observation that the awkward loop is faster (by a lot!) than if numpy.any(parms<bounds[0]) or numpy.any(parms>bounds[1]):

return 1e9

else:

return 0.0

The performance is even worse if you start messing with numpy.sign

sarpy.PKanalysis.PKfitlib.conc_2CXM(t, modelparams, ca, dt)[source]

concentration time curve (see eqn [8]) from 2 parameter exchange model

t: time (vector)

modelparams: (PS, Fpl, ve, vp) (4-tupel)

ca: arterial input function (vector), should have length of 2*len(t)-1 to allow ‘valid’ convolution with impulse response function

concentration time curve for time points t

sarpy.PKanalysis.PKfitlib.conc_Tofts(t, modelparams, ca, dt)[source]

concentration time curve (see eqn [1]) from simple Tofts model

t: time (vector)

modelparams: (Ktrans, ve) (2-tupel)

ca: arterial input function (vector), should have length of 2*len(t)-1 to allow ‘valid’ convolution with impulse response function

concentration time curve for time points t

sarpy.PKanalysis.PKfitlib.conc_XTofts(t, modelparams, ca, dt)[source]

concentration time curve (see eqn [2]) from extended Tofts model. The ad-hoc vascular term is included in addition to the convolution with the Tofts residue, tissue response function.

t: time (vector)

modelparams: (Ktrans, ve, vp) (3-tupel)

ca: arterial input function (vector), should have length of 2*len(t)-1 to allow ‘valid’ convolution with impulse response function

concentration time curve for time points t

sarpy.PKanalysis.PKfitlib.create_model_AIF(parms, time_axis, modify_rate=False, shift_h=False, shift_v=False, shift_arriv=False, scale=False, epsilon=None)[source]

Create AIF for different rates (alphas), and fixed parameters from fit of data with AIF_model function.

coopyright Tammo Rukat, 2013

sarpy.PKanalysis.PKfitlib.fit_2CXM(t, ca, data, p0)[source]

fit the 2CXM with its four parameters to some data

t: time (vector)

ca: AIF (vector) note that len(ca)=2*len(t)-1 for ‘valid’ convolution
e.g.

ca = aif(t,aifchoice=’Lyng’) ca = numpy.concatenate((numpy.zeros(len(t)-1), ca))

data: concentration time curve (vector)

p0: starting guess (4-tupel)

modelparameters: (ve, vp, PS, Fpl) (4-tupel

sarpy.PKanalysis.PKfitlib.fit_double_2CXM(t, ca1, ca2, data1, data2, p0)[source]

fit the 2CXM with its four parameters to some data that has been acquired with two(!) contrast agents

t: time (vector)

ca1, ca2: AIF for Gd-DTPA and HPG-Gd data1: concentration measured (Gd-DTPA)

data2: concentration measured (HPG-Gd)

p0: starting guess (4-tupel)

modelparameters: (ve, vp, PS, Fpl) (4-tupel)

sarpy.PKanalysis.PKfitlib.fit_generic(t, data, model, p0, *pargs, **kwargs)[source]

fit a generic function

t: time (vector) data: concentration time curve (vector) model: function handle p0: starting guess

*pargs ca: AIF (vector) note that len(ca)=2*len(t)-1 for ‘valid’ convolution e.g. ca = aif(t,aifchoice=’Lyng’)

ca = numpy.concatenate((numpy.zeros(len(t)-1), ca))

**kwargs fit_subset: vector (or slice) to define the subset of model results to

be evaluated (default: slice(None))

modelparameters: tupel depending on model success: as handed back from optimize.leastsq() fit: best fit ss_err: sum-of-squares rsquare: R**2 Tip: —- Always consult docs: http://wiki.scipy.org/Cookbook/FittingData

sarpy.PKanalysis.PKfitlib.fit_generic_array(t, data, model, p0, *pargs, **kwargs)[source]

wrapper for fit_generic but data is a 4D array instead of a one-dimensional vector :mask: describes a 3D mask :data: is a 4D array with the first three dimensions matched by

the data

sarpy.PKanalysis.PKfitlib.fit_scn(scn_to_analyse=None, use_stitch=True, model_ID='Tofts', AIF_ID='Checkley', roi_mask_label='auc60_roi', gd_conc_label='gd_conc', **kwargs)[source]

routine for remote running. allowed AIFs = ‘Moroz’,’Checkley’,’Lyng’ and whatever else is defined in modeule PKfitlib Required modules are

sarpy.PKanalysis.PKfitlib.heaviside(time, tau)[source]

Heaviside function for use in AIF model.

sarpy.PKanalysis.PKfitlib.hierarchical_fit_2CXM(t, ca, data, p0)[source]

Follow the suggestion by Sourbron & Buckley wrt fitting models of increasing complexity

sarpy.PKanalysis.PKfitlib.paramconv_modeltosoln(params)[source]

convert models used to set up the model (PS, Fpl, ve, vp) into parameters more useful in the solution (Fp, Fm, Kp, Km)

function paramconv_solntomodel() is the inversion

sarpy.PKanalysis.PKfitlib.paramconv_solntomodel(params)[source]

convert models used to set up the model (PS, Fpl, ve, vp) into parameters more useful in the solution (Fp, Fm, Kp, Km)

this is the inverse of paramconf_modeltosoln()

sarpy.PKanalysis.PKfitlib.rel_prob_from_AIC(AICs, axis=- 1)[source]

Relative probabilities for models whose AIC values are given

Parameters
  • AICs (ndarray) – array that contains the calculated AIC for every model under consideration

  • axis (int) – axis along which the model AIC are organized in the AICs array default: -1 (last value)

The model with a minimum AIC will have a rel likelihood of 1. The other models will have a likelihood indicating the probability (relative to the minimum one) to minimize the information loss due to using a candidate model to represent the “true” model.

sarpy.PKanalysis.PKfitlib.residual_2CXM(t, params)[source]

tissue response function params = (Fp, Fm, Kp, Km)

sarpy.PKanalysis.PKfitlib.residual_Tofts(t, params)[source]

simple Tofts tissue response function - see equation [37] and [38]i

params = (Ktrans, ve)

sarpy.PKanalysis.PKfitlib_testdrive module

sarpy.PKanalysis.visualize_2CXM module

Module contents