Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set contiguous array before conversion from array to tensor #114

Open
wants to merge 88 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
49ba42e
set contiguous array before conversion from array to tensor
ZhengguoTan Jul 26, 2022
ba61c83
remove warning when using sigpy on cpu with cupy installed
ZhengguoTan Aug 23, 2022
b38aad7
set contiguous array when not c_contiguous
ZhengguoTan Dec 22, 2022
509fb39
add keepdims option in rss
ZhengguoTan Dec 22, 2022
2af4f2e
add symm option in hanning function: allows for symmetric hanning window
ZhengguoTan Dec 22, 2022
38d308f
add verbose option in ConjugateGradient
ZhengguoTan Dec 22, 2022
2deb39b
add keepdims option in Sum and Tile linop
ZhengguoTan Dec 26, 2022
0fda946
use 'mean' option to handle overlapping local blocks
ZhengguoTan Dec 26, 2022
a26a3c4
allow for the use of device in Slice linop
ZhengguoTan Dec 26, 2022
a176772
add Sobolev linop
ZhengguoTan Dec 26, 2022
57dceb8
add HDNUFFT linop for high-dimensional NUFFT
ZhengguoTan Dec 26, 2022
ffc87e8
test Conjugate of prox operators
ZhengguoTan Dec 26, 2022
3c93af3
bump up to NumPy 1.20 and Torch 1.12
ZhengguoTan Dec 26, 2022
6e41588
allow for scaling in LinearLeastSquares
ZhengguoTan Jan 3, 2023
5f4d023
make sure all arrays are on the same device in LinearLeastSquares
ZhengguoTan Jan 3, 2023
a99ca8e
allow for verbose in LinearLeastSquares
ZhengguoTan Jan 3, 2023
40ff409
nlop: a generalized nonlinear operator framework
ZhengguoTan Jan 3, 2023
a00607c
add iteratively regularized Gauss-Newton method (IRGNM) algorithm
ZhengguoTan Jan 3, 2023
5b1ce4c
add NonlinearLeastSquares App
ZhengguoTan Jan 3, 2023
4120785
Nlinv: parallel imaging as a nonlinear operator
ZhengguoTan Jan 4, 2023
cf5d90c
add a test case of model-based DTI reconstruction
ZhengguoTan Jan 4, 2023
fd45a5a
coding style
ZhengguoTan Jan 4, 2023
c35e056
coord: conversion between Cartesian and Spherical coordinates
ZhengguoTan Jan 4, 2023
9b5d30d
epi: module for diffusion MRI based on EPI
ZhengguoTan Jan 4, 2023
6d40f6e
retro: module for performing retrospective undersampling in EPI
ZhengguoTan Jan 4, 2023
47d203b
sms: module for Simultaneous Multi-Slice
ZhengguoTan Jan 4, 2023
b4fb22f
coding style
ZhengguoTan Jan 5, 2023
918fcd4
sim: module for MRI signal simulation
ZhengguoTan Jan 5, 2023
b95cbe9
coding style
ZhengguoTan Jan 5, 2023
923c584
SLRMCReg: proximal operator for structured low-rank matrix completion
ZhengguoTan Jan 5, 2023
72760b4
order
ZhengguoTan Jan 5, 2023
ed11134
LLRL1Reg: proximal operator for locally low rank soft thresholding re…
ZhengguoTan Jan 5, 2023
0b5d3c1
dims: generalized MRI dimension definition
ZhengguoTan Jan 5, 2023
f32072e
coding style
ZhengguoTan Jan 5, 2023
a260327
MUSE: multiplexed sensitivity-encoding recon for multi-shot diffusion…
ZhengguoTan Jan 11, 2023
83239dd
MUSSELS: structured low-rank matrix completion recon for multi-shot d…
ZhengguoTan Jan 11, 2023
1db555a
update JULEP paper
ZhengguoTan Jan 12, 2023
736bdee
mri app: CompressedSenseRecon
ZhengguoTan Jan 12, 2023
14bd5d5
update sms slice ordering and test functions
ZhengguoTan Jan 25, 2023
1625d8a
add reference
ZhengguoTan Mar 3, 2023
0297480
sms slice reorder fix and automatic test cases
ZhengguoTan Mar 15, 2023
00c0e67
do not sort sms slice indices
ZhengguoTan Mar 15, 2023
64cfc90
correct for assert_allclose in test_sms
ZhengguoTan Mar 31, 2023
aeb1564
add another test case for sms
ZhengguoTan Mar 31, 2023
b97ce00
typo
ZhengguoTan Apr 4, 2023
86f0ac7
verbose
ZhengguoTan Apr 4, 2023
0da32ad
compatible to newer numpy (1.24)
ZhengguoTan May 9, 2023
0098bb1
nlop in __init__
ZhengguoTan May 9, 2023
7d9344b
rename
ZhengguoTan May 30, 2023
39d6830
iterative smoothing
ZhengguoTan May 30, 2023
41e3dbf
update on sms slice index calculation
ZhengguoTan May 30, 2023
2a0b14c
Non-Cartesian in HighDimensionalRecon
ZhengguoTan Jun 12, 2023
d743737
rename
ZhengguoTan Jun 12, 2023
f5c4103
LLRL1Reg: enables magnitude-only regularization
ZhengguoTan Jul 19, 2023
3bd1354
dce module
ZhengguoTan Jul 25, 2023
e841cc1
simulate a dynamic shepp logan phantom
ZhengguoTan Aug 1, 2023
780a090
test DTI fitting on 1 b-value acquisition
ZhengguoTan Aug 9, 2023
01df496
verbose in alg
ZhengguoTan Nov 21, 2023
7d48c6e
allow for single paramter setting in muse denoising
ZhengguoTan Nov 21, 2023
866244c
unit in test_dce
ZhengguoTan Nov 21, 2023
7fc9f31
new test case in sms
ZhengguoTan Nov 21, 2023
80e05b0
coil compression (cc) module
ZhengguoTan Nov 21, 2023
5d33c7d
diffusion vector set (dvs) module
ZhengguoTan Nov 21, 2023
10d93cd
rename app
ZhengguoTan Nov 22, 2023
0066f7e
fix import
ZhengguoTan Nov 22, 2023
a8dda98
add normalization option in LLRL1Reg: enables singular value normaliz…
ZhengguoTan Dec 5, 2023
8c2f996
checkin an install.sh script that works in conda
ZhengguoTan Dec 18, 2023
56a90a2
specify python 3.10 version
ZhengguoTan Dec 19, 2023
74b94ff
set verbose default as False in muse
ZhengguoTan Feb 14, 2024
3cbcd6f
use antialias in Resize
ZhengguoTan Apr 9, 2024
158e740
reorder slices incl. sms = 3
ZhengguoTan Jun 6, 2024
5700540
add RealValueConstraint linop
ZhengguoTan Aug 15, 2024
a6cb399
use RealValueConstraint in MUSE
ZhengguoTan Aug 15, 2024
24bdfa0
dicom module
ZhengguoTan Aug 15, 2024
598619b
update sense linop to allow up highdims and chain with nlop
ZhengguoTan Aug 15, 2024
5b0b2a6
numpy version bump
ZhengguoTan Aug 15, 2024
000add8
add dti nlop
ZhengguoTan Aug 15, 2024
0413065
add nlls and nlrecon
ZhengguoTan Aug 15, 2024
50b9d24
add model-based dti recon app
ZhengguoTan Aug 15, 2024
9ef850c
add diff module
ZhengguoTan Aug 15, 2024
9f5a0cc
add gmap and grappa modules
ZhengguoTan Aug 15, 2024
34d2ed9
remove redundant lines
ZhengguoTan Aug 15, 2024
bbc0d5e
reformat test epi
ZhengguoTan Aug 15, 2024
a9cd8be
test coord
ZhengguoTan Aug 15, 2024
99a2f4d
torch_dce module
ZhengguoTan Aug 15, 2024
fe0b9ef
ADC calculation
ZhengguoTan Aug 21, 2024
4eaa98e
allows for the use of dcf in HDNUFFT
ZhengguoTan Oct 29, 2024
9e660b0
remove head links in README
ZhengguoTan Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
SigPy
=====

