Skip to content

Commit

Permalink
3D radial trajectory bundle (clean) (#115)
Browse files Browse the repository at this point in the history
* Add four 3D radial trajectories

* Add documentation & references to all 3D radial trajectories

* Add examples and references, refactor trajectory example display functions

* Fix coding style

* Add utils example to ignore list

* Try relative imports for utils

* fix: examples files can import local files.

---------

Co-authored-by: Pierre-antoine Comby <pierre-antoine.comby@crans.org>
  • Loading branch information
Daval-G and paquiteau authored Jul 1, 2024
1 parent ba54f49 commit c61f716
Show file tree
Hide file tree
Showing 11 changed files with 515 additions and 194 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ A benchmark of NUFFT backend for MRI applications is available in https://github


Who is using MRI-NUFFT?
----------------------
-----------------------

Here are several project that rely on MRI-NUFFT:

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"examples_dirs": ["../examples/"],
"gallery_dirs": ["generated/autoexamples"],
"filename_pattern": "/example_",
"ignore_pattern": r"/(__init__|conftest)\.py",
"ignore_pattern": r"/(__init__|conftest|utils)\.py",
"nested_sections": True,
}

Expand Down
2 changes: 2 additions & 0 deletions examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import sys
import runpy
from pathlib import Path

Expand Down Expand Up @@ -45,6 +46,7 @@ class ScriptItem(pytest.Item):

def runtest(self):
"""Run the script as a test."""
sys.path.insert(0, str(self.path.parent))
runpy.run_path(str(self.path))

def repr_failure(self, excinfo):
Expand Down
73 changes: 22 additions & 51 deletions examples/example_2D_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,7 @@
import mrinufft as mn
import mrinufft.trajectories.maths as mntm
from mrinufft import display_2D_trajectory


# Util function to display varying arguments
def show_argument(function, arguments, one_shot, subfigure_size):
# Initialize trajectories with varying option
trajectories = [function(arg) for arg in arguments]

# Plot the trajectories side by side
fig = plt.figure(
figsize=(len(trajectories) * subfigure_size, subfigure_size),
constrained_layout=True,
)
subfigs = fig.subfigures(1, len(trajectories))
for subfig, arg, traj in zip(subfigs, arguments, trajectories):
ax = display_2D_trajectory(
traj,
size=subfigure_size,
one_shot=one_shot,
subfigure=subfig,
)
ax.set_aspect("equal")
ax.set_title(str(arg), fontsize=4 * subfigure_size)
plt.show()


def show_trajectory(trajectory, one_shot, figure_size):
ax = display_2D_trajectory(trajectory, size=figure_size, one_shot=one_shot)
ax.set_aspect("equal")
plt.tight_layout()
plt.show()
from utils import show_argument, show_trajectory


# %%
Expand Down Expand Up @@ -108,7 +79,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [8, 16, 32, 64]
function = lambda x: mn.initialize_2D_radial(x, Ns, tilt=tilt, in_out=in_out)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -122,7 +93,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [8, 16, 32, 64]
function = lambda x: mn.initialize_2D_radial(Nc, x, tilt=tilt, in_out=in_out)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -138,7 +109,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = ["uniform", "golden", "mri-golden", np.pi / 17]
function = lambda x: mn.initialize_2D_radial(Nc, Ns, tilt=x, in_out=in_out)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -161,7 +132,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [True, False]
function = lambda x: mn.initialize_2D_radial(Nc, Ns, tilt=tilt, in_out=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -203,7 +174,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
function = lambda x: mn.initialize_2D_spiral(
Nc, Ns, tilt=tilt, nb_revolutions=x, in_out=in_out
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -227,7 +198,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = ["galilean", "archimedes", "fermat", 1 / 4]
function = lambda x: mn.initialize_2D_spiral(Nc, Ns, tilt=tilt, spiral=x, in_out=in_out)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -254,7 +225,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
Ns,
patch_center=x,
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -300,7 +271,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
Ns,
spiral_reduction=x,
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -326,7 +297,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
Ns,
patch_center=x,
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -366,7 +337,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
function = lambda x: mn.initialize_2D_cones(
Nc, Ns, tilt=tilt, in_out=in_out, nb_zigzags=x
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -381,7 +352,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [0.2, 1, 2, 3]
function = lambda x: mn.initialize_2D_cones(Nc, Ns, tilt=tilt, in_out=in_out, width=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -446,7 +417,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [2, 3, 4, 6]
function = lambda x: mn.initialize_2D_propeller(Nc, Ns, nb_strips=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -483,7 +454,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [Nc, int(2 * Nc / 3), int(Nc / 3)]
function = lambda x: mn.initialize_2D_rings(Nc=x, Ns=Ns, nb_rings=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)

# %%
#
Expand All @@ -494,7 +465,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [Nc, int(4 * Nc / 3), 2 * Nc]
function = lambda x: mn.initialize_2D_rings(Nc=x, Ns=Ns, nb_rings=Nc)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -534,7 +505,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [0, 1, 5, 10]
function = lambda x: mn.initialize_2D_rosette(Nc, Ns, in_out=in_out, coprime_index=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -574,7 +545,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
function = lambda x: mn.initialize_2D_polar_lissajous(
Nc, Ns, in_out=in_out, coprime_index=x
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -597,7 +568,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
function = lambda x: mn.initialize_2D_polar_lissajous(
Nc, Ns, in_out=in_out, nb_segments=x
)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -622,7 +593,7 @@ def show_trajectory(trajectory, one_shot, figure_size):
Nc, Ns, in_out=io, coprime_index=cpi, nb_segments=x
)
show_argument(
function, arguments, one_shot=one_shot, subfigure_size=subfigure_size
function, arguments, one_shot=one_shot, subfig_size=subfigure_size
)


Expand Down Expand Up @@ -658,7 +629,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [1, 2.5, 5, 10]
function = lambda x: mn.initialize_2D_waves(Nc, Ns, nb_zigzags=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand All @@ -677,7 +648,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [0, 1, 1.5, 3]
function = lambda x: mn.initialize_2D_waves(Nc, Ns, width=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down Expand Up @@ -712,7 +683,7 @@ def show_trajectory(trajectory, one_shot, figure_size):

arguments = [1, 1.5, 2, 3]
function = lambda x: mn.initialize_2D_lissajous(Nc, Ns, density=x)
show_argument(function, arguments, one_shot=one_shot, subfigure_size=subfigure_size)
show_argument(function, arguments, one_shot=one_shot, subfig_size=subfigure_size)


# %%
Expand Down
Loading

0 comments on commit c61f716

Please sign in to comment.