.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated\examples\use_cases\plot_dce_liver.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_use_cases_plot_dce_liver.py: =========================================================== 3D DCE-MRI in the liver =========================================================== Fit a linear 2-compartment model to a 3D DCE dataset. Note: this is a large real-world dataset, and the computation may take several hours. In order to test this with a smaller dataset, you can use the `DCE_small` dataset. .. GENERATED FROM PYTHON SOURCE LINES 14-16 Setup ----- .. GENERATED FROM PYTHON SOURCE LINES 16-43 .. code-block:: Python import os import time import shutil import numpy as np import mdreg # We use zarray data in this example data = mdreg.fetch_zarr('DCE') # Variables used in this script tacq = data.attrs['time'] aif = data.attrs['aif'] spacing = data.attrs['spacing'] t0, t1 = 100, 150 # Path for output results_path = os.path.join(os.getcwd(), 'tmp') # Check the data anim = mdreg.plot.animation( data[:, :, :, t0:t1], title='DCE Data', vmin=0, vmax=0.9*np.max(data[...,0]), ) .. container:: sphx-glr-animation .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 44-48 Perform motion correction ------------------------- We fit the DCE data using a linearised 2-compartment model, using motion correction with default settings: .. GENERATED FROM PYTHON SOURCE LINES 48-66 .. code-block:: Python t = time.time() coreg, fit, transfo, pars = mdreg.fit( data, fit_image={ 'func': mdreg.fit_2cm_lin, 'time': tacq, # Acquisition times 'aif': aif, # Signal-time curve in the aorta 'baseline': 5, # Nr of precontrast samples }, maxit=3, path=results_path, verbose=2, ) print(f"Computation time: {round(time.time()-t)} seconds.") .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing.. Iteration 1: fitting signal model Fitting deformation field (iteration 1) Calculation time for iteration 1: 225.01013048887253 min Iteration 2: fitting signal model Fitting deformation field (iteration 2) Calculation time for iteration 2: 227.00593881607057 min Iteration 3: fitting signal model Fitting deformation field (iteration 3) Calculation time for iteration 3: 226.34060509999594 min Total calculation time: 682.6465732375781 min Computation time: 40966 seconds. .. GENERATED FROM PYTHON SOURCE LINES 67-68 Check the result .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. code-block:: Python anim = mdreg.plot.animation( coreg[:, :, :, t0:t1], title='DCE motion corrected', vmin=0, vmax=0.9*np.max(data[...,0]), ) .. container:: sphx-glr-animation .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 76-77 Cleanup disk .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: Python shutil.rmtree(results_path) .. rst-class:: sphx-glr-timing **Total running time of the script:** (686 minutes 12.632 seconds) .. _sphx_glr_download_generated_examples_use_cases_plot_dce_liver.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dce_liver.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dce_liver.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_dce_liver.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_