.. image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
:target: https://opensource.org/licenses/BSD-3-Clause

.. image:: https://travis-ci.com/mikgroup/sigpy.svg?branch=master
:target: https://travis-ci.com/mikgroup/sigpy

.. image:: https://readthedocs.org/projects/sigpy/badge/?version=latest
:target: https://sigpy.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://codecov.io/gh/mikgroup/sigpy/branch/master/graph/badge.svg
:target: https://codecov.io/gh/mikgroup/sigpy

.. image:: https://zenodo.org/badge/139635485.svg
:target: https://zenodo.org/badge/latestdoi/139635485


`Source Code <https://github.com/mikgroup/sigpy>`_ | `Documentation <https://sigpy.readthedocs.io>`_ | `MRI Recon Tutorial <https://github.com/mikgroup/sigpy-mri-tutorial>`_ | `MRI Pulse Design Tutorial <https://github.com/jonbmartin/open-source-pulse-design>`_

SigPy is a package for signal processing, with emphasis on iterative methods. It is built to operate directly on NumPy arrays on CPU and CuPy arrays on GPU. SigPy also provides several domain-specific submodules: ``sigpy.plot`` for multi-dimensional array plotting, ``sigpy.mri`` for MRI reconstruction, and ``sigpy.mri.rf`` for MRI pulse design.

