Esempio n. 1
0
def test_ClosestPeakSelector():
    v, e, vecs_xy, bval, bvec, sig = make_fake_signal()
    opdf_fitter = SlowAdcOpdfModel(bval,
                                   bvec.T,
                                   6,
                                   odf_vertices=v,
                                   odf_edges=e)
    opdf_fitter.angular_distance_threshold = 0.
    norm_sig = sig
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    C = opdf_fitter.fit_data(norm_sig)
    S = opdf_fitter.evaluate_odf(norm_sig)
    for ii in xrange(len(vecs_xy)):
        if np.dot(vecs_xy[ii], [0, 1., 0]) < .56:
            assert_raises(StopIteration, stepper.next_step, ii, [0, 1., 0])
        else:
            step = stepper.next_step(ii, [0, 1., 0])
            s2 = stepper.next_step(ii, vecs_xy[ii])
            assert_array_equal(vecs_xy[ii], step)
            step = stepper.next_step(ii, [1., 0, 0.])
            assert_array_equal([1., 0, 0.], step)

    norm_sig.shape = (2, 2, 4, -1)
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    step = stepper.next_step((0, 0, 0), [1, 0, 0])
    assert_array_equal(step, [1, 0, 0])
Esempio n. 2
0
def test_ClosestPeakSelector():
    v, e, vecs_xy, bval, bvec, sig = make_fake_signal()
    opdf_fitter = SlowAdcOpdfModel(6,
                                   bval,
                                   bvec,
                                   sampling_points=v,
                                   sampling_edges=e)
    norm_sig = sig[..., 1:]
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    C = opdf_fitter.fit_data(norm_sig)
    S = opdf_fitter.evaluate(norm_sig)
    for ii in xrange(len(vecs_xy)):
        if np.dot(vecs_xy[ii], [0, 1., 0]) < .56:
            assert_raises(StopIteration, stepper.next_step, ii, [0, 1., 0])
        else:
            step = stepper.next_step(ii, [0, 1., 0])
            s2 = stepper.next_step(ii, vecs_xy[ii])
            assert_array_equal(vecs_xy[ii], step)
            step = stepper.next_step(ii, [1., 0, 0.])
            assert_array_equal([1., 0, 0.], step)

    norm_sig.shape = (2, 2, 4, -1)
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    step = stepper.next_step((0, 0, 0), [1, 0, 0])
    assert_array_equal(step, [1, 0, 0])
Esempio n. 3
0
def simple_tracking_function(data, fa, bval, bvec, seed_mask, start_steps,
                             voxel_size, density):
    """An example of a simple traking function using the tools in dipy

    This tracking function uses the SlowAdcOpdfModel to fit diffusion data. By
    using the ClosestPeakSelector, the function tracks along the peak of Opdf
    closest to the incoming direction. It also uses the BoundryIntegrator to
    integrate the streamlines and NearestNeighborInterpolator to interpolate
    the data. The ResidualBootstrap means the tracks are probabilistic, not
    deterministic.
    """

    #the interpolator allows us to index the dwi data in continous space
    data_mask = fa > .2
    normalized_data = normalize_data(data, bval)
    interpolator = NearestNeighborInterpolator(normalized_data, voxel_size,
                                               data_mask)

    #the model fits the dwi data, this model can resolve crossing fibers
    #see documentation of SlowAdcOpdfModel for more info
    model = SlowAdcOpdfModel(6, bval, bvec, .006)
    vert, edges, faces = create_half_unit_sphere(4)
    model.set_sampling_points(vert, edges)

    #this residual bootstrap wrapper returns a sample from the bootstrap
    #distribution istead of returning the raw data
    min_signal = normalized_data.min()
    B = model.B
    wrapped_interp = ResidualBootstrapWrapper(interpolator, B, min_signal)


    #the peakselector returns the closest peak to the incoming direction when
    #in voxels with multiple peaks
    peak_finder = ClosestPeakSelector(model, wrapped_interp)
    peak_finder.angle_limit = 60

    seeds = seeds_from_mask(seed_mask, density, voxel_size)

    #the propagator is used to integrate the streamlines
    propogator = BoundryIntegrator(voxel_size)
    tracks = generate_streamlines(peak_finder, propogator, seeds, start_steps)

    return tracks
Esempio n. 4
0
def simple_tracking_function(data, fa, bval, bvec, seed_mask, start_steps,
                             voxel_size, density):
    """An example of a simple traking function using the tools in dipy

    This tracking function uses the SlowAdcOpdfModel to fit diffusion data. By
    using the ClosestPeakSelector, the function tracks along the peak of Opdf
    closest to the incoming direction. It also uses the BoundryIntegrator to
    integrate the streamlines and NearestNeighborInterpolator to interpolate
    the data. The ResidualBootstrap means the tracks are probabilistic, not
    deterministic.
    """

    #the interpolator allows us to index the dwi data in continous space
    data_mask = fa > .2
    normalized_data = normalize_data(data, bval)
    interpolator = NearestNeighborInterpolator(normalized_data, voxel_size,
                                               data_mask)

    #the model fits the dwi data, this model can resolve crossing fibers
    #see documentation of SlowAdcOpdfModel for more info
    model = SlowAdcOpdfModel(6, bval, bvec, .006)
    vert, edges, faces = create_half_unit_sphere(4)
    model.set_sampling_points(vert, edges)

    #this residual bootstrap wrapper returns a sample from the bootstrap
    #distribution istead of returning the raw data
    min_signal = normalized_data.min()
    B = model.B
    wrapped_interp = ResidualBootstrapWrapper(interpolator, B, min_signal)

    #the peakselector returns the closest peak to the incoming direction when
    #in voxels with multiple peaks
    peak_finder = ClosestPeakSelector(model, wrapped_interp)
    peak_finder.angle_limit = 60

    seeds = seeds_from_mask(seed_mask, density, voxel_size)

    #the propagator is used to integrate the streamlines
    propogator = BoundryIntegrator(voxel_size)
    tracks = generate_streamlines(peak_finder, propogator, seeds, start_steps)

    return tracks
