Exemple #1
0
def sticks_and_ball_dummies(gtab):
    sb_dummies = {}
    S, sticks = SticksAndBall(gtab,
                              d=0.0015,
                              S0=100,
                              angles=[(0, 0)],
                              fractions=[100],
                              snr=None)
    sb_dummies['1fiber'] = (S, sticks)
    S, sticks = SticksAndBall(gtab,
                              d=0.0015,
                              S0=100,
                              angles=[(0, 0), (90, 0)],
                              fractions=[50, 50],
                              snr=None)
    sb_dummies['2fiber'] = (S, sticks)
    S, sticks = SticksAndBall(gtab,
                              d=0.0015,
                              S0=100,
                              angles=[(0, 0), (90, 0), (90, 90)],
                              fractions=[33, 33, 33],
                              snr=None)
    sb_dummies['3fiber'] = (S, sticks)
    S, sticks = SticksAndBall(gtab,
                              d=0.0015,
                              S0=100,
                              angles=[(0, 0), (90, 0), (90, 90)],
                              fractions=[0, 0, 0],
                              snr=None)
    sb_dummies['isotropic'] = (S, sticks)
    return sb_dummies
Exemple #2
0
def test_dsi_metrics():
    btable = np.loadtxt(get_fnames('dsi4169btable'))
    gtab = gradient_table(btable[:, 0], btable[:, 1:])
    data, golden_directions = SticksAndBall(gtab,
                                            d=0.0015,
                                            S0=100,
                                            angles=[(0, 0), (60, 0)],
                                            fractions=[50, 50],
                                            snr=None)

    dsmodel = DiffusionSpectrumModel(gtab, qgrid_size=21, filter_width=4500)
    rtop_signal_norm = dsmodel.fit(data).rtop_signal()
    dsmodel.fit(data).rtop_pdf()
    rtop_pdf = dsmodel.fit(data).rtop_pdf(normalized=False)
    assert_almost_equal(rtop_signal_norm, rtop_pdf, 6)
    dsmodel = DiffusionSpectrumModel(gtab, qgrid_size=21, filter_width=4500)
    mevals = np.array(([0.0015, 0.0003, 0.0003], [0.0015, 0.0003, 0.0003]))
    S_0, sticks_0 = MultiTensor(gtab,
                                mevals,
                                S0=100,
                                angles=[(0, 0), (60, 0)],
                                fractions=[50, 50],
                                snr=None)
    S_1, sticks_0 = MultiTensor(gtab,
                                mevals * 2.0,
                                S0=100,
                                angles=[(0, 0), (60, 0)],
                                fractions=[50, 50],
                                snr=None)
    MSD_norm_0 = dsmodel.fit(S_0).msd_discrete(normalized=True)
    MSD_norm_1 = dsmodel.fit(S_1).msd_discrete(normalized=True)
    assert_almost_equal(MSD_norm_0, 0.5 * MSD_norm_1, 4)
Exemple #3
0
def dsi_deconv_voxels():
    gtab = gradient_table(np.loadtxt(get_data('dsi515btable')))
    data = np.zeros((2, 2, 2, 515))
    for ix in range(2):
        for iy in range(2):
            for iz in range(2):
                data[ix, iy, iz], dirs = SticksAndBall(gtab,
                                                       d=0.0015,
                                                       S0=100,
                                                       angles=[(0, 0), (90, 0)],
                                                       fractions=[50, 50],
                                                       snr=None)
    return data, gtab
Exemple #4
0
def test_shore_odf():
    gtab = get_isbi2013_2shell_gtab()

    # load symmetric 724 sphere
    sphere = get_sphere('symmetric724')

    # load icosahedron sphere
    sphere2 = create_unit_sphere(5)
    data, golden_directions = SticksAndBall(gtab,
                                            d=0.0015,
                                            S0=100,
                                            angles=[(0, 0), (90, 0)],
                                            fractions=[50, 50],
                                            snr=None)
    asm = ShoreModel(gtab,
                     radial_order=6,
                     zeta=700,
                     lambdaN=1e-8,
                     lambdaL=1e-8)
    # symmetric724
    asmfit = asm.fit(data)
    odf = asmfit.odf(sphere)
    odf_sh = asmfit.odf_sh()
    odf_from_sh = sh_to_sf(odf_sh, sphere, 6, basis_type=None)
    assert_almost_equal(odf, odf_from_sh, 10)

    directions, _, _ = peak_directions(odf, sphere, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    # 5 subdivisions
    odf = asmfit.odf(sphere2)
    directions, _, _ = peak_directions(odf, sphere2, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    sb_dummies = sticks_and_ball_dummies(gtab)
    for sbd in sb_dummies:
        data, golden_directions = sb_dummies[sbd]
        asmfit = asm.fit(data)
        odf = asmfit.odf(sphere2)
        directions, _, _ = peak_directions(odf, sphere2, .35, 25)
        if len(directions) <= 3:
            assert_equal(len(directions), len(golden_directions))
        if len(directions) > 3:
            assert_equal(gfa(odf) < 0.1, True)
Exemple #5
0
def test_dsi():
    # load symmetric 724 sphere
    sphere = get_sphere('symmetric724')
    # load icosahedron sphere
    sphere2 = create_unit_sphere(5)
    btable = np.loadtxt(get_data('dsi515btable'))
    gtab = gradient_table(btable[:, 0], btable[:, 1:])
    data, golden_directions = SticksAndBall(gtab,
                                            d=0.0015,
                                            S0=100,
                                            angles=[(0, 0), (90, 0)],
                                            fractions=[50, 50],
                                            snr=None)

    ds = DiffusionSpectrumDeconvModel(gtab)

    # symmetric724
    dsfit = ds.fit(data)
    odf = dsfit.odf(sphere)
    directions, _, _ = peak_directions(odf, sphere, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    # 5 subdivisions
    dsfit = ds.fit(data)
    odf2 = dsfit.odf(sphere2)
    directions, _, _ = peak_directions(odf2, sphere2, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    assert_equal(dsfit.pdf().shape, 3 * (ds.qgrid_size, ))
    sb_dummies = sticks_and_ball_dummies(gtab)
    for sbd in sb_dummies:
        data, golden_directions = sb_dummies[sbd]
        odf = ds.fit(data).odf(sphere2)
        directions, _, _ = peak_directions(odf, sphere2, .35, 25)
        if len(directions) <= 3:
            assert_equal(len(directions), len(golden_directions))
        if len(directions) > 3:
            assert_equal(gfa(odf) < 0.1, True)

    assert_raises(ValueError,
                  DiffusionSpectrumDeconvModel,
                  gtab,
                  qgrid_size=16)
Exemple #6
0
def test_gqi():
    #load symmetric 724 sphere
    sphere = get_sphere('symmetric724')
    #load icosahedron sphere
    sphere2 = create_unit_sphere(5)
    btable = np.loadtxt(get_data('dsi515btable'))
    bvals = btable[:, 0]
    bvecs = btable[:, 1:]
    gtab = gradient_table(bvals, bvecs)
    data, golden_directions = SticksAndBall(gtab,
                                            d=0.0015,
                                            S0=100,
                                            angles=[(0, 0), (90, 0)],
                                            fractions=[50, 50],
                                            snr=None)
    gq = GeneralizedQSamplingModel(gtab, method='gqi2', sampling_length=1.4)

    #symmetric724
    gqfit = gq.fit(data)
    odf = gqfit.odf(sphere)
    directions, values, indices = peak_directions(odf, sphere, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    #5 subdivisions
    gqfit = gq.fit(data)
    odf2 = gqfit.odf(sphere2)
    directions, values, indices = peak_directions(odf2, sphere2, .35, 25)
    assert_equal(len(directions), 2)
    assert_almost_equal(angular_similarity(directions, golden_directions), 2,
                        1)

    sb_dummies = sticks_and_ball_dummies(gtab)
    for sbd in sb_dummies:
        data, golden_directions = sb_dummies[sbd]
        odf = gq.fit(data).odf(sphere2)
        directions, values, indices = peak_directions(odf, sphere2, .35, 25)
        if len(directions) <= 3:
            assert_equal(len(directions), len(golden_directions))
        if len(directions) > 3:
            assert_equal(gfa(odf) < 0.1, True)
Exemple #7
0
def sim_data(bvals, bvecs, d=0.0015, S0=100, snr=None):

    descr = np.zeros(13).tolist()
    data = np.zeros((13, len(bvals)))

    descr[0] = ('isotropic', 0)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[0, 0, 0],
                             snr=snr)
    data[0] = S.copy()
    descr[1] = ('one fiber', 1)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(30, 0), (90, 0), (90, 90)],
                             fractions=[100, 0, 0],
                             snr=snr)
    data[1] = S.copy()
    descr[2] = ('two fibers', 2)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=snr)
    data[2] = S.copy()
    descr[3] = ('three fibers', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=snr)
    data[3] = S.copy()
    descr[4] = ('three fibers iso', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[23, 23, 23],
                             snr=snr)
    data[4] = S.copy()
    descr[5] = ('three fibers more iso', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[13, 13, 13],
                             snr=snr)
    data[5] = S.copy()
    descr[6] = ('three fibers one at 60', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (60, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=snr)
    data[6] = S.copy()
    descr[7] = ('three fibers one at 90,90 one smaller', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (60, 0), (90, 90)],
                             fractions=[33, 33, 23],
                             snr=snr)
    data[7] = S.copy()
    descr[8] = ('three fibers one at 60, one at 90 and one smaller', 3)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (60, 0), (90, 90)],
                             fractions=[33, 33, 13],
                             snr=snr)
    data[8] = S.copy()
    descr[9] = ('two fibers at 60 one smaller', 2)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (60, 0), (90, 90)],
                             fractions=[50, 30, 0],
                             snr=snr)
    data[9] = S.copy()
    descr[10] = ('two fibers one at 30', 2)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (45, 0)],
                             fractions=[50, 50],
                             snr=snr)
    data[10] = S.copy()
    descr[11] = ('one fiber one at 30 but small iso', 1)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(30, 0), (60, 0), (90, 90)],
                             fractions=[60, 0, 0],
                             snr=snr)
    data[11] = S.copy()
    descr[12] = ('one fiber one at 30 but even smaller iso', 1)
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d,
                             S0,
                             angles=[(0, 0), (60, 0), (90, 90)],
                             fractions=[30, 0, 0],
                             snr=snr)
    data[12] = S.copy()

    return data, descr
