
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "generated/autoexamples/05-misc/01-synthetic-data.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_generated_autoexamples_05-misc_01-synthetic-data.py>`
        to download the full example code or to run this example in your browser via Binder.

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

.. _sphx_glr_generated_autoexamples_05-misc_01-synthetic-data.py:


=====================
Synthetic fingerprint
=====================

In this Application you build a training pair for MR fingerprinting: the
undersampled image series a scanner would produce, the fully sampled series it
approximates, and the T1, T2 and M0 maps they come from.

The pipeline segments a T1-weighted subject into grey matter, white matter and
CSF, assigns each class an M0, T1 and T2, simulates one fingerprint per class
with extended phase graphs, and mixes the fingerprints voxelwise by tissue
fraction. The volume is then weighted by birdcage coil sensitivities and
encoded with a frame-wise spiral NUFFT. The adjoint and a coil combination
return the image series. Only the simulation is blochsim's. torchio,
deepmriprep, SigPy and mri-nufft provide the subject, the segmentation, the
coils and the encoding.

Prerequisites: Course lessons :doc:`../01-framework/01-first-simulation`.

.. GENERATED FROM PYTHON SOURCE LINES 23-28

.. colab-link::
   :needs_gpu: 1

   !pip install blochsim matplotlib torchio deepmriprep sigpy cmap mri-nufft[finufft,cufinufft]
   !wget --quiet --no-clobber https://raw.githubusercontent.com/pulserver/blochsim/main/docs/figure_style.py

.. GENERATED FROM PYTHON SOURCE LINES 30-37

Setup
-----

Each package has one task here: torchio loads a T1-weighted IXI subject,
deepmriprep segments it with a U-Net and returns tissue probabilities,
``sigpy.mri`` generates birdcage coil sensitivities, and mri-nufft provides the
spiral trajectory and the non-uniform Fourier transform.

.. GENERATED FROM PYTHON SOURCE LINES 37-120

.. code-block:: Python

    import tempfile
    import time

    import mrinufft
    import numpy as np
    import sigpy.mri as smri
    import torch
    import torchio as tio

    from deepmriprep import Preprocess
    from mrinufft.trajectories import initialize_2D_spiral
    from pathlib import Path

    from blochsim.simulators import MRFSimulator









.. GENERATED FROM PYTHON SOURCE LINES 121-123

The pair has a 128 x 128 matrix, 400 frames with one spiral arm of 768 samples
each, and 8 receive channels.

.. GENERATED FROM PYTHON SOURCE LINES 123-135

.. code-block:: Python

    SIZE = 128
    FRAMES = 400
    SAMPLES = 768
    COILS = 8
    SLICE = 110  # axial, at the level of the lateral ventricles

    # The GPU transform is used when it is installed and usable, and the simulation
    # follows it so that the images and the operator are on one device.
    on_gpu = torch.cuda.is_available() and mrinufft.check_backend("cufinufft")
    device = "cuda" if on_gpu else "cpu"
    backend = "cufinufft" if on_gpu else "finufft"








.. GENERATED FROM PYTHON SOURCE LINES 136-144

Subject
-------

The only measurement the pipeline starts from is one IXI subject loaded by
torchio: a T1-weighted volume at 1.5 T. The segmentation reads it, and a table
supplies the tissue properties that a single contrast cannot give.
``download=True`` fetches the archive once, a few hundred MB, into a cache under
the home directory.

.. GENERATED FROM PYTHON SOURCE LINES 144-160