Installation
Expand Down Expand Up @@ -48,15 +29,15 @@ SigPy can also be installed through ``pip``::
# (optional for plot support) pip install matplotlib
# (optional for CUDA support) pip install cupy
# (optional for MPI support) pip install mpi4py

Installation for Developers
***************************

If you want to contribute to the SigPy source code, we recommend you install it with ``pip`` in editable mode::

cd /path/to/sigpy
pip install -e .

To run tests and contribute, we recommend installing the following packages::

pip install coverage ruff sphinx sphinx_rtd_theme black isort
Expand Down Expand Up @@ -101,4 +82,3 @@ Want to do machine learning without giving up signal processing? SigPy has conve

x_torch = sigpy.to_pytorch(x)
A_torch = sigpy.to_pytorch_function(A)

27 changes: 27 additions & 0 deletions conda.recipe/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# to install sigpy from scratch:

git clone https://github.com/ZhengguoTan/sigpy.git sigpy_github

cd sigpy_github

conda create -n sigpy_github python=3.10
conda activate sigpy_github

conda install -c anaconda pip

python -m pip install torch torchvision torchaudio

python -m pip install tqdm
python -m pip install numba
python -m pip install scipy
python -m pip install pywavelets
python -m pip install h5py
python -m pip install matplotlib

# please -
# (1) check your cuda version here
# (2) log into gpu machine when you are in hpc
# https://docs.cupy.dev/en/stable/install.html
pip install cupy-cuda11x

pip install -e .
28 changes: 8 additions & 20 deletions sigpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@
that can be used in conjuction with Alg to form an App.

"""
from sigpy import (
alg,
app,
backend,
block,
config,
conv,
fourier,
interp,
linop,
prox,
pytorch,
sim,
thresh,
util,
wavelet,
)

from .version import __version__ # noqa
from sigpy import alg, app, config, linop, prox, nlop

from sigpy import (backend, block, conv, interp,
fourier, pytorch, sim, thresh,
util, wavelet)
from sigpy.backend import * # noqa
from sigpy.block import * # noqa
from sigpy.conv import * # noqa
Expand All @@ -36,9 +26,7 @@
from sigpy.util import * # noqa
from sigpy.wavelet import * # noqa

from .version import __version__ # noqa

__all__ = ["alg", "app", "config", "linop", "prox"]
__all__ = ['alg', 'app', 'config', 'linop', 'prox', 'nlop']
__all__.extend(backend.__all__)
__all__.extend(block.__all__)
__all__.extend(conv.__all__)
Expand Down
110 changes: 108 additions & 2 deletions sigpy/alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ class ConjugateGradient(Alg):

"""