Exemple #8
0
def test_dsi():

    btable = np.loadtxt(get_data('dsi515btable'))
    bvals = btable[:, 0]
    bvecs = btable[:, 1:]
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    pdf0, odf0, peaks0 = standard_dsi_algorithm(S, bvals, bvecs)
    S2 = S.copy()
    S2 = S2.reshape(1, len(S))
    ds = DiffusionSpectrum(S2, bvals, bvecs)
    assert_almost_equal(np.sum(ds.pdf(S) - pdf0), 0)
    assert_almost_equal(np.sum(ds.odf(ds.pdf(S)) - odf0), 0)

    #compare gfa
    psi = odf0 / odf0.max()
    numer = len(psi) * np.sum((psi - np.mean(psi))**2)
    denom = (len(psi) - 1) * np.sum(psi**2)
    GFA = np.sqrt(numer / denom)
    assert_almost_equal(ds.gfa()[0], GFA)

    #compare indices
    #print ds.ind()
    #print peak_finding(odf0,odf_faces)
    #print peaks0
    data = np.zeros((3, 3, 3, 515))
    data[:, :, :] = S
    ds = DiffusionSpectrum(data, bvals, bvecs)

    ds2 = DiffusionSpectrum(data, bvals, bvecs, auto=False)
    r = np.sqrt(ds2.qtable[:, 0]**2 + ds2.qtable[:, 1]**2 +
                ds2.qtable[:, 2]**2)
    ds2.filter = .5 * np.cos(2 * np.pi * r / 32)
    ds2.fit()
    assert_almost_equal(np.sum(ds2.qa() - ds.qa()), 0)

    #1 fiber
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[100, 0, 0],
                             snr=None)
    ds = DiffusionSpectrum(S.reshape(1, len(S)), bvals, bvecs)
    QA = ds.qa()
    assert_equal(np.sum(QA > 0), 1)

    #2 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    ds = DiffusionSpectrum(S.reshape(1, len(S)), bvals, bvecs)
    QA = ds.qa()
    assert_equal(np.sum(QA > 0), 2)

    #3 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=None)
    ds = DiffusionSpectrum(S.reshape(1, len(S)), bvals, bvecs)
    QA = ds.qa()
    assert_equal(np.sum(QA > 0), 3)

    #isotropic
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[0, 0, 0],
                             snr=None)
    ds = DiffusionSpectrum(S.reshape(1, len(S)), bvals, bvecs)
    QA = ds.qa()
    assert_equal(np.sum(QA > 0), 0)
