MRIGpuNUFFT#

class mrinufft.operators.MRIGpuNUFFT(samples, shape, n_coils=1, n_batchs=1, n_trans=1, density=None, smaps=None, squeeze_dims=True, eps=0.001, **kwargs)[source]#

Bases: FourierOperatorBase, _ToggleGradPlanMixin

Interface for the gpuNUFFT backend.

Parameters:
  • samples (np.ndarray (Mxd)) – the samples locations in the Fourier domain where M is the number of samples and d is the dimensionnality of the output data (2D for an image, 3D for a volume).

  • shape (tuple of int) – shape of the image (not necessarly a square matrix).

  • n_coils (int default 1) – Number of coils used to acquire the signal in case of multiarray receiver coils acquisition

  • density (bool or np.ndarray default None) – if True, the density compensation is estimated from the samples locations. If an array is passed, it is used as the density compensation.

  • squeeze_dims (bool, default True) – If True, will try to remove the singleton dimension for batch and coils.

  • smaps (np.ndarray default None) – Holds the sensitivity maps for SENSE reconstruction.

  • n_trans (int, default =1) – This has no effect for now.

  • kwargs (extra keyword args) – these arguments are passed to gpuNUFFT operator. This is used only in gpuNUFFT

Methods

__init__

adj_op

Compute adjoint Non Uniform Fourier Transform.

check_shape

Validate the shapes of the image or k-space data against operator shapes.

compute_density

Compute the density compensation weights and set it.

compute_smaps

Compute the sensitivity maps and set it.

data_consistency

Compute the data consistency estimation directly on gpu.

get_lipschitz_cst

Return the Lipschitz constant of the operator.

grad_traj_plan

Context manager to enable gradient computation with respect to trajectory.

make_autograd

Make a new Operator with autodiff support.

make_deepinv_phy

Make a new DeepInv Physics with NUFFT operator.

make_linops

Create a Scipy Linear Operator from the NUFFT operator.

op

Compute forward non-uniform Fourier Transform.

pinv_solver

Solves the linear system Ax = y.

pipe

Compute the density compensation weights for a given set of kspace locations.

toggle_grad_traj

Toggle gradient computation with respect to trajectory.

update_samples

Update the samples of the NUFFT operator.

with_autograd

Return a Fourier operator with autograd capabilities.

with_off_resonance_correction

Return a new operator with Off Resonnance Correction.

Attributes

autograd_available

available

backend

cpx_dtype

Return complex floating precision of the operator.

density

Density compensation of the operator.

dtype

Return floating precision of the operator.

img_full_shape

Full image shape with batch and coil dimensions.

interfaces

ksp_full_shape

Full kspace shape with batch and coil dimensions.

n_batchs

Number of coils for the operator.

n_coils

Number of coils for the operator.

n_samples

Return the number of samples used by the operator.

ndim

Number of dimensions in image space of the operator.

norm_factor

Normalization factor of the operator.

samples

Return the samples used by the operator.

shape

Shape of the image space of the operator.

smaps

Sensitivity maps of the operator.

uses_density

Return True if the operator uses density compensation.

uses_sense

Return True if the Fourier Operator uses the SENSE method.

backend: ClassVar[str] = 'gpunufft'[source]#
available: ClassVar[bool] = True[source]#
autograd_available = True[source]#
property shape: tuple[int, ...][source]#

Shape of the image space of the operator.

property dtype[source]#

Return floating precision of the operator.

property n_coils: int[source]#

Number of coils for the operator.

property n_batchs[source]#

Number of coils for the operator.

op(data, coeffs=None)[source]#

Compute forward non-uniform Fourier Transform.

Parameters:
  • img (np.ndarray) – input N-D array with the same shape as self.shape.

  • coeffs (np.ndarray, optional) – output Array. Should be pinned memory for best performances.

Returns:

Masked Fourier transform of the input image.

Return type:

np.ndarray

Note

This function uses numpy for all CPU arrays, and cupy for all on-gpu array. It will convert all its array argument to the respective array library. The outputs will be converted back to the original array module and device.

adj_op(coeffs, data=None)[source]#

Compute adjoint Non Uniform Fourier Transform.

Parameters:
  • coeffs (np.ndarray) – masked non-uniform Fourier transform 1D data.

  • data (np.ndarray, optional) – output image array. Should be pinned memory for best performances.

Returns:

Inverse discrete Fourier transform of the input coefficients.

Return type:

np.ndarray

Note

This function uses numpy for all CPU arrays, and cupy for all on-gpu array. It will convert all its array argument to the respective array library. The outputs will be converted back to the original array module and device.

property uses_sense[source]#

Return True if the Fourier Operator uses the SENSE method.

property smaps[source]#

Sensitivity maps of the operator.

