In [1]:
import numpy as np
# plotting and graphics settings
import matplotlib.pyplot as plt
%pylab inline
try:
import seaborn as sns # pretty graphics. not strictly necessary.
sns.set_context("notebook")
sns.set_style("whitegrid")
except:
pass # with less pretty graphics
We can then load the data from the text file and store each of the three columns as a vector:
In [2]:
time, curve, aif = np.loadtxt('tests/tumor.csv', delimiter=',', unpack=True, comments='#')
print time[0:5]
print curve[0:5]
print aif[0:5]
This is not very enlightening. Of course, we can do better and plot the two curves.
In [3]:
f, (a1,a2)=plt.subplots(1,2)
a1.plot(time, aif, label='AIF')
a2.plot(time,curve, label='Tissue curve')
Out[3]:
This looks like a pretty arterial input function (left) and a tissue curve (right).
To further analyze this data, we need a library for model fitting. Here, we use https://github.com/michimichi/compartmentmodels. This particular library is currently under development, but in a usable status.
In [4]:
import compartmentmodels.compartmentmodels as CM
Experience tells that this curve needs to be fitted with a two-compartment exchange model:
In [5]:
twocx = CM.TwoCXModel(time, curve, aif,
startdict={'Fp':20.0, 'vp': 5.5, 'PS':0.1, 've':9.1})
twocx.fit_model()
Out[5]:
Let us examine the model fit:
In [6]:
f, a = plt.subplots(1,1)
a.plot(time, curve, label='Tissue curve')
a.plot(time, twocx.fit, label='Model fit')
plt.legend(loc=4)
Out[6]:
This fit produced the following parameters:
In [7]:
print twocx.phys_parameters
This concludes our quick demonstration of this library.