Exemple #9
0
def sim_data(bvals,bvecs,d=0.0015,S0=100,snr=None):
    
    data=np.zeros((14,len(bvals)))
    #isotropic
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(90,0),(90,90)], 
                          fractions=[0,0,0], snr=snr)
    data[0]=S.copy()
    #one fiber    
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(30, 0),(90,0),(90,90)], 
                          fractions=[100,0,0], snr=snr)
    data[1]=S.copy()
    #two fibers
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(90,0),(90,90)], 
                          fractions=[50,50,0], snr=snr)
    data[2]=S.copy()
    #three fibers
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(90,0),(90,90)], 
                          fractions=[33,33,33], snr=snr)
    data[3]=S.copy()
    #three fibers iso
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(90,0),(90,90)], 
                          fractions=[23,23,23], snr=snr)
    data[4]=S.copy()
    #three fibers more iso
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(90,0),(90,90)], 
                          fractions=[13,13,13], snr=snr)
    data[5]=S.copy()
    #three fibers one at 60
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(60,0),(90,90)], 
                          fractions=[33,33,33], snr=snr)
    data[6]=S.copy()    
    
    #three fibers one at 90,90 one smaller
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(60,0),(90,90)], 
                          fractions=[33,33,23], snr=snr)
    data[7]=S.copy()
    
    #three fibers one at 90,90 one even smaller
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(60,0),(90,90)], 
                          fractions=[33,33,13], snr=snr)
    data[8]=S.copy()
    
    #two fibers one at 60 one even smaller
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(60,0),(90,90)], 
                          fractions=[50,30,0], snr=snr)
    data[9]=S.copy()
    
    #two fibers one at 30 one at 60 even smaller
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(20,0),(90,90)], 
                          fractions=[50,50,0], snr=snr)
    data[10]=S.copy()
    
    #one fiber one at 30 but small
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(30, 0),(60,0),(90,90)], 
                          fractions=[60,0,0], snr=snr)
    data[11]=S.copy()
    
    #one fiber one at 30 but even smaller
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(0, 0),(60,0),(90,90)], 
                          fractions=[30,0,0], snr=snr)
    data[12]=S.copy()
    
    S,stics=SticksAndBall(bvals, bvecs, d, S0, 
                          angles=[(30, 0),(60,0),(90,90)], 
                          fractions=[0,0,0], snr=snr)
    data[13]=S.copy()
    
    return data