update_samples(new_samples: ndarray[tuple[int, ...], dtype[_ScalarType_co]], *, unsafe: bool = False)[source]#

Update the samples of the NUFFT operator.

Parameters:
  • new_samples (NDArray) – The new samples location of shape Nsamples x N_dimensions.

  • unsafe (bool, default False) – If True, the original array is used directly without any checks. This should be used with caution as it might lead to unexpected behavior.

Notes

If unsafe is True, the new_samples should be of shape (Nsamples, N_dimensions), F-ordered (column-major) and in the range [-pi, pi]. If not, this will lead to unexpected behavior. You have been warned.

If unsafe is False, this is automatically handled.

Note

This function uses numpy internally, and will convert all its array argument to numpy arrays. The outputs will be converted back to the original array module and device.

property density: ndarray[tuple[int, ...], dtype[floating]] | None[source]#

Density compensation of the operator.

classmethod pipe(kspace_loc, volume_shape, max_iter=10, osf=2, normalize=True, **kwargs)[source]#

Compute the density compensation weights for a given set of kspace locations.

Parameters:
  • kspace_loc (np.ndarray) – the kspace locations

  • volume_shape (np.ndarray) – the volume shape

  • max_iter (int default 10) – the number of iterations for density estimation

  • osf (float or int) – The oversampling factor the volume shape

  • normalize (bool) – Whether to normalize the density compensation.

get_lipschitz_cst(max_iter=10, tolerance=1e-05, **kwargs)[source]#

Return the Lipschitz constant of the operator.

Parameters:
  • max_iter (int) – Number of iteration to perform to estimate the Lipschitz constant.

  • tolerance (float, optional default 1e-5) – Tolerance for the spectral radius estimation.

  • kwargs – Extra kwargs for the operator.

Returns:

Lipschitz constant of the operator.

Return type:

float

data_consistency(image_data, obs_data)[source]#

Compute the data consistency estimation directly on gpu.

This mixes the op and adj_op method to perform F_adj(F(x-y)) on a per coil basis. By doing the computation coil wise, it uses less memory than the naive call to adj_op(op(x)-y)

Parameters:
  • image (array) – Image on which the gradient operation will be evaluated. N_coil x Image shape is not using sense.

  • obs_data (array) – Observed data.

Note

This function uses numpy for all CPU arrays, and cupy for all on-gpu array. It will convert all its array argument to the respective array library. The outputs will be converted back to the original array module and device.

_abc_impl = <_abc._abc_data object>[source]#
_dc_host(image_data, obs_data)[source]#
_safe_squeeze(arr)[source]#

Squeeze the first two dimensions of shape of the operator.

check_shape(*, image=None, ksp=None)[source]#

Validate the shapes of the image or k-space data against operator shapes.

Parameters:
  • image (NDArray, optional) – If passed, the shape of image data will be checked.

  • ksp (NDArray or object, optional) – If passed, the shape of the k-space data will be checked.

Raises:

ValueError – If the shape of the provided image does not match the expected operator shape, or if the number of k-space samples does not match the expected number of samples.

compute_density(method: Callable[[...], ndarray[tuple[int, ...], dtype[_ScalarType_co]]] | bool | None | str | dict[str, Any] = None)[source]#

Compute the density compensation weights and set it.

Parameters:

method (str or callable or array or dict or bool) –

The method to use to compute the density compensation.

  • If a string, the method should be registered in the density registry.

  • If a callable, it should take the samples and the shape as input.

  • If a dict, it should have a key ‘name’, to determine which method to use. other items will be used as kwargs.

  • If an array, it should be of shape (Nsamples,) and will be used as is.

  • If True, the method pipe is chosen as default estimation method.

Notes

The “pipe” method is only available for the following backends: tensorflow, finufft, cufinufft, gpunufft, torchkbnufft-cpu and torchkbnufft-gpu.

compute_smaps(method: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | Callable[[...], ndarray[tuple[int, ...], dtype[_ScalarType_co]]] | str | dict[str, Any] | None = None)[source]#

Compute the sensitivity maps and set it.

Parameters:

method (callable or dict or array) – The method to use to compute the sensitivity maps. If an array, it should be of shape (NCoils,XYZ) and will be used as is. If a dict, it should have a key ‘name’, to determine which method to use. other items will be used as kwargs. If a callable, it should take the samples and the shape as input. Note that this callable function should also hold the k-space data (use funtools.partial)

property cpx_dtype[source]#

Return complex floating precision of the operator.

grad_traj_plan()[source]#

Context manager to enable gradient computation with respect to trajectory.

property img_full_shape: tuple[int, ...][source]#

Full image shape with batch and coil dimensions.

