MRICufiNUFFT#
- class mrinufft.operators.MRICufiNUFFT(samples, shape, density=False, n_coils=1, n_batchs=1, smaps=None, smaps_cached=False, verbose=False, squeeze_dims=False, n_trans=1, **kwargs)[source]#
Bases:
FourierOperatorBase,_ToggleGradPlanMixinMRI Transform operator, build around cufinufft.
This operator adds density estimation and compensation (preconditioning) and multicoil support.
- Parameters:
samples (np.ndarray or GPUArray.) – The samples location of shape
Nsamples x N_dimensions.shape (tuple) – Shape of the image space.
n_coils (int) – Number of coils.
n_batchs (int) – Size of the batch dimension.
density (bool or array) –
- Density compensation support.
If array, use this for density compensation
If True, the density compensation will be automatically estimated, using the fixed point method.
If False, density compensation will not be used.
smaps (np.ndarray or GPUArray , optional) –
If None: no Smaps wil be used.
If np.ndarray: Smaps will be copied on the device, according to smaps_cached.
If GPUArray, the smaps are already cached.
smaps_cached (bool, default False) –
If False the smaps are copied on device and free at each iterations.
If True, the smaps are copied on device and stay on it.
squeeze_dims (bool, default False) – If True, will try to remove the singleton dimension for batch and coils.
n_trans (int, default 1) – Number of transform to perform in parallel by cufinufft.
kwargs – Extra kwargs for the raw cufinufft operator
Notes
Cufinufft is able to run multiple transform in parallel, this is controlled by the n_trans parameter. The data provided should be of shape, (n_batch, n_coils, img_shape) for op (type2) and (n_batch, n_coils, n_samples) for adjoint (type1). and in contiguous memory order.
For now only single precision (float32 and complex64) is supported
See also
cufinufft.raw_operator.RawCufinufftMethods
__init__Non Cartesian MRI adjoint operator.
Validate the shapes of the image or k-space data against operator shapes.
Compute the density compensation weights and set it.
Compute the sensitivity maps and set it.
Compute the data consistency estimation directly on gpu.
Return the Lipschitz constant of the operator.
Context manager to enable gradient computation with respect to trajectory.
Make a new Operator with autodiff support.
Make a new DeepInv Physics with NUFFT operator.
Create a Scipy Linear Operator from the NUFFT operator.
Non Cartesian MRI forward operator.
Solves the linear system Ax = y.
Compute the density compensation weights for a given set of kspace locations.
Toggle gradient computation with respect to trajectory.
Update the samples of the NUFFT operator.
Return a Fourier operator with autograd capabilities.
Return a new operator with Off Resonnance Correction.
Attributes
Size in Bytes of the compute batch of images.
Size in Bytes of the compute batch of samples.
Return complex floating precision of the operator.
Density compensation of the operator.
Return floating precision of the operator.
Return the underlying precision parameter.
Full image shape with batch and coil dimensions.
Image size in bytes.
Full kspace shape with batch and coil dimensions.
k-space size in bytes.
Number of coils for the operator.
Number of coils for the operator.
Return the number of samples used by the operator.
Number of dimensions in image space of the operator.
Norm factor of the operator.
Return the samples used by the operator.
Shape of the image space of the operator.
Sensitivity maps of the operator.
Return True if the operator uses density compensation.
Return True if the operator uses sensitivity maps.
Examples using
mrinufft.operators.MRICufiNUFFT#- update_samples(new_samples, *, unsafe=False)[source]#
Update the samples of the NUFFT operator.
- Parameters:
new_samples (np.ndarray or GPUArray) – 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.
- property density: ndarray[tuple[int, ...], dtype[floating]] | None[source]#
Density compensation of the operator.
- op(data, ksp_d=None)[source]#
Non Cartesian MRI forward operator.
- Parameters:
data (np.ndarray or GPUArray)
space. (The uniform (2D or 3D) data in image)
- Return type:
Results array on the same device as data.
Notes
this performs for every coil ell: ..math:: mathcal{F}mathcal{S}_ell x
Note
This function uses
numpyfor all CPU arrays, andcupyfor 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, img_d=None)[source]#
Non Cartesian MRI adjoint operator.
- Parameters:
coeffs (np.array or GPUArray)
- Return type:
Array in the same memory space of coeffs. (ie on cpu or gpu Memory).
Note
This function uses
numpyfor all CPU arrays, andcupyfor 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_sense_device(coeffs, img_d=None)[source]#
Perform sense reconstruction when data is on device.
- _adj_op_sense_host(coeffs, img_d=None)[source]#
Perform sense reconstruction when data is on host.
On device the following array are involved: - coil_img(S, T, 1, X,Y,Z) - ksp_batch(B, 1, X,Y,Z) - smaps_batched(S, T, X,Y,Z) - density_batched(T, K)
- 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.
- _dc_calibless_host(image_data, obs_data)[source]#
Calibrationless Gradient computation when all data is on host.
- _dc_calibless_device(image_data, obs_data)[source]#
Calibrationless Gradient computation when all data is on device.
- 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)
- grad_traj_plan()[source]#
Context manager to enable gradient computation with respect to trajectory.
- 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
-,-
- 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.
- 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:
- 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. We normalize such that the energy of PSF = 1