MRIFourierCorrected#
- class mrinufft.operators.MRIFourierCorrected(fourier_op: FourierOperatorBase, b0_map: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, readout_time: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, r2star_map: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, mask: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, interpolator: str | dict | tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]] = 'svd')[source]#
Bases:
FourierOperatorBaseFourier Operator with B0 Inhomogeneities compensation.
This is a wrapper around the Fourier Operator to compensate for the B0 inhomogeneities in the k-space.
- Parameters:
fourier_op (FourierOperatorBase) – Existing NUFFT operator.
b0_map (NDArray) – Static field inhomogeneities map.
b0_mapandreadout_timeshould have reciprocal units. (e.g. [Hz] and [s]) Also supports Cupy arrays and Torch tensors.readout_time (NDArray) – Readout time in
[s]of shape(n_shots, n_pts)or(n_shots * n_pts,). Also supports Cupy arrays and Torch tensors.mask (NDArray, optional) – Boolean mask of the region of interest (e.g., corresponding to the imaged object). This is used to exclude the background field-map values from histogram computation. The default is
None(use the whole map). Also supports Cupy arrays and Torch tensors.r2star_map (NDArray, optional) – Effective transverse relaxation map (R2*).
r2star_mapandreadout_timeshould have reciprocal units (e.g. [Hz] and [s]). Must have same shape asb0_map. The default isNone(purely imaginary field). Also supports Cupy arrays and Torch tensors.interpolators (str, dict, tuple[NDArray, NDArray]) –
Determine how to decompose the field-map.
If
str, use an existing method in extra/field_map.py with default parametersIf
{"name":name, **kwargs}use an existing method in extra_field_map.py parameterize by kwargs.If``tuple[NDArray, NDArray]`` use this directly as the decomposition (B and C)
Notes
The total field map used to calculate the field coefficients is
field_map = R2*_map + 1j * B0_map. If R2* is not provided, the field is purely imaginary:field_map = 1j * B0_map.You can also use the method
.with_off_resonance_correctionto augment an existing operator with off-resonance correction capability.See also
Methods
__init__Compute Adjoint Operation with off-resonance effect.
Whether the operator supports autograd differentiation.
Validate the shapes of the image or k-space data against operator shapes.
Compute the density compensation weights and set it.
Decompose the field-map in space and time-wise interpolators.
Compute the sensitivity maps and set it.
Compute the gradient data consistency.
Return the Lipschitz constant of the operator.
Make a new Operator with autodiff support.
Make a new DeepInv Physics with NUFFT operator.
Create a Scipy Linear Operator from the NUFFT operator.
Compute Forward Operation with off-resonance effect.
Solves the linear system Ax = y.
Update the field map and recompute the interpolators.
Update the samples of the NUFFT operator.
Return a Fourier operator with autograd capabilities.
Return a new operator with Off Resonnance Correction.
Attributes
Return complex floating precision of the operator.
Density compensation of the operator.
Return floating precision of the operator.
Get the field map used for off-resonance correction.
Get the full readout time for all samples.
Full image shape with batch and coil dimensions.
Full kspace shape with batch and coil dimensions.
Number of coils for the operator.
Number of coils for the operator.
Number of interpolators used to approximate the off-resonance effects.
Return the number of samples used by the operator.
Number of time points in a shot.
Number of dimensions in image space of the operator.
Normalization 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.MRIFourierCorrected#- compute_interpolator(interpolators: str | dict | tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]], field_map: ndarray[tuple[int, ...], dtype[_ScalarType_co]], readout_time: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None, mask: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None)[source]#
Decompose the field-map in space and time-wise interpolators.
Sets the B and C attributes.
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.
- update_field_map(new_field_map: ndarray[tuple[int, ...], dtype[_ScalarType_co]])[source]#
Update the field map and recompute the interpolators.
- property field_map: ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]#
Get the field map used for off-resonance correction.
- property full_readout_time: ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]#
Get the full readout time for all samples.
- autograd_available() bool[source]#
Whether the operator supports autograd differentiation.
- Return type:
- op(data, *args)[source]#
Compute Forward Operation with off-resonance effect.
- Parameters:
data (NDArray) – N-D input image.
- Returns:
Masked distorted N-D k-space. Array module is the same as input data.
- Return type:
NDArray
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, *args)[source]#
Compute Adjoint Operation with off-resonance effect.
- Parameters:
coeffs (NDArray) – k-space data
- Returns:
Inverse Fourier transform of the distorted input k-space. Array module is the same as input coeffs.
- Return type:
NDArray
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.
- property n_interpolators[source]#
Number of interpolators used to approximate the off-resonance effects.
- 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)
- data_consistency(image_data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], obs_data: ndarray[tuple[int, ...], dtype[_ScalarType_co]]) ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]#
Compute the gradient data consistency.
This is the naive implementation using adj_op(op(x)-y). Specific backend can (and should!) implement a more efficient version.
- property density: ndarray[tuple[int, ...], dtype[floating]] | None[source]#
Density compensation of the operator.
- 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, wrt_field_map: 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
wrt_field_map (bool, optional) – If the gradient with respect to the field map 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.
- update_samples(new_samples: ndarray[tuple[int, ...], dtype[floating]], *, unsafe: bool = 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.
- 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: