def test_returnsCorrect(self):
        homeDirectory = expanduser('~')
        dataDirectory = join(homeDirectory, '.dipy', 'isbi2013')

        if not exists(dataDirectory):
            fetch_isbi2013_2shell()

            oldFileNamebval = join(dataDirectory, 'phantom64.bval')
            newFileNamebval = join(dataDirectory, 'bvals.txt')
            rename(oldFileNamebval, newFileNamebval)

            oldFileNamebvecs = join(dataDirectory, 'phantom64.bvec')
            newFileNamebvecs = join(dataDirectory, 'bvecs_moco_norm.txt')
            rename(oldFileNamebvecs, newFileNamebvecs)

            oldFileNameData = join(dataDirectory, 'phantom64.nii.gz')
            newDataDirectory = join(dataDirectory, 'mri')
            makedirs(newDataDirectory)
            newFileNameData = join(newDataDirectory, 'diff_preproc.nii.gz')
            rename(oldFileNameData, newFileNameData)

        gtab, data, voxelSize = readHCP(dataDirectory)
        self.assertIsInstance(gtab, GradientTable)
        self.assertEqual(gtab.bvals.shape, np.array([
            64,
        ]))
        self.assertTrue(
            np.allclose(np.unique(np.round(gtab.bvals)),
                        np.array([0., 1500., 2500.])))
        self.assertTrue(np.array_equal(gtab.bvecs.shape, np.array([64, 3])))
        self.assertEqual(voxelSize, (1.5, 1.5, 1.5))

        normOfbvecs = np.sum(gtab.bvecs**2, 1)
        self.assertTrue(np.allclose(normOfbvecs[np.invert(gtab.b0s_mask)], 1.))

        smallDelta = 12.9
        bigDelta = 21.8
        tau = bigDelta - smallDelta / 3.0
        expectedqvals = np.sqrt(gtab.bvals / tau) / (2 * np.pi)
        self.assertTrue(np.allclose(gtab.qvals, expectedqvals))

        self.assertTrue(np.array_equal(data.shape, np.array([50, 50, 50, 64])))
        self.assertTrue(np.all(data >= 0))
示例#2
0
Continuous and analytical diffusion signal modelling with 3D-SHORE
==================================================================

We show how to model the diffusion signal as a linear combination
of continuous functions from the SHORE basis [Merlet2013]_.
We also compute the analytical Orientation Distribution Function (ODF).

First import the necessary modules:
"""

from dipy.reconst.shore import ShoreModel
from dipy.reconst.shm import sh_to_sf
from dipy.viz import fvtk
from dipy.data import fetch_isbi2013_2shell, read_isbi2013_2shell, get_sphere
from dipy.core.gradients import gradient_table
"""
Download and read the data for this tutorial.

fetch_isbi2013_2shell() provides data from the ISBI HARDI contest 2013 acquired 
for two shells at b-values 1500 and 2500.

The six parameters of these two functions define the ROI where to reconstruct
the data. They respectively correspond to (xmin,xmax,ymin,ymax,zmin,zmax)
with x, y, z and the three axis defining the spatial positions of the voxels.
"""

fetch_isbi2013_2shell()
img, gtab = read_isbi2013_2shell()
data = img.get_data()
data_small = data[10:40, 22, 10:40]
示例#3
0
from dipy.viz import fvtk
from dipy.data import fetch_isbi2013_2shell, read_isbi2013_2shell, get_sphere
from dipy.core.gradients import gradient_table

"""
Download and read the data for this tutorial.

two_shells_voxels() provides data from the ISBI HARDI contest 2013 acquired 
for two shells at b-values 1500 and 2500.

The six parameters of these two functions define the ROI where to reconstruct
the data. They respectively correspond to (xmin,xmax,ymin,ymax,zmin,zmax)
with x,y and the three axis defining the spatial positions of the voxels.
"""

fetch_isbi2013_2shell()
img, gtab=read_isbi2013_2shell()
data = img.get_data()
data_small=data[10:40,10:40,25]

print('data.shape (%d, %d, %d, %d)' % data.shape)

"""
data contains the voxel data and gtab contains a GradientTable
object (gradient information e.g. b-values). For example to read the b-values
it is possible to write print(gtab.bvals).

Instantiate the SHORE Model.

radial_order is the radial order of the SHORE basis.