Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean CPU examples #196

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Examples
========

This is a collection of examples showing how to use mri-nufft to perform MR image reconstruction.
This is a collection of examples showing how to use MRI-nufft to perform MR image reconstruction.
2 changes: 1 addition & 1 deletion examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

"""

import sys
import runpy
import sys
from pathlib import Path

import matplotlib as mpl
Expand Down
6 changes: 1 addition & 5 deletions examples/example_2D_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
# are redundant across the different patterns, some of the documentation
# will refer to previous patterns for explanation.
#
# Note that most sources have not been added yet, but will be in the near
# future.
#

# External
import matplotlib.pyplot as plt
import numpy as np
from utils import show_argument, show_trajectory

# Internal
import mrinufft as mn
import mrinufft.trajectories.maths as mntm
from mrinufft import display_2D_trajectory
from utils import show_argument, show_trajectory


# %%
# Script options
Expand Down
9 changes: 4 additions & 5 deletions examples/example_3D_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# are redundant across the different patterns, some of the documentation
# will refer to previous patterns for explanation.
#
# Note that most sources have not been added yet, but will be in the near
# future. Also the examples hereafter only cover natively 3D trajectories
# Note that the examples hereafter only cover natively 3D trajectories
# or famous 3D trajectories obtained from 2D. Examples on how to use
# 2D-to-3D expansion methods will be presented over another page.
# tools to make 3D trajectories out of 2D ones are presented in
# :ref:`sphx_glr_generated_autoexamples_example_trajectory_tools.py`
#
# In this page in particular, we invite the user to manually run the script
# to be able to manipulate the plot orientations with the matplotlib interface
Expand All @@ -26,12 +26,11 @@
# External
import matplotlib.pyplot as plt
import numpy as np
from utils import show_argument, show_trajectory

# Internal
import mrinufft as mn
from mrinufft import display_2D_trajectory, display_3D_trajectory
from utils import show_argument, show_trajectory


# %%
# Script options
Expand Down
59 changes: 27 additions & 32 deletions examples/example_display_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
Trajectory display configuration
================================

The look of the display trajectories can be tweaked by using :py:class:`displayConfig`
An example to show how to customize trajectory displays.

You can tune these parameters to your own taste and needs.
The parameters presented here can be tuned to your own taste and needs
by using :py:class:`displayConfig`.
"""

import matplotlib as mpl
import matplotlib.pyplot as plt

# %%
import numpy as np

from mrinufft import display_2D_trajectory, display_3D_trajectory, displayConfig
from mrinufft.trajectories import conify, initialize_2D_spiral

# %%
# Script options
# ==============
# These options are used in the examples below to define trajectories and display options.

# Trajectory parameters
Nc = 120 # Number of shots
Ns = 500 # Number of samples per shot
Expand All @@ -26,7 +30,6 @@
subfigure_size = 6 # Figure size for subplots
one_shot = -5 # Highlight one shot in particular


# %%


Expand All @@ -47,28 +50,32 @@ def show_traj(traj, name, values, **kwargs):
# %%
#
# Trajectory displays
# ====================
# To show case the display parameters of trajectories, we will use the following trajectory
# The effect of trajectory parameter are explained in the :ref:`sphx_glr_generated_autoexamples_example_3D_trajectories.py` Example.
# ===================
#
# The following trajectory will be used to showcase the display parameters.
# The trajectory parameters are explained in the
# :ref:`sphx_glr_generated_autoexamples_example_3D_trajectories.py` example.

