Skip to content

Commit 4292bb5

Browse files
authored
Improvements on the documentation (#275)
* refactor: separate examples in sub galleries. * fix: mark raw string for correct backslash use. * fix: docstring formatting * fixup! add the readme gallery files. * fix: formatting and typo * format: black [docs] [docs] * fix: correct path for gif files. [docs] * fix: update template for minigallery. [docs] * feat: use environment variable for examples * fix: example are independent of backend * fix: minigallery working [docs] * fix: format * Add info about documentation build. * fix: handles warning from sphinx [docs] * feat: use cufinufft for pytest examples * fix: format * [docs] fix: typos and string format * feat: update finufft and cufinufft to 2.4.0 * fix: defer installation of finufft to next stage * fix: add squeeze to ensure display of images. * [docs] build docs with cufinufft * fmt: black * fix: gridder with finufft and cufinufft. * fix examples [docs]
1 parent fd6f970 commit 4292bb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+249
-118
lines changed

.github/workflows/test-ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ jobs:
223223
${{ env.activate_venv }}
224224
python -m pip install --upgrade pip
225225
python -m pip install -e .[extra,test,dev]
226-
python -m pip install finufft pooch brainweb-dl torch fastmri
226+
python -m pip install pooch brainweb-dl torch fastmri
227227
228228
- name: Install Python deps
229229
shell: bash
@@ -238,6 +238,7 @@ jobs:
238238
run: |
239239
${{ env.activate_venv }}
240240
export COVERAGE_FILE=coverage_plots
241+
export MRINUFFT_BACKEND=cufinufft
241242
python -m pytest examples -n=4 --cov --cov-branch --cov-report=term --durations=10
242243
243244
- name: Cache brainweb-dl directory
@@ -352,6 +353,7 @@ jobs:
352353
- name: Build API documentation
353354
run: |
354355
${{ env.activate_venv }}
356+
export MRINUFFT_BACKEND=cufinufft
355357
python -m sphinx docs docs_build
356358
357359
- name: Display data

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ To build the documentation locally, you can run the following commands :
146146
cd mri-nufft/docs
147147
# do your changes
148148
cd ..
149+
# you can specify a specfic backend to run the example with an environment variable:
150+
export MRINUFFT_BACKEND=finufft
149151
python -m sphinx-build docs docs_build
150152
# view the documentation in your browser
151153
python -m http.server --directory docs_build 8080
@@ -154,6 +156,8 @@ To build the documentation locally, you can run the following commands :
154156

155157

156158
## Styleguides
159+
### Code
160+
The code base is formatted with [`black`](https://github.com/psf/black) and style guide is enforced with [`ruff`](https://github.com/astral-sh/ruff). You can run `black .` and `ruff check src` to ensure your changes will pass the [linter-check](https://github.com/mind-inria/.github/workflows/style.yml) CI.
157161
### Docstrings
158162
We use Numpy style docstrings. You can find more information about them [here](https://numpydoc.readthedocs.io/en/latest/format.html).
159163

docs/_templates/autosummary/class.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@
3030
{%- endfor %}
3131
{% endif %}
3232
{% endblock %}
33+
34+
.. _sphx_glr_backref_{{fullname}}:
35+
36+
.. minigallery:: {{fullname}}
37+
:add-heading:

docs/_templates/autosummary/function.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44

55
.. autofunction:: {{ objname }}
66

7-
.. _sphx_glr_backref_{{fullname}}:
8-
9-
.. minigallery:: {{fullname}}
10-
:add-heading:
7+
.. minigallery:: {{module}}.{{objname}}
8+
:add-heading: Example using ``{{objname}}``:

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"within_subsection_order": "ExampleTitleSortKey",
8282
"filename_pattern": "/example_",
8383
"ignore_pattern": r"(__init__|conftest|utils).py",
84+
"prefer_full_module": {r".*"},
8485
"nested_sections": True,
8586
"binder": {
8687
"org": "mind-inria",
@@ -100,7 +101,7 @@
100101
intersphinx_mapping = {
101102
"python": ("https://docs.python.org/3", None),
102103
"numpy": ("https://numpy.org/doc/stable/", None),
103-
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
104+
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
104105
"cupy": ("https://docs.cupy.dev/en/stable/", None),
105106
"matplotlib": ("https://matplotlib.org/stable/", None),
106107
}

docs/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In order to perform Non-Uniform fast Fourier transform you need to install a spe
3434

3535
Then, use the ``get_operator(backend=<your backend>, ... )`` to initialize your MRI-NUFFT operator.
3636

37-
For more information , check the :ref:`Examples`
37+
For more information , check the :ref:`general_examples`
3838

3939

4040
Supported Libraries

docs/mrinufft_convention.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ All MRI-NUFFT operators inherit from :class:`FourierOperatorBase` . The minimum
3737
3838
.. tip::
3939

40-
The precision of the samples array will determine the precision of the computation. See also :ref:`K-Space Trajectories`
40+
The precision of the samples array will determine the precision of the computation. See also :ref:`kspace_traj`
4141

4242
Moreover, the two following methods should be implemented for each backend
4343

@@ -67,6 +67,7 @@ Adding a NUFFT Backend
6767

6868
Adding a NUFFT backend to MRI-NUFFT should be easy. We recommend to check how other backends have been inplemented. CPU-based nufft interface can use the `FourierOperatorCPU` to minimize the boiler-plate.
6969

70+
.. _kspace_traj:
7071

7172
K-Space Trajectories
7273
====================

docs/nufft.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. include:: <isonum.txt>
2-
.. __NUFFT:
2+
.. _NUFFT:
33
====================
44
The NUFFT Operator
55
====================

examples/GPU/example_3d_trajectory_display.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
# %%
1212

1313
# Imports
14+
import os
1415
from mrinufft.trajectories.display3D import get_gridded_trajectory
1516
import mrinufft.trajectories.trajectory3D as mtt
1617
from mrinufft.trajectories.utils import Gammas
1718
import matplotlib.pyplot as plt
1819
import numpy as np
1920

2021

22+
BACKEND = os.environ.get("MRINUFFT_BACKEND", "gpunufft")
23+
24+
2125
# %%
2226
# Helper function to Displaying 3D Gridded Trajectories
2327
# =====================================================
@@ -56,6 +60,8 @@ def create_grid(grid_type, trajectories, traj_params, **kwargs):
5660
traj_params["img_size"],
5761
grid_type=grid_type,
5862
traj_params=traj_params,
63+
backend=BACKEND,
64+
osf=2,
5965
**kwargs,
6066
)
6167
plot_slices(axs[:, i], grid, title=name)

examples/GPU/example_cg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
An example to show how to reconstruct volumes using conjugate gradient method.
77
88
This script demonstrates the use of the Conjugate Gradient (CG) method
9-
for solving systems of linear equations of the form Ax = b, where A is a symmetric
9+
for solving systems of linear equations of the form :math:`Ax = b`, where :math:`A`` is a symmetric
1010
positive-definite matrix. The CG method is an iterative algorithm that is particularly
1111
useful for large, sparse systems where direct methods are computationally expensive.
1212
@@ -32,6 +32,9 @@
3232
from brainweb_dl import get_mri
3333
from mrinufft.density import voronoi
3434
from matplotlib import pyplot as plt
35+
import os
36+
37+
BACKEND = os.environ.get("MRINUFFT_BACKEND", "gpunufft")
3538

3639
# %%
3740
# Setup Inputs
@@ -41,12 +44,13 @@
4144

4245
# %%
4346
# Setup the NUFFT operator
44-
NufftOperator = mrinufft.get_operator("gpunufft") # get the operator
47+
NufftOperator = mrinufft.get_operator(BACKEND) # get the operator
4548

4649
nufft = NufftOperator(
4750
samples_loc,
4851
shape=image.shape,
4952
density=True,
53+
squeeze_dims=True,
5054
) # create the NUFFT operator
5155

5256
# %%
@@ -74,7 +78,10 @@
7478
plt.subplot(2, 3, 3)
7579
plt.title("Adjoint NUFFT")
7680
plt.imshow(
77-
abs(nufft.adj_op(kspace_data)), vmin=image.min(), vmax=image.max(), cmap="gray"
81+
abs(nufft.adj_op(kspace_data)),
82+
vmin=image.min(),
83+
vmax=image.max(),
84+
cmap="gray",
7885
)
7986
plt.colorbar()
8087

0 commit comments

Comments
 (0)