.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/anatomical/example_EPI_2D.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_auto_examples_anatomical_example_EPI_2D.py: Single anatomical volume with 2D EPI with SNAKE-fMRI ==================================================== This examples walks through the elementary components of SNAKE. Here we proceed step by step and use the Python interface. A more integrated alternative is to use the CLI ``snake-main`` .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: Python # Imports import numpy as np from snake.core.simulation import SimConfig, default_hardware, GreConfig from snake.core.phantom import Phantom from snake.core.smaps import get_smaps from snake.core.sampling import EPI3dAcquisitionSampler .. GENERATED FROM PYTHON SOURCE LINES 23-25 Setting up the base simulation Config. This configuration holds all key parameters for the simulation, describing the scanner parameters. .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python sim_conf = SimConfig( max_sim_time=3, seq=GreConfig(TR=50, TE=30, FA=3), hardware=default_hardware, ) sim_conf.hardware.n_coils = 8 sim_conf.fov.res_mm = (3,3,3) sim_conf .. raw:: html
SimConfig
max_sim_time(float)3
seq(GreConfig)
GreConfig
TR (float)TE (float)FA (float)
50303
hardware(HardwareConfig)
HardwareConfig
gmax (float)smax (float)n_coils (int)dwell_time_ms (float)raster_time_ms (float)field (float)
4020080.0010.0053.0
fov(FOVConfig)
FOVConfig
size (ThreeFloats)offset (ThreeFloats)angles (ThreeFloats)res_mm (ThreeFloats)
(181, 217, 181)(-90.25, -126.25, -72.25)(0, 0, 0)(3, 3, 3)
rng_seed(int)19290506


.. GENERATED FROM PYTHON SOURCE LINES 37-46 Creating the base Phantom ------------------------- The simulation acquires the data describe in a phantom. A phantom consists of fuzzy segmentation of head tissue, and their MR intrinsic parameters (density, T1, T2, T2*, magnetic susceptibilities) Here we use Brainweb reference mask and values for convenience. .. GENERATED FROM PYTHON SOURCE LINES 46-53 .. code-block:: Python phantom = Phantom.from_brainweb(sub_id=4, sim_conf=sim_conf, output_res=1) # Here are the tissue availables and their parameters phantom .. rst-class:: sphx-glr-script-out .. code-block:: none No matrix size found in the header. The header is probably missing. Phantom[brainweb-{sub_id:02d}]: (12, 5) tissue name PropTissueEnum.T1PropTissueEnum.T2PropTissueEnum.T2sPropTissueEnum.rhoPropTissueEnum.chi vessels 1600.080.070.0 1.0-9.0 wm 500.070.061.00.7699999809265137-9.050000190734863 muscles 900.050.040.0 1.0-9.050000190734863 skull 300.0 1.0 1.00.10000000149011612-8.859999656677246 dura 1000.0100.050.00.6000000238418579-9.050000190734863 marrow 1000.050.040.0 1.0-9.050000190734863 csf 4000.02000.02000.0 1.0-9.050000190734863 muscles_skin 2569.0329.058.0 1.0-9.050000190734863 gm 900.090.069.00.8600000143051147-9.050000190734863 fat 250.070.060.0 1.0-7.789999961853027 bck 800.0800.0800.0 0.00.36000001430511475 fat2 250.070.060.0 1.0-7.789999961853027 .. GENERATED FROM PYTHON SOURCE LINES 54-56 Setting up Acquisition Pattern and Initializing Result file. ------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 56-67 .. code-block:: Python # The next piece of simulation is the acquisition trajectory. # Here nothing fancy, we are using a EPI (fully sampled), that samples a 3D # k-space (this akin to the 3D EPI sequence of XXXX) sampler = EPI3dAcquisitionSampler(accelz=1, acsz=0.1, orderz="top-down") smaps = None if sim_conf.hardware.n_coils > 1: smaps = get_smaps(sim_conf.shape, n_coils=sim_conf.hardware.n_coils) .. GENERATED FROM PYTHON SOURCE LINES 68-78 Acquisition with Cartesian Engine --------------------------------- The generated file ``example_EPI.mrd`` does not contains any k-space data for now, only the sampling trajectory. let's put some in. In order to do so, we need to setup the **acquisition engine** that models the MR physics, and get sampled at the specified k-space trajectory. Here, we have a single frame to acquire with 60 slice (one EPI per slice), so a single worker will be enough. .. GENERATED FROM PYTHON SOURCE LINES 78-92 .. code-block:: Python from snake.core.engine import EPIAcquisitionEngine engine = EPIAcquisitionEngine(model="T2s", slice_2d=True) # use the 2D epi. engine( "example_EPI2D.mrd", sampler=sampler, phantom=phantom, sim_conf=sim_conf, worker_chunk_size=20, n_workers=2, ) .. rst-class:: sphx-glr-script-out .. code-block:: none Using 2D acquisition, the TR_eff is updated to TR_vol Existing example_EPI2D.mrd it will be overwritten [Errno 2] No such file or directory: 'example_EPI2D.mrd' 0%| | 0/60 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_EPI_2D.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_EPI_2D.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_