Skip to content

Commit

Permalink
Make a new release with documentation build flow (#165)
Browse files Browse the repository at this point in the history
* revised documentation of Cartesian Fourier operators

* run isort to optimize imports

* Base operator docstring

* Use f-string and clean code

* rename coefs to coeffs

* format docstrings

* [typo] Use american learned.

* add dtype option for gradient.

* [test] add pydocstyle to CI

* Use FourierOperatorBase class.

* use the uses_sense property

* single Channel reconstruction can also be used for SENSE.

* add shape and n_coils

* fix import

* last check function removing

* add docstring

* uses sense check for Gradient operator.

* cleanup doc and add ref

* cast to builtin int 

Make the condition pass if `n_coil` is a custom integer type (eg np.int64)

* inherit from OperatorBase

* remove redundant declaration of op/adj_op method.

* pass extra gradient args to parentclass.

This allow to setup deeper parameters, such as input_data_writeable.

* add auto threshold operator.

* fix deprecated dtype (error with numpy 1.24)

* fix bugs.

* add auto sure example.

* rework of the eestimation function.

* cleaning.

* remove level-shared method.

* add thresh range argument.

* someone left a bug here.

* refactor: externalize the computation of wavelet threshold.

* improve docstrings.

* use elif blocks.

* s/level/scale/g

* improve auto-threshold example.

* update docstring parameters.

* add import in init modules.

* Cartesian-> cartesian

* coeffs_shape

* Fix typo

* feat: update the example for auto_threshold.

* Final Documentation Pull Request #155  (#158)

* documentation reconstructors

* Revised the documentation on non-uniform Fourier operators

* Clean documentation on gradient operators

* Update mri/operators/fourier/cartesian.py

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/non_cartesian.py

Comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/non_cartesian.py

comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/non_cartesian.py

comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/non_cartesian.py

comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/cartesian.py

comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/cartesian.py

comply to the pydocstyle guidelines

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/cartesian.py

Minor typo

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/cartesian.py

Minor fix

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/cartesian.py

Minor fix

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/operators/fourier/non_cartesian.py

* Update mri/operators/fourier/non_cartesian.py

* Update mri/operators/fourier/non_cartesian.py

* Update mri/operators/fourier/non_cartesian.py

* Update mri/reconstructors/base.py

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/reconstructors/base.py

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/reconstructors/base.py

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Apply suggestions from code review

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* Update mri/reconstructors/base.py

Co-authored-by: Pierre-Antoine Comby <[email protected]>

* [doc] s/: np\./: numpy\./g

* [doc] s/""" /"""/g

* [doc][fourier] Constructor parameters in class docstring

* [doc] s/: ndarray/: numpy.ndarray/g

---------

Co-authored-by: Zaineb AMOR <[email protected]>
Co-authored-by: Philippe Ciuciu <[email protected]>
Co-authored-by: Guillaume DAVAL FREROT <[email protected]>
Co-authored-by: Pierre-Antoine Comby <[email protected]>
Co-authored-by: Daval-G <[email protected]>
Co-authored-by: Pierre-antoine Comby <[email protected]>

* Update versioning

* Updated codes

* Fix one example

* Cartesian recon

* Fix Density comp

* Added density compensation and gpunufft stuff

* refactored all examples

* Fix GL

* Update setup.py

* Update setup.py

* Update setup.py

* Fix density compensation comparison module

* Added density compensation module

* Create gpu_requirements

* Rename gpu_requirements to gpu_requirements.txt

* Update README.txt

* Update gpu_requirements.txt

* Update gpu_requirements.txt

* Update setup.py

* Added auto tuto

* Final large iteration

* Move back to GPU for speed

* Minor bug fix

* Checking done

* fix versioning

* remove

* Fix auto thresh

* Fix grid search

* Update modopt

---------

Co-authored-by: Philippe Ciuciu <[email protected]>
Co-authored-by: Pierre-antoine Comby <[email protected]>
Co-authored-by: Pierre-Antoine Comby <[email protected]>
Co-authored-by: Daval-G <[email protected]>
Co-authored-by: Zaineb AMOR <[email protected]>
Co-authored-by: Guillaume DAVAL FREROT <[email protected]>
Co-authored-by: GILIYAR RADHAKRISHNA Chaithya <[email protected]>
  • Loading branch information
8 people authored Jan 19, 2024
1 parent 7e65415 commit d32ebdf
Show file tree
Hide file tree
Showing 59 changed files with 1,771 additions and 1,553 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
python -m pip install git+https://github.com/CEA-COSMIC/ModOpt.git@develop
python -m pip install git+https://github.com/CEA-COSMIC/pysap.git@develop
python -m pip install git+https://github.com/AGrigis/pysphinxdoc.git
python -m pip install coverage nose pytest pytest-cov pycodestyle twine pytest-xdist
python -m pip install coverage nose pytest pytest-cov pycodestyle pydocstyle twine pytest-xdist
python -m pip install pynfft2
python -m pip install --upgrade .
Expand All @@ -57,7 +57,8 @@ jobs:
run: |
pycodestyle mri --ignore="E121,E123,E126,E226,E24,E704,E402,E731,E722,E741,W503,W504,W605"
pycodestyle examples --ignore="E121,E123,E126,E226,E24,E704,E402,E731,E722,E741,W503,W504,W605"
pydocstyle mri --convention=numpy
pydocstyle examples --convention=numpy
- name: Run Tests
shell: bash -l {0}
run: |
Expand Down
21 changes: 21 additions & 0 deletions doc/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,24 @@ @article{man1997
year = {1997},
pages = {785-792},
}

@article{Pruessmann1999,
title={SENSE: Sensitivity encoding for fast MRI},
author={Klaas Paul Pruessmann and Markus Weiger and Markus B. Scheidegger and Peter Boesiger},
journal={Magnetic Resonance in Medicine},
year={1999},
volume={42},
}
@inproceedings{Donoho1994,
address = {Baltimore, MD, USA},
title = {Threshold selection for wavelet shrinkage of noisy data},
ISBN = {978-0-7803-2050-5},
url = {http://ieeexplore.ieee.org/document/412133/},
DOI = {10.1109/IEMBS.1994.412133},
booktitle = {Proceedings of 16th Annual International Conference of the
IEEE Engineering in Medicine and Biology Society},
publisher = {IEEE},
author = {Donoho, D.L. and Johnstone, I.M.},
year = 1994,
pages = {A24–A25}
}
61 changes: 35 additions & 26 deletions examples/CalibrationlessReconstruction_GL_Cartesian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Cartesian Calibrationless Reconstruction using GroupLASSO Regularizer
=====================================================================
==============================================================
Author: Chaithya G R
Expand All @@ -13,32 +13,36 @@
We use the toy datasets available in pysap, more specifically a 2D parallel MRI
brain slice on 32 channels and the acquisition cartesian scheme.
"""

# %%
# Package import
from mri.operators import FFT, WaveletN
from mri.operators.utils import convert_mask_to_locations
from mri.reconstructors import CalibrationlessReconstructor
import pysap
from pysap.data import get_sample_data

# Third party import
from modopt.math.metrics import ssim
from modopt.opt.proximity import GroupLASSO
from modopt.math.metrics import ssim
import numpy as np
import matplotlib.pyplot as plt


# %%
# Loading input data
cartesian_ref_image = get_sample_data('2d-pmri')
image = pysap.Image(data=np.sqrt(np.sum(cartesian_ref_image.data**2, axis=0)))
cartesian_ref_image = get_sample_data('2d-pmri').data
image = np.linalg.norm(cartesian_ref_image, axis=0)
# Obtain MRI cartesian mask
mask = get_sample_data("cartesian-mri-mask")
kspace_loc = convert_mask_to_locations(mask.data)
mask = get_sample_data("cartesian-mri-mask").data

# %%
# View Input
# image.show()
# mask.show()
plt.subplot(1, 2, 1)
plt.imshow(np.abs(image), cmap='gray')
plt.title("MRI Data")
plt.subplot(1, 2, 2)
plt.imshow(mask, cmap='gray')
plt.title("K-space Sampling Mask")
plt.show()

#############################################################################
# %%
# Generate the kspace
# -------------------
#
Expand All @@ -47,18 +51,19 @@
# We then reconstruct the zero order solution as a baseline

# Get the locations of the kspace samples and the associated observations
fourier_op = FFT(samples=kspace_loc, shape=image.shape,
fourier_op = FFT(mask=mask, shape=image.shape,
n_coils=cartesian_ref_image.shape[0])
kspace_obs = fourier_op.op(cartesian_ref_image)

# Zero Filled reconstruction
zero_filled = fourier_op.adj_op(kspace_obs)
image_rec0 = pysap.Image(data=np.sqrt(np.sum(np.abs(zero_filled)**2, axis=0)))
# image_rec0.show()
base_ssim = ssim(image_rec0, image)
print('The Base SSIM is : ' + str(base_ssim))
# %%
# Zero order solution
zero_soln = np.linalg.norm(fourier_op.adj_op(kspace_obs), axis=0)
base_ssim = ssim(zero_soln, image)
plt.imshow(np.abs(zero_soln), cmap='gray')
plt.title('Zero Order Solution : SSIM = ' + str(np.around(base_ssim, 2)))
plt.show()

#############################################################################
# %%
# FISTA optimization
# ------------------
#
Expand All @@ -71,6 +76,7 @@
nb_scale=4,
n_coils=cartesian_ref_image.shape[0],
)
coeffs = linear_op.op(cartesian_ref_image)
regularizer_op = GroupLASSO(weights=6e-8)
# Setup Reconstructor
reconstructor = CalibrationlessReconstructor(
Expand All @@ -80,12 +86,15 @@
gradient_formulation='synthesis',
verbose=1,
)
x_final, costs, metrics = reconstructor.reconstruct(
# %%
# Run the FISTA reconstruction and view results
image_rec, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_obs,
optimization_alg='fista',
num_iterations=300,
num_iterations=100,
)
image_rec = pysap.Image(data=np.sqrt(np.sum(np.abs(x_final)**2, axis=0)))
image_rec = np.linalg.norm(image_rec, axis=0)
recon_ssim = ssim(image_rec, image)
print('The Reconstruction SSIM is : ' + str(recon_ssim))
# image_rec.show()
plt.imshow(np.abs(image_rec), cmap='gray')
plt.title('Iterative Reconstruction : SSIM = ' + str(np.around(recon_ssim, 2)))
plt.show()
55 changes: 32 additions & 23 deletions examples/CalibrationlessReconstruction_OWL_Cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,35 @@
We use the toy datasets available in pysap, more specifically a 2D parallel MRI
brain slice on 32 channels and the acquisition cartesian scheme.
"""

# %%
# Package import
from mri.operators import FFT, WaveletN, OWL
from mri.operators.utils import convert_mask_to_locations
from mri.reconstructors import CalibrationlessReconstructor
import pysap
from pysap.data import get_sample_data

# Third party import
from modopt.math.metrics import ssim
import numpy as np
import matplotlib.pyplot as plt


# %%
# Loading input data
cartesian_ref_image = get_sample_data('2d-pmri')
image = pysap.Image(data=np.sqrt(np.sum(cartesian_ref_image.data**2, axis=0)))
cartesian_ref_image = get_sample_data('2d-pmri').data
image = np.linalg.norm(cartesian_ref_image, axis=0)
# Obtain MRI cartesian mask
mask = get_sample_data("cartesian-mri-mask")
kspace_loc = convert_mask_to_locations(mask.data)
mask = get_sample_data("cartesian-mri-mask").data

# %%
# View Input
# image.show()
# mask.show()
plt.subplot(1, 2, 1)
plt.imshow(np.abs(image), cmap='gray')
plt.title("MRI Data")
plt.subplot(1, 2, 2)
plt.imshow(mask, cmap='gray')
plt.title("K-space Sampling Mask")
plt.show()

#############################################################################
# %%
# Generate the kspace
# -------------------
#
Expand All @@ -46,18 +50,19 @@
# We then reconstruct the zero order solution as a baseline

# Get the locations of the kspace samples and the associated observations
fourier_op = FFT(samples=kspace_loc, shape=image.shape,
fourier_op = FFT(mask=mask, shape=image.shape,
n_coils=cartesian_ref_image.shape[0])
kspace_obs = fourier_op.op(cartesian_ref_image)

# Zero Filled reconstruction
zero_filled = fourier_op.adj_op(kspace_obs)
image_rec0 = pysap.Image(data=np.sqrt(np.sum(np.abs(zero_filled)**2, axis=0)))
# image_rec0.show()
base_ssim = ssim(image_rec0, image)
print('The Base SSIM is : ' + str(base_ssim))
# %%
# Zero order solution
zero_soln = np.linalg.norm(fourier_op.adj_op(kspace_obs), axis=0)
base_ssim = ssim(zero_soln, image)
plt.imshow(np.abs(zero_soln), cmap='gray')
plt.title('Zero Order Solution : SSIM = ' + str(np.around(base_ssim, 2)))
plt.show()

#############################################################################
# %%
# FISTA optimization
# ------------------
#
Expand Down Expand Up @@ -86,11 +91,15 @@
gradient_formulation='synthesis',
verbose=1,
)
x_final, costs, metrics = reconstructor.reconstruct(
# %%
# Run the FISTA reconstruction and view results
image_rec, costs, metrics = reconstructor.reconstruct(
kspace_data=kspace_obs,
optimization_alg='fista',
num_iterations=200,
num_iterations=100,
)
image_rec = pysap.Image(data=np.sqrt(np.sum(np.abs(x_final)**2, axis=0)))
image_rec = np.linalg.norm(image_rec, axis=0)
recon_ssim = ssim(image_rec, image)
print('The Reconstruction SSIM is : ' + str(recon_ssim))
plt.imshow(np.abs(image_rec), cmap='gray')
plt.title('Iterative Reconstruction : SSIM = ' + str(np.around(recon_ssim, 2)))
plt.show()
78 changes: 0 additions & 78 deletions examples/GPU_Examples/NonCartesian_gpuNUFFT_DensityCompensation.py

This file was deleted.

Loading

0 comments on commit d32ebdf

Please sign in to comment.