def __init__(self, A, b, x, P=None, max_iter=100, tol=0):
def __init__(self, A, b, x, P=None, max_iter=100, tol=0, verbose=False):
self.A = A
self.b = b
self.P = P
self.x = x
self.tol = tol
self.verbose = verbose
self.device = backend.get_device(x)
with self.device:
xp = self.device.xp
Expand Down Expand Up @@ -278,7 +279,12 @@ def _update(self):
util.xpay(self.p, beta, z)
self.rzold = rznew

self.resid = self.rzold.item() ** 0.5
self.resid = self.rzold.item()**0.5

if self.verbose:
print(" cg iter: " + "%2d" % (self.iter)
+ "; resid: " + "%13.6f" % (self.resid)
+ "; norm: " + "%13.6f" % (xp.linalg.norm(self.x.flatten())))

def _done(self):
return (
Expand Down Expand Up @@ -840,6 +846,106 @@ def _done(self):
return self.iter >= self.max_iter or self.residual <= self.tol


class IRGNM(Alg):
r"""Iteratively Regularized Gauss-Newton Method (IRGNM)

Args:
A (nlop): Non-linear forward model.
y (array): Observation.
x (array): Variable.
x0 (array): bias for L2 regularization.
max_iter (int): maximum number of iterations.
alpha (int): regularization strength.
redu (float): reduction factor along iterations.
inner_iter (int): maximum number of inner iterations.
inner_tol (float): tolerance for the inner iterations.

References:
Bauer F., Kannengiesser S. (2007).
An alternative approach to the image reconstruction
for parallel data acquisition in MRI.
Math. Meth. Appl. Sci. 30, 1437-1451.

Uecker M., Hohage T., Block K. T., Frahm J. (2008)
Image reconstruction by regularized nonlinear inversion
-- joint estimation of coil sensitivities and image content.
Magn. Reson. Med. 60, 674-682.

Tan Z., Roeloffs V., Voit D., Joseph A. A., Untenberger M.,
Merboldt K. D., Frahm J. (2016).
Model-based reconstruction for real-time phase-contrast flow MRI:
Improved spatiotemporal accuracy.
Magn. Reson. Med. 77, 1082-1093.

"""
def __init__(self, A, y, x, x0=None,
max_iter=6, alpha=1, redu=2,
inner_iter=100, inner_tol=0.01, verbose=True):
self.A = A
self.y = y
self.device = backend.get_device(y)

# outer iteration
self.max_iter = max_iter
self.alpha = alpha
self.redu = redu

# inner iteration
self.inner_iter = inner_iter
self.inner_tol = inner_tol

self.verbose = verbose

xp = self.device.xp
with self.device:
self.x = sp.to_device(x, device=self.device)

self.x0 = xp.zeros(x.shape, dtype=y.dtype)
if x0 is not None:
self.x0 = sp.to_device(x0, device=self.device)

super().__init__(max_iter)

def _update(self):
xp = self.device.xp

with self.device:
dx = xp.zeros_like(self.x)

r = self.y - self.A(self.x)

resid = xp.linalg.norm(r).item()

if self.verbose:
print("gn iter: " + "%2d" % (self.iter)
+ "; alpha: " + "%.6f" % (self.alpha)
+ "; resid: " + "%.6f" % (resid))

p = self.A.adjoint(self.x, r)
p += self.alpha * (self.x0 - self.x)

# update dx
def AHA(x):
return self.A.adjoint(self.x, self.A.derivative(self.x, x)) \
+ self.alpha * x

inner_tol = self.inner_tol * xp.linalg.norm(p).item()

inner_alg = ConjugateGradient(AHA, p, dx,
max_iter=self.inner_iter,
tol=inner_tol)
while not inner_alg.done():
inner_alg.update()

# update x
self.x += 1. * dx
self.alpha /= self.redu

def _done(self):
over_iter = self.iter >= self.max_iter
return over_iter


class GerchbergSaxton(Alg):
"""Gerchberg-Saxton method, also called the variable exchange method.
Iterative method for recovery of a signal from the amplitude of linear
Expand Down
Loading