.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated\examples\tutorials\plot_model_fitting.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_model_fitting.py: =========================================================== Fitting models without motion correction =========================================================== This example illustrates how mdreg can be used to fit models without motion correction. The idea is illustrated for a 3D time series with variable flip angles (VFA), and a linear signal model fit. .. GENERATED FROM PYTHON SOURCE LINES 12-14 Setup ----- .. GENERATED FROM PYTHON SOURCE LINES 14-24 .. code-block:: Python import numpy as np import mdreg # Example data included in mdreg data = mdreg.fetch('VFA') # Variables used in this examples array = data['array'] # 4D signal data (x, y, z, FA) FA = data['FA'] # The FA values in degrees .. GENERATED FROM PYTHON SOURCE LINES 25-30 Perform model fit ----------------- The linear VFA signal model is included in `mdreg` as the function `mdreg.fit_spgr_vfa_lin`, which requires the flip angle (FA) values in degrees as input: .. GENERATED FROM PYTHON SOURCE LINES 30-37 .. code-block:: Python fit, pars = mdreg.fit_spgr_vfa_lin( array, # Signal data to fit FA=FA, # Flip angle in degrees progress_bar=True, # Set to True to show a progress bar ) .. rst-class:: sphx-glr-script-out .. code-block:: none Fitting VFA model: 0%| | 0/269568 [00:00
.. GENERATED FROM PYTHON SOURCE LINES 56-60 Pixel-by-pixel fitting ---------------------- Alternatively, the function `mdreg.fit_pixels` can be used to fit any single-pixel model directly: .. GENERATED FROM PYTHON SOURCE LINES 60-70 .. code-block:: Python fit, pars = mdreg.fit_pixels( array, model=mdreg.spgr_vfa, xdata=FA, func_init=mdreg.spgr_vfa_init, p0=[1,0.5], bounds=([0,0], [np.inf,1]), ) .. GENERATED FROM PYTHON SOURCE LINES 71-72 Check the model fit: .. GENERATED FROM PYTHON SOURCE LINES 72-79 .. code-block:: Python anim = mdreg.plot.animation( fit, title='VFA model fit', vmin=0, vmax=np.percentile(array, 99), ) .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (64 minutes 33.466 seconds) .. _sphx_glr_download_generated_examples_tutorials_plot_model_fitting.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_model_fitting.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_model_fitting.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_model_fitting.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_