.. code-block:: Python

    CACHE = Path.home() / ".cache" / "blochsim" / "ixi-tiny"
    subject = tio.datasets.IXITiny(str(CACHE), download=True)[0]







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

 .. code-block:: none

    Downloading https://www.dropbox.com/s/ogxjwjxdv5mieah/ixi_tiny.zip?dl=1 to /tmp/tmppxehu0wk.zip
    0it [00:00, ?it/s]      0%|          | 0/233926107 [00:01<?, ?it/s]      3%|▎         | 6168576/233926107 [00:01<00:03, 57018117.25it/s]      6%|▋         | 14688256/233926107 [00:01<00:03, 72181460.03it/s]     11%|█         | 25255936/233926107 [00:01<00:02, 87090475.47it/s]     16%|█▌        | 37756928/233926107 [00:01<00:01, 99913738.55it/s]     20%|██        | 47587328/233926107 [00:02<00:01, 99099632.87it/s]     24%|██▍       | 56942592/233926107 [00:02<00:01, 91842973.20it/s]     29%|██▉       | 68034560/233926107 [00:02<00:01, 96254977.93it/s]     34%|███▍      | 80617472/233926107 [00:02<00:01, 104387179.52it/s]     41%|████      | 96460800/233926107 [00:02<00:01, 120666493.93it/s]     46%|████▋     | 108478464/233926107 [00:02<00:01, 117864154.84it/s]     51%|█████▏    | 120242176/233926107 [00:02<00:01, 71673685.56it/s]      58%|█████▊    | 135929856/233926107 [00:02<00:01, 88979188.20it/s]     63%|██████▎   | 147144704/233926107 [00:03<00:00, 90062406.27it/s]     70%|███████   | 164241408/233926107 [00:03<00:00, 109102931.94it/s]     76%|███████▋  | 178659328/233926107 [00:03<00:00, 117785845.15it/s]     82%|████████▏ | 191774720/233926107 [00:03<00:00, 113732744.06it/s]     89%|████████▉ | 207626240/233926107 [00:03<00:00, 124732136.76it/s]     94%|█████████▍| 220905472/233926107 [00:03<00:00, 102717239.62it/s]     99%|█████████▉| 232333312/233926107 [00:03<00:00, 98063789.86it/s]     233930752it [00:03, 59133707.30it/s]                               




.. GENERATED FROM PYTHON SOURCE LINES 161-167

Tissue classes
--------------

deepmriprep segments the head into grey matter, white matter and CSF with a
U-Net. It returns three probability maps, not one label per voxel, so the
phantom contains partial volume.

.. GENERATED FROM PYTHON SOURCE LINES 167-216

.. code-block:: Python

    NAMES = ("grey matter", "white matter", "CSF")

    segmentation = Preprocess().run(
        str(subject.image.path),
        output_paths={
            name: f"{tempfile.gettempdir()}/{name}.nii.gz" for name in ("p1", "p2", "p3")
        },
        run_all=False,
    )





.. image-sg:: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_001.png
   :alt: T1w, grey, white, CSF
   :srcset: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_001.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/brain_extraction_bbox_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/brain_extraction_bbox_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/brain_extraction_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/brain_extraction_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_nogm_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_nogm_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_0_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_0_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_1_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_1_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_2_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_2_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_3_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_3_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_4_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_4_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_5_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_5_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_6_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_6_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_7_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_7_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_8_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_8_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_9_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_9_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_10_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_10_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_11_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_11_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_12_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_12_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_13_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_13_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_14_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_14_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_15_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_15_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_16_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_16_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_patch_17_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_patch_17_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/segmentation_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/segmentation_model.pt
    Downloaded https://raw.githubusercontent.com/wwu-mmll/deepmriprep/main/deepmriprep/data/models/warp_model.pt to /opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/deepmriprep/data/models/warp_model.pt
    128x128 slice, 5733 brain voxels; 92% are a mixture of two tissues or more




.. GENERATED FROM PYTHON SOURCE LINES 217-224

The figure shows the T1-weighted contrast and the three probabilities.

Each class takes an M0, a T1 and a T2 from a table, here values at 1.5 T. A
T1-weighted volume is a contrast and not a map, so the table cannot be read
from this subject: the measurement gives the location and fraction of each
tissue, and the table gives its properties. A relaxometry protocol on the same
subject would fill the table from data.

.. GENERATED FROM PYTHON SOURCE LINES 224-238

.. code-block:: Python

    class_M0 = torch.tensor([0.80, 0.70, 1.00])  # relative proton density
    class_T1 = torch.tensor([1100.0, 650.0, 4000.0])  # ms
    class_T2 = torch.tensor([95.0, 70.0, 2000.0])  # ms






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

 .. code-block:: none


    tissue           voxels     M0  T1 (ms)  T2 (ms)
    grey matter        2428   0.80     1100     95.0
    white matter       2297   0.70      650     70.0
    CSF                 568   1.00     4000   2000.0




.. GENERATED FROM PYTHON SOURCE LINES 239-246

Simulation per class
--------------------

The sequence is an inversion followed by 400 repetitions whose flip angle
follows a sinusoidal schedule. :class:`~blochsim.simulators.MRFSimulator`
accepts tensor-valued tissue properties, so the three classes are simulated in
one call, as three EPG runs instead of one per voxel.

