def organize_cfin_data(path=None): """ Create the expected file-system structure for the CFIN multi b-value diffusion data-set. """ dpd.fetch_cfin_multib() if path is None: if not op.exists(afq_home): os.mkdir(afq_home) my_path = afq_home else: my_path = path base_folder = op.join(my_path, 'cfin_multib', 'derivatives', 'dmriprep') if not op.exists(base_folder): anat_folder = op.join(base_folder, 'sub-01', 'sess-01', 'anat') os.makedirs(anat_folder, exist_ok=True) dwi_folder = op.join(base_folder, 'sub-01', 'sess-01', 'dwi') os.makedirs(dwi_folder, exist_ok=True) t1_img = dpd.read_cfin_t1() nib.save(t1_img, op.join(anat_folder, 'sub-01_sess-01_T1w.nii.gz')) dwi_img, gtab = dpd.read_cfin_dwi() nib.save(dwi_img, op.join(dwi_folder, 'sub-01_sess-01_dwi.nii.gz')) np.savetxt(op.join(dwi_folder, 'sub-01_sess-01_dwi.bvecs'), gtab.bvecs) np.savetxt(op.join(dwi_folder, 'sub-01_sess-01_dwi.bvals'), gtab.bvals) dataset_description = { "BIDSVersion": "1.0.0", "Name": "CFIN", "Subjects": ["sub-01"] } desc_file = op.join(my_path, 'cfin_multib', 'dataset_description.json') with open(desc_file, 'w') as outfile: json.dump(dataset_description, outfile)
import dipy.reconst.dki as dki import dipy.reconst.dti as dti import dipy.reconst.dki_micro as dki_micro from dipy.data import fetch_cfin_multib from dipy.data import read_cfin_dwi from dipy.segment.mask import median_otsu from scipy.ndimage.filters import gaussian_filter """ DKI requires multi-shell data, i.e. data acquired from more than one non-zero b-value. Here, we use fetch to download a multi-shell dataset which was kindly provided by Hansen and Jespersen (more details about the data are provided in their paper [Hansen2016]_). The total size of the downloaded data is 192 MBytes, however you only need to fetch it once. """ fetch_cfin_multib() img, gtab = read_cfin_dwi() data = img.get_data() affine = img.affine """ Function ``read_cfin_multib`` return img and gtab which contains respectively a nibabel Nifti1Image object (where the data can be extracted) and a GradientTable object with information about the b-values and b-vectors. Before fitting the data, we preform some data pre-processing. We first compute a brain mask to avoid unnecessary calculations on the background of the image. """
from dipy.data import fetch_cfin_multib, read_cfin_dwi, get_sphere from dipy.core.gradients import gradient_table import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable """ Download and read the data for this tutorial. MAPMRI requires multi-shell data, to properly fit the radial part of the basis. to ``False`` to only download eddy-current/motion corrected data. The total size of the downloaded data is 187.66 MBytes, however you only need to fetch it once. """ fetch_cfin_multib() """ ``data`` contains the voxel data and ``gtab`` contains a ``GradientTable`` object (gradient information e.g. b-values). For example, to show the b-values it is possible to write:: print(gtab.bvals) For the values of the q-space indices to make sense it is necessary to explicitly state the ``big_delta`` and ``small_delta`` parameters in the gradient table. """ img, gtab = read_cfin_dwi() big_delta = 0.0365 # seconds