From 7827b5066a971152d4c7aac3dbd81792c28dcb14 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Thu, 25 Apr 2024 10:51:15 +0200 Subject: [PATCH] fix doc --- docs/advanced_guide/writing_config_file.md | 8 ------- docs/examples/example_big.py | 11 +++++----- docs/examples/example_shepp_logan.py | 9 ++++---- .../example_simulation_with_factory.py | 22 +++++++++++-------- docs/examples/example_vds_simrec.py | 15 ++++++------- src/snkf/handlers/acquisition/base.py | 4 ++++ src/snkf/handlers/motion/__init__.py | 3 +++ src/snkf/handlers/motion/image.py | 2 -- src/snkf/handlers/motion/kspace.py | 8 +++---- 9 files changed, 40 insertions(+), 42 deletions(-) diff --git a/docs/advanced_guide/writing_config_file.md b/docs/advanced_guide/writing_config_file.md index 88e2cce..ce48662 100644 --- a/docs/advanced_guide/writing_config_file.md +++ b/docs/advanced_guide/writing_config_file.md @@ -4,11 +4,3 @@ ``` - -```{include} ../../../src/snkf/conf/simulation/sl_basic.yaml -``` - - - - - diff --git a/docs/examples/example_big.py b/docs/examples/example_big.py index fd4f50e..556beb9 100644 --- a/docs/examples/example_big.py +++ b/docs/examples/example_big.py @@ -1,12 +1,11 @@ # %% [markdown] -""" -# Custom Phantom and ROI +# # Custom Phantom and ROI -In this example we are going to show the different way to generate phantom data, using -the BIG phantom. -This phantom is more realistic than the Shepp-Logan Phantom, but is a 2D phantom. -""" +# In this example we are going to show the different way to generate phantom data, using +# the BIG phantom. +# This phantom is more realistic than the Shepp-Logan Phantom, but is a 2D phantom. +# %% import matplotlib.pyplot as plt from snkf.handlers.phantom._big import generate_phantom, raster_phantom diff --git a/docs/examples/example_shepp_logan.py b/docs/examples/example_shepp_logan.py index 98a0ff7..b758c81 100644 --- a/docs/examples/example_shepp_logan.py +++ b/docs/examples/example_shepp_logan.py @@ -1,10 +1,9 @@ # %% [markdown] -""" -# Generate a 3d+t Simple Phantom - -In this example we simulate a 3D phantom and add a simple activation pattern. -""" +# # Generate a 3d+t Simple Phantom +# +# In this example we simulate a 3D phantom and add a simple activation pattern. +# %% import matplotlib.pyplot as plt from snkf.simulation import SimData diff --git a/docs/examples/example_simulation_with_factory.py b/docs/examples/example_simulation_with_factory.py index 6d9d4ba..3a26d72 100644 --- a/docs/examples/example_simulation_with_factory.py +++ b/docs/examples/example_simulation_with_factory.py @@ -1,11 +1,9 @@ # %% [markdown] -""" -# Using a simulation configuration file +# # Using a simulation configuration file -This example present how to use a simulation config file. -""" +# This example present how to use a simulation config file. +# %% -import io # to simulate a file access. from snkf import load_from_yaml @@ -18,6 +16,7 @@ # # For instance to create a 2D+T +# %% sim_config = """ ### Simulation for a Shepp Logan phantom with activation. @@ -47,17 +46,22 @@ # %% [markdown] # ```{note} -# In the handlers section, the name of each handler matter! -# it is the key for finding the related handler object. -# They will be processed in order. +# In the handlers section, the name of each handler matter! +# it is the key for finding the related handler object. +# They will be processed in order. # ``` # # ## Launching the simulation # # Thanks to the detailled configuration it is as simple as: -# equivalent to +# %% + +# The two following lines are equivalent to # with open("your_config.yaml") as config_file: + +import io # to simulate a file access. + with io.StringIO(sim_config) as config_file: simulator, sim = load_from_yaml(config_file) diff --git a/docs/examples/example_vds_simrec.py b/docs/examples/example_vds_simrec.py index e96870b..6d3fb04 100644 --- a/docs/examples/example_vds_simrec.py +++ b/docs/examples/example_vds_simrec.py @@ -1,9 +1,6 @@ # %% [markdown] -""" -# Simulation and Reconstruction - -This example shows how to simulate and reconstruct a simple 2D vds simulation. -""" +# # Simulation and Reconstruction +# This example shows how to simulate and reconstruct a simple 2D vds simulation. # %% @@ -40,7 +37,7 @@ # # We initialize the simulator from the availables handlers -# %% +# %% execution={"timeout": "1000"} print(list_handlers()) simulator = ( @@ -80,7 +77,7 @@ # # Simple adjoint fourier transform. -# %% +# %% execution={"timeout": "1000"} adj_data = ZeroFilledReconstructor().reconstruct(sim) @@ -89,7 +86,8 @@ # %% [markdown] # ### Sequential Reconstruction -# %% +# %% execution={"timeout": "1000"} + seq_data = SequentialReconstructor( max_iter_per_frame=20, threshold="sure", compute_backend="numpy" ).reconstruct(sim) @@ -98,6 +96,7 @@ # %% [markdown] # ### LowRank + Sparse Reconstruction +# %% execution={"timeout": "1000"} lr_s = LowRankPlusSparseReconstructor( lambda_l=0.1, lambda_s="sure", algorithm="otazo_raw", max_iter=20 ).reconstruct(sim) diff --git a/src/snkf/handlers/acquisition/base.py b/src/snkf/handlers/acquisition/base.py index 7437c97..0d71528 100644 --- a/src/snkf/handlers/acquisition/base.py +++ b/src/snkf/handlers/acquisition/base.py @@ -284,10 +284,14 @@ class NonCartesianAcquisitionHandler(BaseAcquisitionHandler): The MRI acquisition is modelled as follows: .. math:: + s(t) = \int_{\Omega} \rho(x,t) \exp(-2i\pi k(t) \cdot x) dx + where :math:`\rho` is the object, :math:`k(t)` is the k-space trajectory. + In practice: .. math:: + s(t) = \sum_{x \in \Omega} \rho(x,t) \exp(-2i\pi k(t) \cdot x) \Delta x """ diff --git a/src/snkf/handlers/motion/__init__.py b/src/snkf/handlers/motion/__init__.py index 02f26bc..f7215f4 100644 --- a/src/snkf/handlers/motion/__init__.py +++ b/src/snkf/handlers/motion/__init__.py @@ -1,3 +1,6 @@ """Motion Module.""" from .image import RandomMotionImageHandler +from .kspace import RandomMotionKspaceHandler + +__all__ = ["RandomMotionImageHandler", "RandomMotionKspaceHandler"] diff --git a/src/snkf/handlers/motion/image.py b/src/snkf/handlers/motion/image.py index 29773a1..3f52111 100644 --- a/src/snkf/handlers/motion/image.py +++ b/src/snkf/handlers/motion/image.py @@ -3,8 +3,6 @@ import numpy as np from numpy.typing import NDArray -from snkf.base import validate_rng - from ...simulation import SimData from ..base import AbstractHandler, requires_field from .utils import apply_shift, apply_rotation_at_center, motion_generator diff --git a/src/snkf/handlers/motion/kspace.py b/src/snkf/handlers/motion/kspace.py index 8b386a0..c28b2de 100644 --- a/src/snkf/handlers/motion/kspace.py +++ b/src/snkf/handlers/motion/kspace.py @@ -6,11 +6,11 @@ """ import numpy as np -from np.typing import NDArray +from numpy.typing import NDArray from ...simulation import SimData from ..base import AbstractHandler, requires_field -from .utils import motion_generator, rotation3D +from .utils import motion_generator, rotation3d @requires_field(["kspace_data", "kspace_mask"]) @@ -36,7 +36,7 @@ class RandomMotionKspaceHandler(AbstractHandler): time resolution for the simulation. """ - __handler_name__ = "motion-image" + __handler_name__ = "motion-kspace" ts_std_mm: tuple[float, float, float] rs_std_mm: tuple[float, float, float] @@ -104,7 +104,7 @@ def rotate(kspace_loc_to_corrupt: NDArray, rotation: NDArray) -> NDArray: """ new_loc = np.zeros_like(kspace_loc_to_corrupt) for t in range(kspace_loc_to_corrupt.shape[0]): - R = rotation3D(rotation[:, t]) + R = rotation3d(rotation[:, t]) new_loc[t, :, :] = np.matmul(kspace_loc_to_corrupt[t, :, :], R) return new_loc