.. GENERATED FROM PYTHON SOURCE LINES 246-261

.. code-block:: Python

    schedule = 5.0 + 55.0 * torch.sin(torch.linspace(0.0, 4 * torch.pi, FRAMES)).abs()
    simulator = MRFSimulator(TR=12.0, TI=20.0, T1=class_T1, T2=class_T2)

    per_class = torch.as_tensor(simulator.simulate(flip=schedule))






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

 .. code-block:: none

    3 classes x 400 frames in 0.4s -> (3, 400)




.. GENERATED FROM PYTHON SOURCE LINES 262-270

Whole-brain volume
------------------

A voxel that is part grey matter and part CSF produces the sum of the two
fingerprints, weighted by the tissue fractions, and not the fingerprint of the
averaged relaxation times. An inversion-prepared train is strongly nonlinear in
T1, so averaging the parameters before simulating is wrong in every voxel that
is not pure. The mixing is a matrix product over the class fingerprints:

.. GENERATED FROM PYTHON SOURCE LINES 270-273

.. code-block:: Python

    weights = (fractions * class_M0).to(per_class.dtype)
    series = (weights @ per_class) * brain[..., None]








.. GENERATED FROM PYTHON SOURCE LINES 274-276

The ground-truth maps are the fraction-weighted averages of the class
parameters, the best result a single-compartment fit of this data can return:

.. GENERATED FROM PYTHON SOURCE LINES 276-281

.. code-block:: Python

    share = occupancy.clamp_min(1e-6)
    truth_M0 = (fractions @ class_M0) * brain
    truth_T1 = (fractions @ class_T1) / share * brain
    truth_T2 = (fractions @ class_T2) / share * brain








.. GENERATED FROM PYTHON SOURCE LINES 282-290

Coils and encoding
------------------

The coil sensitivities are birdcage maps from SigPy. Each frame is encoded by
one spiral arm, rotated by the golden angle from the previous frame, so
consecutive frames sample different parts of k-space. One arm of 768 samples
on a 128 x 128 matrix is about 21-fold undersampled, as in fingerprinting
acquisitions.

.. GENERATED FROM PYTHON SOURCE LINES 290-311

.. code-block:: Python

    sensitivities = torch.as_tensor(smri.birdcage_maps((COILS, SIZE, SIZE))).to(
        torch.complex64
    )
    trajectory = initialize_2D_spiral(
        FRAMES, SAMPLES, tilt="golden", nb_revolutions=8
    ).astype(np.float32)

    build = mrinufft.get_operator(backend)
    arms = [
        build(
            trajectory[frame], (SIZE, SIZE), n_coils=COILS, squeeze_dims=False, density=True
        )
        for frame in range(FRAMES)
    ]





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

 .. code-block:: none

    400 arms built in 29.7s




.. GENERATED FROM PYTHON SOURCE LINES 312-313

The forward transform takes the coil-weighted image of each frame to k-space:

.. GENERATED FROM PYTHON SOURCE LINES 313-351

.. code-block:: Python

    coil_series = (sensitivities[:, None] * series.movedim(-1, 0)[None]).to(device)

    kspace = torch.stack(
        [arms[frame].op(coil_series[:, frame][None])[0] for frame in range(FRAMES)]
    )




.. image-sg:: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_002.png
   :alt: coil 0, coil 1, coil 2, coil 3, 3 of 400 arms
   :srcset: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_002.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    forward NUFFT 7.4s -> (400, 8, 768)




.. GENERATED FROM PYTHON SOURCE LINES 352-360

The figure shows four of the eight coil sensitivities and three of the arms.

Reconstruction
--------------

Each frame is reconstructed by the adjoint transform, and the channels are
combined with the sensitivity maps. The maps are known here; a real pipeline
estimates them.

.. GENERATED FROM PYTHON SOURCE LINES 360-375

.. code-block:: Python


    folded = torch.stack(
        [arms[frame].adj_op(kspace[frame][None])[0] for frame in range(FRAMES)]
    )
    weights = sensitivities.to(device)
    combined = (folded * weights.conj()[None]).sum(1) / (
        weights.abs().square().sum(0)[None] + 1e-6
    )





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

 .. code-block:: none

    adjoint and combine 7.8s




.. GENERATED FROM PYTHON SOURCE LINES 376-384

Data pair
---------

