
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "generated/gallery/12-mprage/mprage3D_sequence.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_generated_gallery_12-mprage_mprage3D_sequence.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_generated_gallery_12-mprage_mprage3D_sequence.py:


====================
3D Cartesian MPRAGE
====================

An inversion preparation is followed after the prescribed inversion delay by a
train of low-flip-angle spoiled Cartesian gradient echoes. The inversion time
is measured to the first excitation centre; the corresponding central ADC
sample occurs one TE later. The ordering assigns recovery times within each
inversion cycle to ``(line, partition)`` views. MPRAGE is used for
high-resolution 3D T1-weighted structural imaging.

.. GENERATED FROM PYTHON SOURCE LINES 13-69








.. GENERATED FROM PYTHON SOURCE LINES 70-79

Timing structure
----------------

Each cycle comprises inversion, crusher, inversion delay, spoiled
gradient-echo train and recovery interval. ``ti=None`` and ``tr=None`` take the
shortest inversion time and recovery supported by the modules. Four lines per
partition provide a compact timing diagram. Clinical matrices typically
require inversion times of several hundred milliseconds and much
longer readout trains.

.. GENERATED FROM PYTHON SOURCE LINES 79-89

.. code-block:: Python


    from pypulseqpp.sequences import mprage3D_sequence

    compact = mprage3D_sequence(n_x=128, n_y=4, n_z=4, ti=None, tr=None, n_dummy=0)
    print(
        f"{compact.num_blocks} blocks, {compact.duration()[0]:.2f} s, "
        f"TI {compact.get_definition('TI')[0] * 1e3:.0f} ms, "
        f"TR {compact.get_definition('TR')[0] * 1e3:.0f} ms"
    )





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    80 blocks, 0.16 s, TI 8 ms, TR 41 ms




.. GENERATED FROM PYTHON SOURCE LINES 90-92

.. code-block:: Python

    compact.paper_plot()




.. image-sg:: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_001.png
   :alt: mprage3D sequence
   :srcset: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 93-104

Sampling order
--------------

At a protocol matrix, each inversion cycle acquires the sampled lines of one
partition:
the inversion cycle is constant along each row of the map, and the index
within the train runs outward from the centre of the line axis. The centre of
k-space is therefore the first view in a train. ``TI`` is measured from the
inversion-pulse centre to that view's excitation-pulse centre; the central
ADC sample occurs one echo time later, at ``TI + TE``. Peripheral lines are
acquired later in the recovery.

.. GENERATED FROM PYTHON SOURCE LINES 104-117

.. code-block:: Python


    protocol = mprage3D_sequence(n_x=192, n_y=128, n_z=24, ti=0.9, tr=2.3, n_dummy=0)
    print(
        f"{protocol.duration()[0]:.1f} s, "
        f"{int(np.asarray(protocol.evaluate_labels(evolution='adc')['ECO']).max()) + 1} "
        "readouts in the longest train, "
        f"central ADC at {(protocol.get_definition('TI')[0] + protocol.get_definition('TE')[0]) * 1e3:.1f} ms"
    )





.. image-sg:: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_002.png
   :alt: mprage3D sequence
   :srcset: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_002.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    55.2 s, 128 readouts in the longest train, central ADC at 904.0 ms




.. GENERATED FROM PYTHON SOURCE LINES 118-127

Accelerated sampling
--------------------

``ry`` and ``rz`` subsample the line and partition axes. ``caipi_shift``
offsets the sampled partitions between adjacent lines to control the alias
distribution. Fewer lines per partition reduce both train duration and the
range of inversion-recovery weighting. Scan duration equals the number of
inversion cycles multiplied by TR; the fully sampled calibration region still
requires every partition.

.. GENERATED FROM PYTHON SOURCE LINES 127-143

.. code-block:: Python


    accelerated = mprage3D_sequence(
        n_x=192, n_y=128, n_z=24, ry=2, rz=2, caipi_shift=1, ti=0.9, tr=2.3, n_dummy=0
    )





.. image-sg:: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_003.png
   :alt: mprage3D sequence
   :srcset: /generated/gallery/12-mprage/images/sphx_glr_mprage3D_sequence_003.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

                     views   cycles  per train  scan (s)
    1 x 1             2391       24       99.6      55.2
    2 x 2, shift 1     883       24       36.8      55.2





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.852 seconds)


.. _sphx_glr_download_generated_gallery_12-mprage_mprage3D_sequence.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: mprage3D_sequence.ipynb <mprage3D_sequence.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: mprage3D_sequence.py <mprage3D_sequence.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: mprage3D_sequence.zip <mprage3D_sequence.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
