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

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

.. _sphx_glr_generated_gallery_15-epi_epi2D_sequence.py:


========================
2D echo-planar imaging
========================

A slice-selective excitation is followed by alternating readout gradients and
phase-encode blips that acquire multiple Cartesian lines in one echo train.
Spoilers suppress residual transverse coherence between repetitions.
Off-resonance phase accumulates during the train and produces geometric
distortion along the phase-encode axis. EPI supports rapid structural imaging
and functional MRI.

.. GENERATED FROM PYTHON SOURCE LINES 13-93








.. GENERATED FROM PYTHON SOURCE LINES 94-100

Single-shot acquisition
-----------------------

Every phase-encode line is acquired after one excitation. Echo-train length
equals the number of acquired lines and determines the accumulated
off-resonance phase across k-space.

.. GENERATED FROM PYTHON SOURCE LINES 100-118

.. code-block:: Python


    from pypulseqpp.sequences import epi2D_sequence

    diagram = epi2D_sequence(
        n_x=64,
        n_y=48,
        n_slices=1,
        n_shots=1,
        n_dummy=0,
        fat_saturation=True,
        tr=None,
    )
    single = epi2D_sequence(n_x=96, n_y=96, n_slices=1, n_shots=1, n_dummy=0)
    print(
        f"{diagram.num_blocks} blocks, {diagram.duration()[0] * 1e3:.1f} ms, "
        f"TE {diagram.get_definition('TE')[0] * 1e3:.2f} ms"
    )





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

 .. code-block:: none

    58 blocks, 50.6 ms, TE 22.14 ms




.. GENERATED FROM PYTHON SOURCE LINES 119-121

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

.. GENERATED FROM PYTHON SOURCE LINES 121-124

.. code-block:: Python


    diagram.paper_plot()




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





.. GENERATED FROM PYTHON SOURCE LINES 125-138

Segmentation and in-plane acceleration
--------------------------------------

Segmentation and in-plane acceleration both reduce echo-train length.
``n_shots`` interleaves the lines over several excitations, so every line is
still acquired. ``ry`` skips lines within one excitation and requires a
parallel-imaging reconstruction for the omitted lines. Off-resonance
:math:`\Delta f` adds a phase of :math:`2\pi \Delta f\, \mathrm{esp}`
per echo spacing :math:`\mathrm{esp}`. This phase is linear in :math:`k_y`
and displaces the image along the phase-encode axis by
:math:`\Delta f \cdot \mathrm{esp} \cdot N_\mathrm{etl}` pixels, where
:math:`N_\mathrm{etl}` is the echo-train length. Both segmentation and
acceleration reduce :math:`N_\mathrm{etl}` and therefore the displacement.

.. GENERATED FROM PYTHON SOURCE LINES 138-163

.. code-block:: Python


    segmented = epi2D_sequence(n_x=96, n_y=96, n_slices=1, n_shots=3, n_dummy=0)
    accelerated = epi2D_sequence(n_x=96, n_y=96, n_slices=1, ry=3, n_dummy=0, n_acs_y=0)

    designs = {"1 shot": single, "3 shots": segmented, "ry = 3": accelerated}






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

 .. code-block:: none

                echoes  trains  per train   TE (ms)  scan (ms)  px per Hz
    1 shot          96       1       96.0     55.94      108.3      0.100
    3 shots         96       3       32.0     23.46      131.6      0.035
    ry = 3          32       1       32.0     23.44       43.1      0.035




.. GENERATED FROM PYTHON SOURCE LINES 164-171

Echo traversal
--------------

The ordinate gives the phase-encode line acquired at each echo index. A
single shot traverses the axis one line at a time. A segmented acquisition
traverses it in steps of ``n_shots``, each shot starting one line further
on. An accelerated acquisition traverses it once in steps of ``ry``.

.. GENERATED FROM PYTHON SOURCE LINES 171-176




.. image-sg:: /generated/gallery/15-epi/images/sphx_glr_epi2D_sequence_002.png
   :alt: 1 shot, 3 shots, ry = 3
   :srcset: /generated/gallery/15-epi/images/sphx_glr_epi2D_sequence_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 177-183

Which lines are acquired
------------------------

Segmentation and acceleration produce the same train length from different
sets of lines: the segmented acquisition acquires every line, the accelerated
acquisition one line in three.

.. GENERATED FROM PYTHON SOURCE LINES 183-188




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





.. GENERATED FROM PYTHON SOURCE LINES 189-196

Functional MRI time series
---------------------------

Repeated frames form an fMRI time series. The acquisition below uses eight
slices in four multiband groups. ``REP`` identifies the volume and ``SLC``
identifies the group; acquisition times are the start times of the ADC
blocks in the sequence.

.. GENERATED FROM PYTHON SOURCE LINES 196-228

.. code-block:: Python


    fmri = epi2D_sequence(
        n_x=64,
        n_y=64,
        n_slices=8,
        multiband=2,
        n_frames=4,
        n_shots=1,
        n_dummy=0,
        fat_saturation=False,
        tr=1.0,
    )
    labels = fmri.evaluate_labels(evolution="adc")



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






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

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


.. _sphx_glr_download_generated_gallery_15-epi_epi2D_sequence.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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