The training input is the undersampled series ``combined`` and the target is the
fully sampled series ``series``. Each frame contains one spiral arm, so
aliasing in a single frame exceeds the signal, but the time course of each
voxel retains the fingerprint, which is what a fingerprinting reconstruction
uses. Both series are normalised to their peak magnitude.

.. GENERATED FROM PYTHON SOURCE LINES 384-431




.. image-sg:: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_003.png
   :alt: frame 0, frame 200, one voxel
   :srcset: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_003.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    per-frame error inside the brain :  60.3%
    time-course agreement            : median 0.894, tenth percentile 0.715




.. GENERATED FROM PYTHON SOURCE LINES 432-438

The printed error is the mean per-frame error in the brain. The time-course
agreement is the normalised inner product between the undersampled and the
fully sampled time course of each voxel.

Ground-truth maps
-----------------

.. GENERATED FROM PYTHON SOURCE LINES 438-451




.. image-sg:: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_004.png
   :alt: 01 synthetic data
   :srcset: /generated/autoexamples/05-misc/images/sphx_glr_01-synthetic-data_004.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 452-461

The T1 and T2 maps use perceptually uniform colormaps, one per relaxation
parameter, so that a T1 map is never read as a T2 map [1]_.

Export
------

The archive holds the pair, the ground-truth maps, the segmentation, and the
schedule and trajectory that produced them. It is written to a temporary
directory so that a documentation build leaves no file behind.

.. GENERATED FROM PYTHON SOURCE LINES 461-483

.. code-block:: Python

    contents = {
        "undersampled": undersampled.cpu().numpy(),
        "reference": reference.cpu().numpy(),
        "M0": truth_M0.numpy(),
        "T1": truth_T1.numpy(),
        "T2": truth_T2.numpy(),
        "tissue_probabilities": fractions.numpy(),
        "flip_angles_deg": schedule.numpy(),
        "trajectory": trajectory,
    }






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

 .. code-block:: none

    synthetic_mrf.npz  56.6 MiB
      undersampled     (400, 128, 128)      complex64
      reference        (400, 128, 128)      complex64
      M0               (128, 128)           float32
      T1               (128, 128)           float32
      T2               (128, 128)           float32
      tissue_probabilities (128, 128, 3)        float32
      flip_angles_deg  (400,)               float32
      trajectory       (400, 768, 2)        float32




.. GENERATED FROM PYTHON SOURCE LINES 484-518

Command-line interface
----------------------

To turn the script into a tool, replace three inputs and keep the rest:

- the torchio subject by a T1-weighted NIfTI, which is the contrast the
  segmentation was trained on;
- the generated spiral and sine schedule by a trajectory and a flip-angle
  schedule read from a matfile;
- the temporary directory by an output path.

The tissue table is the one input that is chosen and not read.

References
----------

.. [1] Fuderer M, et al. Color-map recommendation for MR relaxometry maps.
       Magn Reson Med 93(2):490-506 (2025).

Specification
-------------

What this Application did, stated the way you would ask an agent for it:

.. code-block:: text

   Build a synthetic MR fingerprinting training pair. Load an IXI subject with
   torchio and segment it into grey matter, white matter and CSF with
   deepmriprep. Give each class M0, T1 and T2 from a table at 1.5 T and
   simulate one inversion-prepared MRFSimulator train of 400 frames per class.
   Mix the fingerprints by tissue fraction, weight by 8 birdcage coils, encode
   with one golden-angle spiral arm per frame (mri-nufft), then reconstruct
   each frame by the adjoint and a coil combination. Report the per-frame error
   and the time-course agreement, and save the pair with the maps and schedule.


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

   **Total running time of the script:** (2 minutes 53.689 seconds)


.. _sphx_glr_download_generated_autoexamples_05-misc_01-synthetic-data.py:

.. only:: html

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

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pulserver/blochsim/gh-pages?urlpath=lab/tree/v0.0.17/notebooks/generated/autoexamples/05-misc/01-synthetic-data.ipynb
        :alt: Launch binder
        :width: 150 px

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

      :download:`Download Jupyter notebook: 01-synthetic-data.ipynb <01-synthetic-data.ipynb>`

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

      :download:`Download Python source code: 01-synthetic-data.py <01-synthetic-data.py>`

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

      :download:`Download zipped: 01-synthetic-data.zip <01-synthetic-data.zip>`


.. only:: html

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

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