interfaces: dict[str, tuple[bool, type[FourierOperatorBase]]] = {'bart': (False, <class 'mrinufft.operators.interfaces.bart.MRIBartNUFFT'>), 'cartesian': (True, <class 'mrinufft.operators.cartesian.MRICartesianOperator'>), 'cufinufft': (True, <class 'mrinufft.operators.interfaces.cufinufft.MRICufiNUFFT'>), 'ducc0': (False, <class 'mrinufft.operators.interfaces.ducc0.MRIDUCC0'>), 'finufft': (True, <class 'mrinufft.operators.interfaces.finufft.MRIfinufft'>), 'gpunufft': (True, <class 'mrinufft.operators.interfaces.gpunufft.MRIGpuNUFFT'>), 'numpy': (True, <class 'mrinufft.operators.interfaces.nudft_numpy.MRInumpy'>), 'pynfft': (False, <class 'mrinufft.operators.interfaces.nfft.MRInfft'>), 'pynufft-cpu': (False, <class 'mrinufft.operators.interfaces.pynufft_cpu.MRIPynufft'>), 'sigpy': (True, <class 'mrinufft.operators.interfaces.sigpy.MRISigpyNUFFT'>), 'stacked': (True, <class 'mrinufft.operators.stacked.MRIStackedNUFFT'>), 'stacked-cufinufft': (True, <class 'mrinufft.operators.stacked.MRIStackedNUFFTGPU'>), 'tensorflow': (False, <class 'mrinufft.operators.interfaces.tfnufft.MRITensorflowNUFFT'>), 'torchkbnufft-cpu': (False, <class 'mrinufft.operators.interfaces.torchkbnufft.TorchKbNUFFTcpu'>), 'torchkbnufft-gpu': (False, <class 'mrinufft.operators.interfaces.torchkbnufft.TorchKbNUFFTgpu'>)}[source]#
property ksp_full_shape: tuple[int, int, int][source]#

Full kspace shape with batch and coil dimensions.

make_autograd(*, wrt_data: bool = True, wrt_traj: bool = False, paired_batch: bool = False) MRINufftAutoGrad[source]#

Make a new Operator with autodiff support.

Parameters:
  • wrt_data (bool, optional) – If the gradient with respect to the data is computed, default is true

  • wrt_traj (bool, optional) – If the gradient with respect to the trajectory is computed, default is false

  • paired_batch (int, optional) – If provided, specifies batch size for varying data/smaps pairs. Default is None, which means no batching

Returns:

A NUFFT operator with autodiff capabilities.

Return type:

torch.nn.module

Raises:

ValueError – If autograd is not available.

make_deepinv_phy(*args, **kwargs) DeepInvPhyNufft[source]#

Make a new DeepInv Physics with NUFFT operator.

Parameters:
  • wrt_data (bool, optional) – If the gradient with respect to the data is computed, default is true

  • wrt_traj (bool, optional) – If the gradient with respect to the trajectory is computed, default is false

  • paired_batch (int, optional) – If provided, specifies batch size for varying data/smaps pairs. Default is None, which means no batching

  • viewed_as_real (bool, optional) – If True, the DeepInverse physics wrapper accepts and returns real-view tensors with a final dimension of size 2 representing the real and imaginary parts. Default is False.

Returns:

A NUFFT operator with autodiff capabilities.

Return type:

torch.nn.module

Raises:

ValueError – If autograd is not available.

make_linops(*, cupy: bool = False)[source]#

Create a Scipy Linear Operator from the NUFFT operator.

We add a _nufft private attribute with the current operator.

Parameters:

cupy (bool, default False) – If True, create a Cupy Linear Operator

See also

-, -

property n_samples: int[source]#

Return the number of samples used by the operator.

property ndim[source]#

Number of dimensions in image space of the operator.

property norm_factor: floating[source]#

Normalization factor of the operator.

pinv_solver(kspace_data, optim='lsqr', **kwargs)[source]#

Solves the linear system Ax = y.

It uses a least-square optimization solver,

Parameters:
  • kspace_data (NDArray) – The k-space data to reconstruct.

  • optim (str, default "lsqr") – name of the least-square optimizer to use.

  • **kwargs – Extra arguments to pass to the least-square optimizer.

Returns:

Reconstructed image

Return type:

NDArray

property samples: ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]#

Return the samples used by the operator.

toggle_grad_traj()[source]#

Toggle gradient computation with respect to trajectory.

property uses_density[source]#

Return True if the operator uses density compensation.

classmethod with_autograd(wrt_data=True, wrt_traj=False, paired_batch=False, *args, **kwargs)[source]#

Return a Fourier operator with autograd capabilities.

with_off_resonance_correction(readout_time: NDArray, b0_map: NDArray | None = None, r2star_map: NDArray | None = None, mask: NDArray | None = None, interpolator: str | dict | tuple[NDArray, NDArray] = 'svd') MRIFourierCorrected[source]#

Return a new operator with Off Resonnance Correction.

Return type:

MRIFourierCorrected