traj = conify(initialize_2D_spiral(Nc // 6, Ns), nb_cones=6)[::-1]

# %%
# ``linewidth``
# -------------
# The linewidth of the shot can be updated to have more or less empty space in the plot.
# The ``linewidth`` corresponds to the curve thickness, and can be changed
# to improve the shots visibility.
show_traj(traj, "linewidth", [0.5, 2, 4])

# %%
# ``palette``
# -----------
# The ``palette`` parameter allows to change the color of the shots.
# The ``palette`` parameter allows you to change the color of the shots.
show_traj(traj, "palette", ["tab10", "magma", "jet"])

# %%
# ``one_shot_color``
# ------------------
# The ``one_shot_color`` parameter allows to highlight one shot in particular.
# The ``one_shot_color`` parameter is used to highlight one shot in particular
# with a specified color.
with displayConfig(palette="viridis"):
show_traj(
traj, "one_shot_color", ["tab:blue", "tab:orange", "tab:green"], one_shot=-5
Expand All @@ -77,49 +84,37 @@ def show_traj(traj, name, values, **kwargs):
# %%
# ``nb_colors``
# -------------
# The ``nb_colors`` parameter allows to change the number of colors used to display the shots.

# The ``nb_colors`` parameter allows you to change the number of colors used from the
# specified color palette to display the shots.
show_traj(traj, "nb_colors", [1, 4, 10])


# %%
# Labels, titles and legends
# ==========================

# %%
# ``fontsize``
# ------------
# The ``fontsize`` parameter allows to change the fontsize of the labels /title

# The ``fontsize`` parameter changes the fontsize of the labels/titles.
show_traj(traj, "fontsize", [12, 18, 24])

# %%
# ``pointsize``
# -------------
# To show the gradient constraint violation we can use the ``pointsize`` parameter
# The ``pointsize`` parameter is used when showing the gradient constraint violations
# to change the violation point sizes.
show_traj(traj, "pointsize", [0.5, 2, 4], show_constraints=True)

# %%
# ``gradient_point_color`` and ``slewrate_point_color``
# -----------------------------------------------------
# The ``gradient_point_color`` and ``slewrate_point_color`` parameters allows to change the color of the points
# that are violating the gradient or slewrate constraints.

# The ``gradient_point_color`` and ``slewrate_point_color`` parameters allows you
# to change the color of the points where gradient or slew rate constraint violations
# are observed.
show_traj(
traj,
"slewrate_point_color",
["tab:blue", "tab:orange", "tab:red"],
show_constraints=True,
)


# %%
# Gradients profiles
# ==================

# %%

# %%

# %%

# %%
24 changes: 17 additions & 7 deletions examples/example_gif_2D.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
"""
=======================
2D Trajectories display
=======================
========================
Animated 2D trajectories
========================

A collection of 2D trajectories are generated and saved as a gif.
An animation to show 2D trajectory customization.

"""

import time

import joblib
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image, ImageSequence
import time

import mrinufft.trajectories.display as mtd
import mrinufft.trajectories.trajectory2D as mtt
from mrinufft.trajectories.display import displayConfig

# Options
# %%
# Script options
# ==============

Nc = 16
Ns = 200
Expand All @@ -29,7 +33,9 @@
duration = 150 # seconds


# Generation
# %%
# Trajectory generation
# =====================

# Initialize trajectory function
functions = [
Expand Down Expand Up @@ -125,6 +131,10 @@
]


# %%
# Animation rendering
# ===================

frame_setup = [
(f, i, name, arg)
for (name, f), args in list(zip(functions, arguments))
Expand Down
21 changes: 15 additions & 6 deletions examples/example_gif_3D.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
=======================
3D Trajectories display
=======================
========================
Animated 3D trajectories
========================

A collection of 3D trajectories are generated and saved as a gif.
An animation to show 3D trajectory customization.

"""

import time

import joblib
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -17,7 +18,9 @@
import mrinufft.trajectories.trajectory3D as mtt
from mrinufft.trajectories.display import displayConfig

# Options
# %%
# Script options
# ==============

Nc = 8 * 8
Ns = 200
Expand All @@ -30,7 +33,9 @@
duration = 150 # seconds


# Generation
# %%
# Trajectory generation
# =====================

# Initialize trajectory function
functions = [
Expand Down Expand Up @@ -134,6 +139,10 @@
]


# %%
# Animation rendering
# ===================

frame_setup = [
(f, i, name, arg)
for (name, f), args in list(zip(functions, arguments))
Expand Down
Loading
Loading