
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "generated/gallery/15-epi/epi3D_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_15-epi_epi3D_sequence.py>`
        to download the full example code.

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

.. _sphx_glr_generated_gallery_15-epi_epi3D_sequence.py:


========================
3D echo-planar imaging
========================

A slab-selective excitation is followed by alternating readout gradients with
phase-encode and partition blips. The sampled ``(line, partition)`` views form
a CAIPIRINHA lattice [BRE06]_, and segmented skipped-CAIPI traversal [STI21]_
distributes the lattice among shots. Spoilers suppress residual
transverse coherence between repetitions; off-resonance accumulates during
each echo train. 3D EPI supports rapid structural and functional imaging.

.. GENERATED FROM PYTHON SOURCE LINES 13-144








.. GENERATED FROM PYTHON SOURCE LINES 145-152

Accelerated acquisition
-----------------------

The first configuration uses in-plane and partition acceleration, three
shots per shell, and a nonzero CAIPI shift. Each shot reads every third sampled lattice line;
successive echoes therefore contain both the skipped-line displacement and
the partition jump.

.. GENERATED FROM PYTHON SOURCE LINES 152-171

.. code-block:: Python


    from pypulseqpp.sequences import epi3D_sequence

    baseline = epi3D_sequence(
        n_x=64,
        n_y=64,
        n_z=16,
        ry=2,
        rz=4,
        n_shots=3,
        n_dummy=0,
    )
    print(f"{baseline.num_blocks} blocks, {baseline.duration()[0]:.2f} s")
    print(
        f"CAIPI shift {int(baseline.get_definition('CaipiShift')[0])}, "
        f"TE {baseline.get_definition('TE')[0] * 1e3:.2f} ms, "
        f"TR {baseline.get_definition('TR')[0] * 1e3:.1f} ms"
    )





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

 .. code-block:: none

    228 blocks, 0.19 s
    CAIPI shift 2, TE 8.83 ms, TR 189.4 ms




.. GENERATED FROM PYTHON SOURCE LINES 172-174

Sequence diagram
----------------

.. GENERATED FROM PYTHON SOURCE LINES 174-177

.. code-block:: Python


    baseline.paper_plot()




.. image-sg:: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_001.png
   :alt: epi3D sequence
   :srcset: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 178-192

Skipped-CAIPI traversal
-----------------------

Each cell of the lattice is one ``(line, partition)`` view, shaded where it
is sampled. Lines and arrows connect consecutive echoes within each train. No
line joins separate shots. The panel title gives the pattern as
:math:`S \cdot (R_y \times R_z)_{z\Delta z}`, with accelerations
:math:`R_y` and :math:`R_z`, segmentation factor :math:`S` (shots per shell)
and CAIPI shift :math:`\Delta z` as defined in [STI21]_. The partition jumps between consecutive echoes
are the CAIPI blips: they alternate between amplitudes
:math:`b^{(1)} = (S \cdot \Delta z) \bmod R_z` and
:math:`b^{(2)} = (R_z - b^{(1)}) \bmod R_z` partitions, and the pattern
repeats every :math:`n` echoes. Equivalent shells are folded onto one lattice cell; a small
vertical display offset separates coincident paths from different shots.

.. GENERATED FROM PYTHON SOURCE LINES 192-199




.. image-sg:: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_002.png
   :alt: $3\cdot{2\times4}_{z2}$:  $b^{(1)}=2,\ b^{(2)}=2,\ n=2$
   :srcset: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 200-208

Single-shot comparison
----------------------

With ``n_shots=1``, one longer echo train acquires the same lattice for
each shell. Three shots shorten each echo train and therefore the geometric
distortion along the phase-encode axis. The phase-encode step between
consecutive echoes of a segmented train spans three sampled lattice lines,
so its blips are larger than those of the single-shot train.

.. GENERATED FROM PYTHON SOURCE LINES 208-245

.. code-block:: Python


    single_shot = epi3D_sequence(
        n_x=64,
        n_y=64,
        n_z=16,
        ry=2,
        rz=4,
        n_shots=1,
        n_dummy=0,
    )






.. image-sg:: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_003.png
   :alt: $3\cdot{2\times4}_{z2}$:  $b^{(1)}=2,\ b^{(2)}=2,\ n=2$, $1\cdot{2\times4}_{z2}$:  $b^{(1)}=2,\ b^{(2)}=2,\ n=2$
   :srcset: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_003.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

               echoes  trains  per train   TE (ms)
    3 shots       120      12       10.0      8.83
    1 shot        128       4       32.0     17.10




.. GENERATED FROM PYTHON SOURCE LINES 246-253

In-plane acceleration
---------------------

``ry`` subsamples phase-encode lines, reducing echo-train length and
increasing lattice spacing along :math:`k_y`. The sampled views remain on a
single CAIPIRINHA lattice, whose CAIPI shift determines the positions of the
aliases [BRE06]_.

.. GENERATED FROM PYTHON SOURCE LINES 253-274

.. code-block:: Python


    accelerated = epi3D_sequence(
        n_x=64,
        n_y=64,
        n_z=16,
        ry=3,
        rz=2,
        n_shots=3,
        n_dummy=0,
    )
    print(
        f"ry=3, rz=2: CAIPI shift {int(accelerated.get_definition('CaipiShift')[0])}, "
        f"{accelerated.num_blocks} blocks, {accelerated.duration()[0]:.2f} s"
    )





.. image-sg:: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_004.png
   :alt: $3\cdot{3\times2}_{z1}$:  $b^{(1)}=1,\ b^{(2)}=1,\ n=2$
   :srcset: /generated/gallery/15-epi/images/sphx_glr_epi3D_sequence_004.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    ry=3, rz=2: CAIPI shift 1, 384 blocks, 0.32 s




.. GENERATED FROM PYTHON SOURCE LINES 275-287

References
----------

.. [BRE06] Breuer FA, Blaimer M, Mueller MF, Seiberlich N, Heidemann RM,
   Griswold MA, Jakob PM. Controlled aliasing in volumetric parallel imaging
   (2D CAIPIRINHA). *Magnetic Resonance in Medicine*. 2006;55(3):549-556.
   https://doi.org/10.1002/mrm.20787

.. [STI21] Stirnberg R, Stöcker T. Segmented K-space blipped-controlled
   aliasing in parallel imaging for high spatiotemporal resolution EPI.
   *Magnetic Resonance in Medicine*. 2021;85(3):1540-1551.
   https://doi.org/10.1002/mrm.28486


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

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


.. _sphx_glr_download_generated_gallery_15-epi_epi3D_sequence.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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