def test_coordinate_transformation():
    # test for a vector of size 3
    cartesian_vector = np.random.rand(3)
    spherical_vector = utils.cart2sphere(cartesian_vector)
    recovered_cartesian_vector = utils.sphere2cart(spherical_vector)
    assert_almost_equal(cartesian_vector, recovered_cartesian_vector)

    # test for a vector of size N x 3
    cartesian_vector = np.random.rand(10, 3)
    spherical_vector = utils.cart2sphere(cartesian_vector)
    recovered_cartesian_vector = utils.sphere2cart(spherical_vector)
    assert_almost_equal(cartesian_vector, recovered_cartesian_vector)
Example #2
0
def test_orienting_stick():
    # test for orienting the axis of the Stick along mu
    # first test to see if Estick equals Gaussian with lambda_par along mu
    random_n_mu_vector = np.random.rand(2) * np.pi
    n = utils.sphere2cart(np.r_[1, random_n_mu_vector])
    random_bval = np.r_[np.random.rand() * 1e9]
    random_lambda_par = np.random.rand() * 3e-9

    scheme = acquisition_scheme_from_bvalues(
        random_bval, np.atleast_2d(n), delta, Delta)
    # initialize model
    stick = cylinder_models.C1Stick(mu=random_n_mu_vector,
                                    lambda_par=random_lambda_par)

    # test if parallel direction attenuation as a Gaussian
    E_stick = stick(scheme)
    E_check = np.exp(-random_bval * (random_lambda_par))
    assert_almost_equal(E_stick, E_check)

    # test if perpendicular direction does not attenuate
    n_perp = perpendicular_vector(n)
    scheme = acquisition_scheme_from_bvalues(
        random_bval, np.atleast_2d(n_perp), delta, Delta)
    E_stick_perp = stick(scheme)
    assert_almost_equal(E_stick_perp, 1.)
Example #3
0
def test_watson_kappa():
    # test for Wn(k2) > Wn(k1) when k2>k1 along mu
    random_mu = np.random.rand(2)
    random_mu_cart = utils.sphere2cart(np.r_[1., random_mu])
    odi1 = .8
    odi2 = .6
    watson = distributions.SD1Watson(mu=random_mu)
    Wn1 = watson(n=random_mu_cart, odi=odi1)
    Wn2 = watson(n=random_mu_cart, odi=odi2)
    assert_equal(Wn2 > Wn1, True)
Example #4
0
def test_bingham_equal_to_watson(beta_fraction=0):
    # test if bingham with beta=0 equals watson distribution
    mu_ = np.random.rand(2)
    n_cart = utils.sphere2cart(np.r_[1., mu_])
    psi_ = np.random.rand() * np.pi
    odi_ = np.random.rand()
    bingham = distributions.SD2Bingham(mu=mu_,
                                       psi=psi_,
                                       odi=odi_,
                                       beta_fraction=beta_fraction)
    watson = distributions.SD1Watson(mu=mu_, odi=odi_)
    Bn = bingham(n=n_cart)
    Wn = watson(n=n_cart)
    assert_almost_equal(Bn, Wn, 3)
Example #5
0
def test_orienting_zeppelin():
    # test for orienting the axis of the Zeppelin along mu
    # first test to see if Ezeppelin equals Gaussian with lambda_par along mu
    random_mu = np.random.rand(2) * np.pi
    n = np.array([utils.sphere2cart(np.r_[1, random_mu])])
    random_bval = np.r_[np.random.rand() * 1e9]
    scheme = acquisition_scheme_from_bvalues(random_bval, n, delta, Delta)
    random_lambda_par = np.random.rand() * 3 * 1e-9
    random_lambda_perp = random_lambda_par / 2.

    zeppelin = gaussian_models.G2Zeppelin(
        mu=random_mu, lambda_par=random_lambda_par,
        lambda_perp=random_lambda_perp)
    E_zep_par = zeppelin(scheme)
    E_check_par = np.exp(-random_bval * random_lambda_par)
    assert_almost_equal(E_zep_par, E_check_par)

    # second test to see if Ezeppelin equals Gaussian with lambda_perp
    # perpendicular to mu
    n_perp = np.array([perpendicular_vector(n[0])])
    scheme = acquisition_scheme_from_bvalues(random_bval, n_perp, delta, Delta)
    E_zep_perp = zeppelin(scheme)
    E_check_perp = np.exp(-random_bval * random_lambda_perp)
    assert_almost_equal(E_zep_perp, E_check_perp)