Hi DIPY Experts,
I had a few questions regarding the Manjon localpca implementation using DIPY.
1) In the case of multiple b=0 volumes, is the noise estimated from just the b=0 volumes? In the case of only one b=0 volume is the noise then estimated from the diffusion weighted images instead?
2) Are the images registered using an affine transform so that the images are roughly aligned prior to noise estimation and localPCA? If so, are the affine transforms just stored as part of the header and not applied to create a new image in order to preserve the uncorrelated nature of the noise?
3) Some data such as those from GE scanners sometimes upsample the data during reconstruction. If this is true, then the assumption of spatial independence of noise is not held true and when running the localPCA (Matlab version) the results did not look much more different than the inputs. In this situation, is there another denoising technique you recommend that could handle this situation?
Thanks,
Ajay

Dear Experts,
I tried to process ivim data by following https://www.frontiersin.org/articles/10.3389/fninf.2014.00008/full and https://dipy.org/documentation/1.1.1./examples_built/reconst_ivim/.
However, I am unable to get output.
I will be highly obliged if you can examine the log below and advice.
Best Regards,
Amitkumar J. Choudhari,
Assistant Professor, Dept. of Radiology,
Tata Memorial Hospital, Mumbai.
>>> fimg = "dwi.nii.gz"
>>> import nibabel as nib
>>> img = nib.load(fimg)
>>> data = img.get_data()
<stdin>:1: DeprecationWarning: get_data() is deprecated in favor of get_fdata(), which has a more predictable return type. To obtain get_data() behavior going forward, use numpy.asanyarray(img.dataobj).
* deprecated from version: 3.0
* Will raise <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 5.0
>>> data.shape
(176, 176, 23, 43)
>>> affine = img.get_affine()
<stdin>:1: DeprecationWarning: get_affine method is deprecated.
Please use the ``img.affine`` property instead.
* deprecated from version: 2.1
* Will raise <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 4.0
>>> header = img.get_header()
<stdin>:1: DeprecationWarning: get_header method is deprecated.
Please use the ``img.header`` property instead.
* deprecated from version: 2.1
* Will raise <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 4.0
>>>
>>> header = img.get_header()
>>>
>>> voxel_size = header.get_zooms()[:3]
>>> voxel_size
(1.3068181, 1.3068181, 6.0)
>>> S0 = data[:, :, :, 0]
>>> img2 = nib.Nifti1Image(S0, affine)
>>> nib.save (img2, "sub_data.nii.gz")
>>> from dipy.segment.mask import median_otsu
>>> mask, S0_mask = median_otsu(data [:, :, :, 0])
>>> fbval = "dwi.bval"
>>> fbvec = "dwi.bvec"
>>> from dipy.io<http://dipy.io/> import read_bvals_bvecs
>>> bvals, bvecs = read_bvals_bvecs(fbval, fbvec)
>>> from dipy.core.gradients import gradient_table
>>> gtab = gradient_table(bvals, bvecs)
>>> gtab
<dipy.core.gradients.GradientTable object at 0x7f7265d78820>
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from dipy.reconst.ivim import IvimModel
>>> from dipy.data import get_fnameshttps://dipy.org/documentation/1.1.1./examples_built/reconst_ivim/<http://dipy.org/documentation/1.1.1./examples_built/reconst_ivim/>
>>> from dipy.io.image import load_nifti_data
>>> fraw, fbval, fbvec = get_fnames('ivim')
Download Progress: [########################################] 100.00% of 0.00 MB>>>
>>> data = img.get_data()
<stdin>:1: DeprecationWarning: get_data() is deprecated in favor of get_fdata(), which has a more predictable return type. To obtain get_data() behavior going forward, use numpy.asanyarray(img.dataobj).
* deprecated from version: 3.0
* Will raise <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 5.0
>>> bvals, bvecs = read_bvals_bvecs(fbval, fbvec)
>>> gtab = gradient_table(bvals, bvecs, b0_threshold=0)
>>> print('data.shape (%d, %d, %d, %d)' % data.shape)
data.shape (176, 176, 23, 43)
>>> z = 12
>>> b = 0
>>> plt.imshow(data[:, :, z, b].T, origin='lower', cmap='gray',
... interpolation='nearest')
<matplotlib.image.AxesImage object at 0x7f723009d5e0>
>>> plt.axhline(y=100)
<matplotlib.lines.Line2D object at 0x7f7233b643a0>
>>> plt.axvline(x=170)
<matplotlib.lines.Line2D object at 0x7f723009dd00>
>>> plt.savefig("ivim_data_slice.png")
>>> plt.close()
>>> ivimmodel = IvimModel(gtab, fit_method='trr')
/home/amitjc/.local/lib/python3.8/site-packages/dipy/reconst/ivim.py:147: UserWarning: Bounds for this fit have been set from experiments and literature survey. To change the bounds, please input your bounds in model definition...
warnings.warn(bounds_warning, UserWarning)
>>> x1, x2 = 50, 125
>>> y1, y2 = 40, 140
>>> data_slice = data[x1:x2, y1:y2, z, :]
>>> plt.imshow(data[x1:x2, y1:y2, z, b].T, origin='lower',
... cmap="gray", interpolation='nearest')
<matplotlib.image.AxesImage object at 0x7f72232b7c70>
>>> plt.savefig("CSF_slice.png")
>>> plt.close()
>>> ivimmodel = IvimModel(gtab, fit_method='trr')
>>> ivimfit = ivimmodel.fit(data_slice)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/amitjc/.local/lib/python3.8/site-packages/dipy/reconst/multi_voxel.py", line 33, in new_fit
fit_array[ijk] = single_voxel_fit(self, data[ijk])
File "/home/amitjc/.local/lib/python3.8/site-packages/dipy/reconst/ivim.py", line 317, in fit
S0_prime, D = self.estimate_linear_fit(
File "/home/amitjc/.local/lib/python3.8/site-packages/dipy/reconst/ivim.py", line 377, in estimate_linear_fit
-np.log(data[self.gtab.bvals >=
IndexError: boolean index did not match indexed array along dimension 0; dimension is 43 but corresponding boolean dimension is 21

Dear Linda,
The ‘.f’ “function" gives you the free water volume fractions. So if you want to exclude FA values of voxels with high free water volume fractions, let's say voxels containing more than 70% of free water volume fraction, you have to run the lines of code that you mentioned on your previous email:
F = fwdtifit.f
FA = fwdtifit.fa
FA[F > 0.7] = 0
In the same way, if you want to remove the AD, RD, and MD values on these voxels containing high free water volume fractions, you have to use the following lines of code:
MD = fwdtifit.md
MD[F > 0.7] = 0
RD = fwdtifit.rd
RD[F > 0.7] = 0
AD = fwdtifit.ad
AD[F > 0.7] = 0
Note that these later lines of code are different to what you sent before.
Best regards,
Rafael NH

Dear all,
That warning is likely to rise due to some background voxel. However, if this warning appears consistently, please rise an issue in Dipy including some example that triggers that warning.
Regarding the model parameters (Ajay’s question - sorry for the late reply), fwdti returns a matrix which last dimensions corresponds to:
1) Three diffusion tensor's eigenvalues
2) Three lines of the eigenvector matrix each containing the
first, second and third coordinates of the eigenvector
3) The volume fraction of the free water compartment
(See functions documentation).
So if you want to save tensor parameters in lower triangule format you have to convert them first. Something like this:
from dipy.reconst.dti import lower_triangular
from dipy.reconst.vec_val_sum import vec_val_vect
evals = fwdtifit.evals
evecs = fwdtifit.evecs
dt = lower_triangular(vec_val_vect(evecs, evals))
Best Regards,
Rafael