Skip to content

Commit

Permalink
Group effort (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolbPTB authored Jan 21, 2025
1 parent e8bfc9e commit 66b2bd8
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 169 deletions.
16 changes: 8 additions & 8 deletions docs/source/contributor_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This repository uses a *pyproject.toml* file to specify all the requirements.
Python scripts showcasing how MRpro can be used. Any data needed has to be available from
an online repository (e.g. zenodo) such that it can be automatically downloaded.
Individual cells should be indicated with ``# %%``. For markdown cells use ``# %% [markdown]``.
The translation from python script to jupyter notebook is done in pre-commit (locally and on GitHub)
The translation from Python script to Jupyter notebook is done in pre-commit (locally and on GitHub)
using `jupytext <https://jupytext.readthedocs.io/en/latest/>`_ . See its documentation for more details.

After translating the scripts to notebooks, the notebooks are run and their output is converted to html and added
Expand All @@ -37,7 +37,7 @@ This repository uses a *pyproject.toml* file to specify all the requirements.

**src/mrpro/data**
All the data classes such as ``KData``, ``ImageData`` or ``CsmData``.
As the name suggestions these should mainly contain data and meta information.
As the names suggest these should mainly contain data and meta information.
Any functionality beyond what is absolutely required for the classes should be put as separate functions.

**src/mrpro/operators**
Expand All @@ -60,7 +60,7 @@ which we have also added to the list of extensions that VSCode should recommend
We also run `mypy <https://pypi.org/project/mypy/>`_ as a type checker.

In CI, our linting is driven by `pre-commit <https://pre-commit.com/>`_.
If you install MRpro via ``pip install -e .[test]``, pre-commit will be installed in your python environment.
If you install MRpro via ``pip install -e .[test]``, pre-commit will be installed in your Python environment.
You can either add pre-commit to your git pre-commit hooks, requiring it to pass before each commit (``pre-commit install``),
or run it manually using ``pre-commit run --all-files`` after making your changes, before requesting a PR review.

Expand All @@ -84,22 +84,22 @@ You can use VSCode's test panel to discover and run tests. All tests must pass b

Building the Documentation
==========================
You can build the documentation locally via running ``make html`` in the docs folder. The documentation will also be build in each PR and can be viewed online.
You can build the documentation locally via running ``make html`` in the ``docs`` folder. The documentation will also be build in each PR and can be viewed online.
Please check how your new additions render in the documentation before requesting a PR review.


Adding new Examples
===================
New exciting applications of MRpro can be added in ``examples`` as only ``.py`` files with code-cells. These can, for example, be used in VSCode with the python extension, or in JupyterLab with the `jupytext <https://jupytext.readthedocs.io/en/latest/>`_ extension.
New exciting applications of MRpro can be added in ``examples`` as only ``.py`` files with code-cells. These can, for example, be used in VSCode with the Python extension, or in JupyterLab with the `jupytext <https://jupytext.readthedocs.io/en/latest/>`_ extension.
A pre-commit action will convert the scripts to notebooks. Our documetantion build will pick up these notebooks, run them, and include them with outputs in the documentation.
The data to run the examples should be publicly available and hosted externally, for example at zenodo.
Please be careful not to add any binary files to your commits.

Release Strategy
================
We are still in pre-release mode and do not guarantee a stable API / strict semantic versioning compatibility. We currently use ```0.YYMMDD``` as versioning and release in regular intervals to `pypi <https://pypi.org/project/mrpro/>`_.
We are still in pre-release mode and do not guarantee a stable API / strict semantic versioning compatibility. We currently use ``0.YYMMDD`` as versioning and release in regular intervals to `pypi <https://pypi.org/project/mrpro/>`_.

Compatibility
=============
We aim to always be compatible with the latest stable pytorch release and the latest python version supported by pytorch. We are compatible with one previous python version.
Our type hints will usually only be valid with the latest pytorch version.
We aim to always be compatible with the latest stable PyTorch release and the latest Python version supported by pytorch. We are compatible with one previous Python version.
Our type hints will usually only be valid with the latest PyTorch version.
9 changes: 4 additions & 5 deletions docs/source/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ User Guide
==========

MRpro is a MR image reconstruction and processing framework specifically developed to work well with pytorch.
The data classes utilize `torch.Tensor` for storing data such as MR raw data or reconstructed image data,
operators are implemented as `torch.nn.Module`
Where possible batch parallelisation of pytorch is utilized to speed up image reconstruction.
The data classes utilize `torch.Tensor` for storing data such as MR raw data or reconstructed image data.
Operators are implemented as `torch.nn.Module` where possible batch parallelisation of pytorch is utilized to speed up image reconstruction.

Installation
============
Expand Down Expand Up @@ -39,7 +38,7 @@ A basic pipeline would contain the following steps:

The following provides some basic information about these steps.
For more detailed information please have a look at the :doc:`examples`.
You can easily launch notebooks via the |colab-badge| badge and give the notebooks a try -
You can easily launch notebooks via the |colab-badge| badge and give the notebooks a try!

Reading in raw data
-------------------
Expand All @@ -54,7 +53,7 @@ for available trajectory calculators and :doc:`_notebooks/comparison_trajectory_
.. note::
In MRpro, we use the convention ``(z, y, x)`` for spatial dimensions and ``(k2, k1, k0)`` for k-space dimensions.
Here, `k0` is the readout direction, `k1` and `k2` are phase encoding directions.
The full shape of a multi-slice 2D k-space data, for example, is ``(other, coil, 1, k1, k0)`` where `other` will be the different slices.
The full shape of a multi-slice 2D k-space data for example is ``(other, coil, 1, k1, k0)`` where `other` will be the different slices.
In general, `other` can be any number of additional dimensions.

.. note::
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/cartesian_reconstruction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"source": [
"# Basics of MRpro and Cartesian Reconstructions\n",
"# Basics of MRpro and Cartesian reconstructions\n",
"Here, we are going to have a look at a few basics of MRpro and reconstruct data acquired with a Cartesian sampling\n",
"pattern."
]
Expand Down Expand Up @@ -578,7 +578,7 @@
"different operators and chain them together. Wouldn't it be nice if this could be done automatically?\n",
"\n",
"That is why we also included some top-level reconstruction algorithms in MRpro. For this whole steps from above,\n",
"we can simply use a `~mrpro.algorithnms.reconstruction.DirectReconstruction`.\n",
"we can simply use a `~mrpro.algorithms.reconstruction.DirectReconstruction`.\n",
"Reconstruction algorithms can be instantiated from only the information in the `~mrpro.data.KData` object.\n",
"\n",
"In contrast to operators, top-level reconstruction algorithms operate on the data objects of MRpro, i.e. the input is\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/comparison_trajectory_calculators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lines_to_next_cell": 2
},
"source": [
"# Different ways to obtain the Trajectory\n",
"# Different ways to obtain the trajectory\n",
"This example builds upon the <project:direct_reconstruction.ipynb> example and demonstrates three ways\n",
"to obtain the trajectory information required for image reconstruction:\n",
"- using the trajectory that is stored in the ISMRMRD file\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/direct_reconstruction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"source": [
"# Direct Reconstruction of 2D golden angle radial data\n",
"# Direct reconstruction of 2D golden angle radial data\n",
"Here we use the `~mrpro.algorithms.reconstruction.DirectReconstruction` class to perform a basic reconstruction of\n",
"2D radial data.\n",
"A *direct* reconstruction uses the density compensated adjoint of the acquisition operator to obtain the images."
Expand Down
12 changes: 6 additions & 6 deletions examples/notebooks/iterative_sense_reconstruction_radial2D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"source": [
"# Iterative SENSE Reconstruction of 2D golden angle radial data\n",
"# Iterative SENSE reconstruction of 2D golden angle radial data\n",
"Here we use an iterative reconstruction method reconstruct images from ISMRMRD 2D radial data."
]
},
Expand Down Expand Up @@ -76,9 +76,9 @@
"We read the raw k-space data and the trajectory from the ISMRMRD file\n",
"(see <project:comparison_trajectory_calculators.ipynb> for more information on the trajectory calculation).\n",
"Our example data contains three datasets:\n",
"- `radial2D_402spokes_golden_angle_with_traj.h5` with 402 spokes\n",
"- `radial2D_96spokes_golden_angle_with_traj.h5` with 96 spokes\n",
"- `radial2D_24spokes_golden_angle_with_traj.h5` with 24 spokes\n",
"- ``radial2D_402spokes_golden_angle_with_traj.h5`` with 402 spokes\n",
"- ``radial2D_96spokes_golden_angle_with_traj.h5`` with 96 spokes\n",
"- ``radial2D_24spokes_golden_angle_with_traj.h5`` with 24 spokes\n",
"\n",
"We use the 402 spokes dataset for the reconstruction."
]
Expand Down Expand Up @@ -213,7 +213,7 @@
"We now peek behind the scenes to see how the iterative SENSE reconstruction is implemented. We perform all steps\n",
"`~mrpro.algorithms.reconstruction.IterativeSENSEReconstruction` does when initialized with only an `~mrpro.data.KData`\n",
"object, i.e., we need to set up a Fourier operator, estimate coil sensitivity maps, and the density weighting.\n",
"without reusing any thing from `direct_reconstruction`."
"without reusing any thing from ``direct_reconstruction```."
]
},
{
Expand Down Expand Up @@ -249,7 +249,7 @@
"source": [
"### Set up the acquisition model $A$\n",
"We need `~mrpro.operators.FourierOp` and `~mrpro.operators.SensitivityOp` operators to set up the acquisition model\n",
"$A$. The Fourier operator is created from the trajectory and header information in `kdata`:"
"$A$. The Fourier operator is created from the trajectory and header information in ``kdata``:"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"source": [
"# Regularized Iterative SENSE Reconstruction of 2D golden angle radial data\n",
"# Regularized iterative SENSE reconstruction of 2D golden angle radial data\n",
"Here we use the `~mrpro.algorithms.reconstruction.RegularizedIterativeSENSEReconstruction` class to reconstruct\n",
"undersampled images from 2D radial data."
]
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/qmri_t1_mapping_with_grad_acq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lines_to_next_cell": 2
},
"source": [
"# $T_1$ mapping from a continuous Golden radial acquisition"
"# $T_1$ mapping from a continuous golden radial acquisition"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/cartesian_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # Basics of MRpro and Cartesian Reconstructions
# # Basics of MRpro and Cartesian reconstructions
# Here, we are going to have a look at a few basics of MRpro and reconstruct data acquired with a Cartesian sampling
# pattern.

Expand Down Expand Up @@ -295,7 +295,7 @@ def show_images(*images: torch.Tensor, titles: list[str] | None = None) -> None:
# different operators and chain them together. Wouldn't it be nice if this could be done automatically?
#
# That is why we also included some top-level reconstruction algorithms in MRpro. For this whole steps from above,
# we can simply use a `~mrpro.algorithnms.reconstruction.DirectReconstruction`.
# we can simply use a `~mrpro.algorithms.reconstruction.DirectReconstruction`.
# Reconstruction algorithms can be instantiated from only the information in the `~mrpro.data.KData` object.
#
# In contrast to operators, top-level reconstruction algorithms operate on the data objects of MRpro, i.e. the input is
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/comparison_trajectory_calculators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # Different ways to obtain the Trajectory
# # Different ways to obtain the trajectory
# This example builds upon the <project:direct_reconstruction.ipynb> example and demonstrates three ways
# to obtain the trajectory information required for image reconstruction:
# - using the trajectory that is stored in the ISMRMRD file
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/direct_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # Direct Reconstruction of 2D golden angle radial data
# # Direct reconstruction of 2D golden angle radial data
# Here we use the `~mrpro.algorithms.reconstruction.DirectReconstruction` class to perform a basic reconstruction of
# 2D radial data.
# A *direct* reconstruction uses the density compensated adjoint of the acquisition operator to obtain the images.
Expand Down
12 changes: 6 additions & 6 deletions examples/scripts/iterative_sense_reconstruction_radial2D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # Iterative SENSE Reconstruction of 2D golden angle radial data
# # Iterative SENSE reconstruction of 2D golden angle radial data
# Here we use an iterative reconstruction method reconstruct images from ISMRMRD 2D radial data.

# %% [markdown]
Expand Down Expand Up @@ -33,9 +33,9 @@
# We read the raw k-space data and the trajectory from the ISMRMRD file
# (see <project:comparison_trajectory_calculators.ipynb> for more information on the trajectory calculation).
# Our example data contains three datasets:
# - `radial2D_402spokes_golden_angle_with_traj.h5` with 402 spokes
# - `radial2D_96spokes_golden_angle_with_traj.h5` with 96 spokes
# - `radial2D_24spokes_golden_angle_with_traj.h5` with 24 spokes
# - ``radial2D_402spokes_golden_angle_with_traj.h5`` with 402 spokes
# - ``radial2D_96spokes_golden_angle_with_traj.h5`` with 96 spokes
# - ``radial2D_24spokes_golden_angle_with_traj.h5`` with 24 spokes
#
# We use the 402 spokes dataset for the reconstruction.

Expand Down Expand Up @@ -105,7 +105,7 @@
# We now peek behind the scenes to see how the iterative SENSE reconstruction is implemented. We perform all steps
# `~mrpro.algorithms.reconstruction.IterativeSENSEReconstruction` does when initialized with only an `~mrpro.data.KData`
# object, i.e., we need to set up a Fourier operator, estimate coil sensitivity maps, and the density weighting.
# without reusing any thing from `direct_reconstruction`.
# without reusing any thing from ``direct_reconstruction```.

# %% [markdown]
# ### Set up density compensation operator $W$
Expand All @@ -124,7 +124,7 @@
# %% [markdown]
# ### Set up the acquisition model $A$
# We need `~mrpro.operators.FourierOp` and `~mrpro.operators.SensitivityOp` operators to set up the acquisition model
# $A$. The Fourier operator is created from the trajectory and header information in `kdata`:
# $A$. The Fourier operator is created from the trajectory and header information in ``kdata``:

# %%
fourier_operator = mrpro.operators.FourierOp(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # Regularized Iterative SENSE Reconstruction of 2D golden angle radial data
# # Regularized iterative SENSE reconstruction of 2D golden angle radial data
# Here we use the `~mrpro.algorithms.reconstruction.RegularizedIterativeSENSEReconstruction` class to reconstruct
# undersampled images from 2D radial data.

Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/qmri_t1_mapping_with_grad_acq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# %% [markdown]
# # $T_1$ mapping from a continuous Golden radial acquisition
# # $T_1$ mapping from a continuous golden radial acquisition


# %% [markdown]
Expand Down
6 changes: 3 additions & 3 deletions src/mrpro/algorithms/csm/inati.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def inati(
coil_images: torch.Tensor,
smoothing_width: SpatialDimension[int] | int,
) -> torch.Tensor:
"""Calculate a coil sensitivity map (csm) using an the Inati method [INA2013]_ [INA2014]_.
"""Calculate a coil sensitivity map (csm) using the Inati method [INA2013]_ [INA2014]_.
This is for a single set of coil images. The input should be a tensor with dimensions (coils, z, y, x). The output
This is for a single set of coil images. The input should be a tensor with dimensions `(coils, z, y, x)`. The output
will have the same dimensions. Either apply this function individually to each set of coil images, or see
CsmData.from_idata_inati which performs this operation on a whole dataset.
`~mrpro.data.CsmData.from_idata_inati` which performs this operation on a whole dataset.
.. [INA2013] Inati S, Hansen M, Kellman P (2013) A solution to the phase problem in adaptvie coil combination.
in Proceedings of the 21st Annual Meeting of ISMRM, Salt Lake City, USA, 2672.
Expand Down
5 changes: 3 additions & 2 deletions src/mrpro/algorithms/csm/walsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def walsh(coil_images: torch.Tensor, smoothing_width: SpatialDimension[int] | in
Normalize the resulting eigenvectors to produce the final CSMs.
This function works on a single set of coil images. The input should be a tensor with dimensions
(coils, z, y, x). The output will have the same dimensions. Either apply this function individually to each set of
coil images, or see CsmData.from_idata_walsh which performs this operation on a whole dataset [WAL2000]_.
`(coils, z, y, x)`. The output will have the same dimensions. Either apply this function individually to each set of
coil images, or see `~mrpro.data.CsmData.from_idata_walsh` which performs this operation on a whole dataset
[WAL2000]_.
This implementation is inspired by `ismrmrd-python-tools <https://github.com/ismrmrd/ismrmrd-python-tools>`_.
Expand Down
8 changes: 4 additions & 4 deletions src/mrpro/algorithms/dcf/dcf_voronoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def _volume(v: ArrayLike):
def dcf_1d(traj: torch.Tensor) -> torch.Tensor:
"""Calculate sample density compensation function for 1D trajectory.
This function operators on a single `other` sample.
See also `~mrpro.data.DcfData` and `mrpro.utils.smap`
This function operates on a single `other` sample.
See also `~mrpro.data.DcfData` and `~mrpro.utils.smap`.
Parameters
----------
Expand Down Expand Up @@ -71,8 +71,8 @@ def dcf_2d3d_voronoi(traj: torch.Tensor) -> torch.Tensor:
The Voronoi tessellation assigns each point in k-space a region based on the proximity to its nearest neighbors. The
DCF is then computed based on the inverse of the area of these regions.
This function operators on a single `other` sample.
See also `~mrpro.data.DcfData` and `mrpro.utils.smap`
This function operates on a single `other` sample.
See also `~mrpro.data.DcfData` and `~mrpro.utils.smap`.
Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions src/mrpro/algorithms/optimizers/adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def adam(
1. Initialize parameters and moment estimates (:math:`m_0`, :math:`v_0`).
2. Compute the gradient of the objective function.
3. Compute biased corrected estimates of the moments :math:`\hat{m}_t` and :math:`\hat{v}_t`.
3. Compute bias-corrected estimates of the moments :math:`\hat{m}_t` and :math:`\hat{v}_t`.
4. Update parameters using the adaptive step size.
This function wraps PyTorch's :class:`torch.optim.Adam` and :class:`torch.optim.AdamW` implementations,
Expand Down Expand Up @@ -79,7 +79,7 @@ def adam(
eps
term added to the denominator to improve numerical stability
weight_decay
weight decay (L2 penalty if `decoupled_weight_decay` is False)
weight decay (L2 penalty if `decoupled_weight_decay` is `False`)
amsgrad
whether to use the AMSGrad variant [REDDI2019]_
decoupled_weight_decay
Expand Down
4 changes: 2 additions & 2 deletions src/mrpro/algorithms/optimizers/cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def cg(
is the only stopping criterion used to stop the cg.
If the condition number of :math:`H` is large, a small residual may not imply a highly accurate solution.
callback
function to be called at each iteration. This can be used to monitor the progress of the algorithm.
Function to be called at each iteration. This can be used to monitor the progress of the algorithm.
Returns
-------
an approximate solution of the linear system :math:`Hx=b`
An approximate solution of the linear system :math:`Hx=b`.
References
----------
Expand Down
Loading

0 comments on commit 66b2bd8

Please sign in to comment.