.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated\examples\tutorials\plot_wex.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_tutorials_plot_wex.py: ======================================== An exploration of water exchange effects ======================================== This tutorial will explore the effect of water exchange in a standard two-compartmental tissue using the models in `dcmri.Tissue`. The three tissue compartments involved are the blood, interstitium and tissue cells. The water exchange effects refer to the transport of water across the barriers between them: **transendothelial** water exchange between blood and interstitium, and **transcytolemmal** water exchange between interstitium and tissue cells. The water exchange in the blood compartment between plasma and red blood cells is assumed to be in the fast exchange limit. Water exchange across either of these two barriers can be in the fast-exchange limit (F), restricted (R), or there may be no water exchange at all (N). Since there are two barriers involved this leads to 3x3=9 possible water exchange regimes. `dcmri.Tissue` denotes these 9 regimes by a combination of the letters F, R and N: the frst letter refers to the water exchange across the endothelium, and the second to the water exchange across the cell wall. For instance, 'FR' means fast water exchange (F) across the endothelium, and restricted water exchange (R) across the cell wall. For regimes with restricted water exchange, the rate of exchange is quantified by the permeability-surface area (PS) of water, a quantity in units of mL/sec/cm3. `dcmri.Tissue` uses the notation ``PSe`` for the transendothelial water PS and ``PSc`` for the transcytolemmal PS. .. GENERATED FROM PYTHON SOURCE LINES 32-36 Simulation setup ---------------- We set up the simulation by importing the necessary packages and defining the constants that will be fixed throughout. .. GENERATED FROM PYTHON SOURCE LINES 38-52 .. code-block:: Python import matplotlib.pyplot as plt import dcmri as dc # Generate a synthetic AIF with default settings t, aif, _ = dc.fake_aif(tacq=300) # Save AIF and its properties in a dictionary aif = { 't': t, 'aif': aif, 'r1': dc.relaxivity(3, 'blood', 'gadodiamide'), 'R10a': 1/dc.T1(3.0,'blood'), } .. GENERATED FROM PYTHON SOURCE LINES 53-63 The role of water exchange ---------------------------- To show how water exchange is relevant in DC-MRI analysis, it is insightful to first consider the extreme ends of the water exchange spectrum in some more detail: fast water exchange (F) and no water exchange (N). Let's first generate a tissue without water exchange across either barrier. We will use the more general model of restricted water exchange 'RR' and set the permeabilities to zero, as this then also plots the signals in individual compartments: .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: Python tissue_nn = dc.Tissue('2CX', 'RR', PSe=0, PSc=0, **aif) tissue_nn.plot() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_001.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 68-81 In this model the indicator and water occupy the same compartments, so the concentrations on the right are the same. The magnetization (bottom left) follows the profile of the indicator concentrations exactly: since magnetization cannot exchange, it cannot equilibrate and remains directly proportional to the concentration in the compartment. Notably, the magnetization in the tissue cells remains constant as no indicator can enter this compartment to modify it, and no magnetization can be transferred. Now lets consider the opposite scenario of fast water exchange across both barriers (*Note*: we could use the FF model here, but for the purposes of this illustration it is more instructive to use RR with very high values for the water permeabilities): .. GENERATED FROM PYTHON SOURCE LINES 81-85 .. code-block:: Python tissue_ff = dc.Tissue('2CX','RR', PSe=1e3, PSc=1e3, **aif) tissue_ff.plot() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_002.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-96 The indicator concentration in the tissue compartments is not affected by the level of water exchange (top and bottom right), but the magnetization in all 3 compartments is now effectively the same (bottom left). Even the tissue cells, which receive no indicator at all, show the same signal changes over time as the interstitium and blood compartments. This is because, with very high levels of water exchange, the magnetization between all 3 compartments mixes so rapidly that any differences are levelled out instantly. The tissue is well-mixed for water (and therefore water magnetization), although it is not well-mixed for indicator. .. GENERATED FROM PYTHON SOURCE LINES 98-101 Now let's consider the cases where one of the barriers is highly permeable for water, and the other is impermeable. First let's look at the case of high transendothelial water exchange and no transcytolemmal water exchange: .. GENERATED FROM PYTHON SOURCE LINES 101-105 .. code-block:: Python tissue_fn = dc.Tissue('2CX','RR', PSe=1e3, PSc=0, **aif) tissue_fn.plot() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_003.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 106-109 As expected, blood and interstitium have the same magnetization throughout and the magnetization of tissue cells is not altered at all. The opposite case is similar: .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. code-block:: Python tissue_nf = dc.Tissue('2CX','RR', PSe=0, PSc=1e3, **aif) tissue_nf.plot() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_004.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 114-116 In this case the tissue cells recieve the same magnetization as the interstitium. .. GENERATED FROM PYTHON SOURCE LINES 119-129 Water exchange effect on the MR signal -------------------------------------- From a measurement perspective, the important question is to what extent water exchange across either barrier affects the measured signal, shown in the top left corner of the plots above. To illustrate the signal differences in more detail, we plot signals in mixed exchange regimes against the extremes of fast and no exchange. For reference we also include a tissue with intermediate water exchange: .. GENERATED FROM PYTHON SOURCE LINES 129-163 .. code-block:: Python # Build a tissue in an intermediate water exchange regime tissue_rr = dc.Tissue('2CX','RR', PSe=1, PSc=2, **aif) # Generate signals in all regimes signal_ff = tissue_ff.signal() signal_nn = tissue_nn.signal() signal_fn = tissue_fn.signal() signal_nf = tissue_nf.signal() signal_rr = tissue_rr.signal() # Plot signals against extremes fig, ax = plt.subplots(1,3,figsize=(15,5)) ax[0].set_title("""No transendothelial exchange \n Fast transcytolemmal exchange""") ax[1].set_title("""Fast transendothelial exchange \n No transcytolemmal exchange""") ax[2].set_title("""Restricted transendothelial exchange \n Restricted transcytolemmal exchange""") ax[0].plot(t, signal_nf, 'r--', label='Mixed exchange') ax[1].plot(t, signal_fn, 'r--', label='Mixed exchange') ax[2].plot(t, signal_rr, 'r--', label='Restricted exchange') for axis in ax: axis.plot(t, signal_ff, 'g-', label='Fast exchange') axis.plot(t, signal_nn, 'b-', label='No exchange') axis.set_xlabel('Time (sec)') axis.set_ylabel('Signal (a.u.)') axis.legend() plt.show() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_005.png :alt: No transendothelial exchange Fast transcytolemmal exchange, Fast transendothelial exchange No transcytolemmal exchange, Restricted transendothelial exchange Restricted transcytolemmal exchange :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 164-173 These figures show clearly that water exchange levels have a measureable effect on signals, and at all times lie between the extremes of no water exchange (blue) and fast water exchange (green). However, while the effect of water exchange is detectable, it is comparatively small considering the difference between the blue and green curves represent the extremes. By contrast, changing the exchange rate of the indicator between its extremes of no- and infinite indicator exchange has a more significant impact on the signal: .. GENERATED FROM PYTHON SOURCE LINES 173-192 .. code-block:: Python tissue_2cx = dc.Tissue('2CX','RR', **aif) tissue_nx = dc.Tissue('2CX','RR', PS=0, **aif) tissue_fx = dc.Tissue('2CX','RR', PS=1e3, **aif) # Plot signals fig, ax = plt.subplots(1,1,figsize=(6,5)) ax.set_title('Fast vs no transendothelial indicator exchange') ax.plot(t, tissue_fx.signal(), 'g-', label='Fast indicator exchange') ax.plot(t, tissue_nx.signal(), 'b-', label='No indicator exchange') ax.plot(t, tissue_2cx.signal(), 'r--', label='Intermediate indicator exchange') ax.set_xlabel('Time (sec)') ax.set_ylabel('Signal (a.u.)') ax.legend() plt.show() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_006.png :alt: Fast vs no transendothelial indicator exchange :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 193-203 Water exchange bias ------------------- As shown above, water exchange is to some extent a second order effect compared to indicator exchange. Nevertheless, making inaccurate assumptions regarding the level of water exchange can lead to large biases in the other measured parameters. One way to explore the scale of this water exchange bias is by training a tissue that has no water exchange (NN) using data generated by a tissue in fast water exchange: .. GENERATED FROM PYTHON SOURCE LINES 203-209 .. code-block:: Python # Train a NN tissue on the fast-exchange signal and plot results tissue_nn = dc.Tissue('2CX', 'NN', **aif) tissue_nn.train(t, signal_ff) tissue_nn.plot(t, signal_ff) .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_007.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 210-213 The plot shows that the no-exchange tissue predicts the data with high accuracy. However, the reconstructed magnetization is incorrect for fast exchange tissue, and the reconstructed parameters are severely biased: .. GENERATED FROM PYTHON SOURCE LINES 213-221 .. code-block:: Python truth = tissue_ff.params('vp','vi','Ktrans') rec = tissue_nn.params('vp','vi','Ktrans') print('vp error:', round(100*(rec[0]-truth[0])/truth[0],1), '%') print('vi error:', round(100*(rec[1]-truth[1])/truth[1],1), '%') print('Ktrans error:', round(100*(rec[2]-truth[2])/truth[2],1), '%') .. rst-class:: sphx-glr-script-out .. code-block:: none vp error: 40.5 % vi error: 16.9 % Ktrans error: 0.9 % .. GENERATED FROM PYTHON SOURCE LINES 222-228 Removing water exchange bias ---------------------------- Water exchange forms a dangerous source of measurement error because it cannot be detected by comparing the fit to the data. In ideal circumstances, it can be removed by generalizing the model to allow for any level of water exchange. Let's try this and look at the results again: .. GENERATED FROM PYTHON SOURCE LINES 228-234 .. code-block:: Python # Train an RR tissue and plot again tissue = dc.Tissue('2CX','RR', **aif) tissue.train(t, signal_ff, xtol=1e-3) tissue.plot(t, signal_ff) .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_008.png :alt: MRI signals, Concentration in indicator compartments, Magnetization in water compartments, Concentration in water compartments :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 235-238 Plotting the results now show a practically perfect fit to the data, and the magnetization is close to the fast exchange limit. Also the measurements of the kinetic parameters are more accurate: .. GENERATED FROM PYTHON SOURCE LINES 238-244 .. code-block:: Python rec = tissue.params('vp','vi','Ktrans') print('vp error:', round(100*(rec[0]-truth[0])/truth[0],1), '%') print('vi error:', round(100*(rec[1]-truth[1])/-truth[1],1), '%') print('Ktrans error:', round(100*(rec[2]-truth[2])/truth[2],1), '%') .. rst-class:: sphx-glr-script-out .. code-block:: none vp error: 1.0 % vi error: -0.8 % Ktrans error: 0.7 % .. GENERATED FROM PYTHON SOURCE LINES 245-249 As a bonus the water-exchange sensitive model also estimates the water permeability. While a numerical fit will not produce the accurate result of infinite water PS, this nevertheless produces values that correspond to extremely high levels of water exchange: .. GENERATED FROM PYTHON SOURCE LINES 249-254 .. code-block:: Python rec = tissue.params('PSe', 'PSc', round_to=0) print('PSe:', rec[0], 'mL/sec/cm3') print('PSc:', rec[1], 'mL/sec/cm3') .. rst-class:: sphx-glr-script-out .. code-block:: none PSe: 106.0 mL/sec/cm3 PSc: 147.0 mL/sec/cm3 .. GENERATED FROM PYTHON SOURCE LINES 255-270 Handling water exchange ----------------------- The above example suggests one strategy of removing water exchange bias, i.e. include water exchange rates as free parameters and get the added benefit of a water exchange measurement. However this may not always be the right approach. The data in this tutorial are noise-free, and therefore even very subtle structure can be exploited to estimate parameters. In noisy data this may not be the case, and one may well be forced to fix parameters that have a relatively small effect on the data in order to improve the precision in others. This raises the question where any of the regimes of fast and zero water exchange offers a good approximation to real tissues. For this exercise we will assume values on the upper end of literature data. We plot the resulting signal against the extremes of fast and no exchange: .. GENERATED FROM PYTHON SOURCE LINES 270-289 .. code-block:: Python # Generate tissue tissue = dc.Tissue('2CX', 'RR', PSe=0.05, PSc=1.5, **aif) tissue_nn = dc.Tissue('2CX', 'NN', **aif) tissue_ff = dc.Tissue('2CX', 'FF', **aif) # Plot signals fig, ax = plt.subplots(1,1,figsize=(6,5)) ax.set_title('Restricted water exchange against extremes') ax.plot(t, tissue_ff.signal(), 'g-', label='Fast water exchange') ax.plot(t, tissue_nn.signal(), 'b-', label='No water exchange') ax.plot(t, tissue.signal(), 'r--', label='Restricted water exchange') ax.set_xlabel('Time (sec)') ax.set_ylabel('Signal (a.u.)') ax.legend() plt.show() .. image-sg:: /generated/examples/tutorials/images/sphx_glr_plot_wex_009.png :alt: Restricted water exchange against extremes :srcset: /generated/examples/tutorials/images/sphx_glr_plot_wex_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 290-299 With these settings, the restricated water exchange signal is approximately intermediate between fast and no water exchange. Hence neither approximation appears particulare more accurate than the alternative. However, the impact of water exchange also depends on the imaging sequence, such as the choice of flip angle. Hence these effects should be taken into account when optimizing the scan protocol. Water exchange sensitivity should be maximized for studies that aim to measure it, and minimized for studies where it is a confounder. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 26.212 seconds) .. _sphx_glr_download_generated_examples_tutorials_plot_wex.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_wex.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_wex.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_wex.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_