Esempio n. 5
0
def test_ClosestPeakSelector():
    v, e, vecs_xy, bval, bvec, sig = make_fake_signal()
    opdf_fitter = SlowAdcOpdfModel(6, bval, bvec, sampling_points=v, sampling_edges=e)
    norm_sig = sig[..., 1:]
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    C = opdf_fitter.fit_data(norm_sig)
    S = opdf_fitter.evaluate(norm_sig)
    for ii in xrange(len(vecs_xy)):
        if np.dot(vecs_xy[ii], [0, 1., 0]) < .56:
            assert_raises(StopIteration, stepper.next_step, ii, [0, 1., 0])
        else:
            step = stepper.next_step(ii, [0, 1., 0])
            s2 = stepper.next_step(ii, vecs_xy[ii])
            assert_array_equal(vecs_xy[ii], step)
            step = stepper.next_step(ii, [1., 0, 0.])
            assert_array_equal([1., 0, 0.], step)

    norm_sig.shape = (2, 2, 4, -1)
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    step = stepper.next_step((0, 0, 0), [1, 0, 0])
    assert_array_equal(step, [1, 0, 0])
Esempio n. 6
0
def test_ClosestPeakSelector():
    v, e, vecs_xy, bval, bvec, sig = make_fake_signal()
    opdf_fitter = SlowAdcOpdfModel(bval, bvec.T, 6, odf_vertices=v, odf_edges=e)
    opdf_fitter.angular_distance_threshold = 0.0
    norm_sig = sig
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    C = opdf_fitter.fit_data(norm_sig)
    S = opdf_fitter.evaluate_odf(norm_sig)
    for ii in xrange(len(vecs_xy)):
        if np.dot(vecs_xy[ii], [0, 1.0, 0]) < 0.56:
            assert_raises(StopIteration, stepper.next_step, ii, [0, 1.0, 0])
        else:
            step = stepper.next_step(ii, [0, 1.0, 0])
            s2 = stepper.next_step(ii, vecs_xy[ii])
            assert_array_equal(vecs_xy[ii], step)
            step = stepper.next_step(ii, [1.0, 0, 0.0])
            assert_array_equal([1.0, 0, 0.0], step)

    norm_sig.shape = (2, 2, 4, -1)
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    step = stepper.next_step((0, 0, 0), [1, 0, 0])
    assert_array_equal(step, [1, 0, 0])
Esempio n. 7
0
def test_ClosestPeakSelector():
    sphere, vecs_xy, bval, bvec, sig = make_fake_signal()
    opdf_fitter = SlowAdcOpdfModel(bval, bvec.T, 6, sphere=sphere)
    opdf_fitter.angular_distance_threshold = 0.
    norm_sig = sig
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    stepper.angular_spacing_threshould = 0.
    S = opdf_fitter.fit(norm_sig).odf()
    for ii in xrange(len(vecs_xy)):
        if np.dot(vecs_xy[ii], [0, 1., 0]) < .56:
            assert_raises(StopIteration, stepper.next_step, ii, [0, 1., 0])
        else:
            step = stepper.next_step(ii, [0, 1., 0])
            s2 = stepper.next_step(ii, vecs_xy[ii])
            assert_array_equal(vecs_xy[ii], step)
            step = stepper.next_step(ii, [1., 0, 0.])
            assert_array_almost_equal([1., 0, 0.], step)

    norm_sig.shape = (2, 2, 4, -1)
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=49)
    step = stepper.next_step((0, 0, 0), [1, 0, 0])
    assert_array_almost_equal(step, [1, 0, 0])
Esempio n. 8
0
def test_set_angle_limit():
    bval = np.ones(100)
    bval[0] = 0
    bvec = np.ones((3, 100))
    sig = np.zeros(100)
    v = np.ones((200, 3)) / np.sqrt(3)
    e = None
    opdf_fitter = SlowAdcOpdfModel(bval,
                                   bvec.T,
                                   6,
                                   odf_vertices=v,
                                   odf_edges=e)
    norm_sig = sig[..., 1:]
    stepper = ClosestPeakSelector(opdf_fitter, norm_sig, angle_limit=55)
    assert_raises(ValueError, stepper._set_angle_limit, 99)
    assert_raises(ValueError, stepper._set_angle_limit, -1.1)