Exemple #10
0
def test_gqi():

    #load odf sphere
    vertices, faces = sphere_vf_from('symmetric724')
    edges = unique_edges(faces)
    half_vertices, half_edges, half_faces = reduce_antipodal(vertices, faces)

    #load bvals and gradients
    btable = np.loadtxt(get_data('dsi515btable'))
    bvals = btable[:, 0]
    bvecs = btable[:, 1:]
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    #pdf0,odf0,peaks0=standard_dsi_algorithm(S,bvals,bvecs)
    S2 = S.copy()
    S2 = S2.reshape(1, len(S))

    odf_sphere = (vertices, faces)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere)
    dsfit = ds.fit(S)
    assert_equal((dsfit.peak_values > 0).sum(), 3)

    #change thresholds
    ds.relative_peak_threshold = 0.5
    ds.angular_distance_threshold = 30
    dsfit = ds.fit(S)
    assert_equal((dsfit.peak_values > 0).sum(), 2)

    #1 fiber
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[100, 0, 0],
                             snr=None)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere)
    ds.relative_peak_threshold = 0.5
    ds.angular_distance_threshold = 20
    dsfit = ds.fit(S)
    QA = dsfit.qa
    #1/0
    assert_equal(np.sum(QA > 0), 1)

    #2 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere)
    ds.relative_peak_threshold = 0.5
    ds.angular_distance_threshold = 20
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 2)

    #3 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=None)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere)
    ds.relative_peak_threshold = 0.5
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 3)

    #isotropic
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[0, 0, 0],
                             snr=None)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere)
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 0)

    #3 fibers DSI2
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=None)
    ds = GeneralizedQSamplingModel(bvals, bvecs, odf_sphere, squared=True)
    ds.relative_peak_threshold = 0.5
    dsfit = ds.fit(S, gfa_thr=0.05)
    QA = dsfit.qa

    #3 fibers DSI2 with a 3D volume
    data = np.zeros((3, 3, 3, len(S)))
    data[..., :] = S.copy()
    dsfit = ds.fit(data, gfa_thr=0.05)
    #1/0
    assert_array_almost_equal(np.sum(dsfit.peak_values > 0, axis=-1),
                              3 * np.ones((3, 3, 3)))
Exemple #11
0
def test_dsi():

    #load odf sphere
    vertices, faces = sphere_vf_from('symmetric724')
    edges = unique_edges(faces)
    half_vertices, half_edges, half_faces = reduce_antipodal(vertices, faces)

    #load bvals and gradients
    btable = np.loadtxt(get_data('dsi515btable'))
    bvals = btable[:, 0]
    bvecs = btable[:, 1:]
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    #pdf0,odf0,peaks0=standard_dsi_algorithm(S,bvals,bvecs)
    S2 = S.copy()
    S2 = S2.reshape(1, len(S))

    odf_sphere = (vertices, faces)
    ds = DiffusionSpectrumModel(bvals, bvecs, odf_sphere)
    dsfit = ds.fit(S)
    assert_equal((dsfit.peak_values > 0).sum(), 3)

    #change thresholds
    ds.relative_peak_threshold = 0.5
    ds.angular_distance_threshold = 30
    dsfit = ds.fit(S)
    assert_equal((dsfit.peak_values > 0).sum(), 2)

    #assert_almost_equal(np.sum(ds.pdf(S)-pdf0),0)
    #assert_almost_equal(np.sum(ds.odf(ds.pdf(S))-odf0),0)

    assert_almost_equal(dsfit.gfa, np.array([0.5749720469955439]))

    #1 fiber
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[100, 0, 0],
                             snr=None)
    ds = DiffusionSpectrumModel(bvals, bvecs, odf_sphere)
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 1)

    #2 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[50, 50, 0],
                             snr=None)
    ds = DiffusionSpectrumModel(bvals, bvecs, odf_sphere)
    ds.relative_peak_threshold = 0.5
    ds.angular_distance_threshold = 20
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 2)

    #Give me 2 directions
    assert_equal(len(dsfit.get_directions()), 2)

    #3 fibers
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[33, 33, 33],
                             snr=None)
    ds = DiffusionSpectrumModel(bvals, bvecs, odf_sphere)
    ds.relative_peak_threshold = 0.5
    dsfit = ds.fit(S, return_odf=True)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 3)

    #Give me 3 directions
    assert_equal(len(dsfit.get_directions()), 3)

    #Recalculate the odf with a different sphere.

    vertices, faces = sphere_vf_from('symmetric724')

    odf1 = dsfit.odf()
    print len(odf1)

    odf2 = dsfit.odf((vertices, faces))
    print len(odf2)

    assert_array_almost_equal(odf1, odf2)

    #isotropic
    S, stics = SticksAndBall(bvals,
                             bvecs,
                             d=0.0015,
                             S0=100,
                             angles=[(0, 0), (90, 0), (90, 90)],
                             fractions=[0, 0, 0],
                             snr=None)
    ds = DiffusionSpectrumModel(bvals, bvecs, odf_sphere)
    dsfit = ds.fit(S)
    QA = dsfit.qa
    assert_equal(np.sum(QA > 0), 0)