コード例 #1
0
ファイル: test_soderman.py プロジェクト: weningerleon/dmipy
def test_RTAP_to_diameter_soderman(samples=1000):
    """This tests if the RTAP of the cylinder relates correctly to the diameter
    of the cylinder."""
    mu = [0, 0]
    lambda_par = 1.7
    diameter = 10e-6

    delta = np.tile(1e-10, samples)  # delta towards zero
    Delta = np.tile(1e10, samples)  # Delta towards infinity
    qvals_perp = np.linspace(0, 10e6, samples)
    n_perp = np.tile(np.r_[1., 0., 0.], (samples, 1))
    scheme = acquisition_scheme_from_qvalues(
        qvals_perp, n_perp, delta, Delta)

    soderman = cylinder_models.C2CylinderStejskalTannerApproximation(
        mu=mu, lambda_par=lambda_par, diameter=diameter)

    E_soderman = soderman(scheme)

    rtap_soderman = 2 * np.pi * np.trapz(
        E_soderman * qvals_perp, x=qvals_perp
    )

    diameter_soderman = 2 / np.sqrt(np.pi * rtap_soderman)

    assert_almost_equal(diameter_soderman, diameter, 7)
コード例 #2
0
def test_C2_watson_gamma_equals_gamma_watson():
    scheme = wu_minn_hcp_acquisition_scheme()

    cylinder = cylinder_models.C2CylinderStejskalTannerApproximation()
    watsoncyl = distribute_models.SD1WatsonDistributed([cylinder])

    gammawatsoncyl = distribute_models.DD1GammaDistributed(
        [watsoncyl],
        target_parameter='C2CylinderStejskalTannerApproximation_1_diameter')

    param_name = 'C2CylinderStejskalTannerApproximation_1_lambda_par'
    params1 = {
        'SD1WatsonDistributed_1_' + param_name: 1.7e-9,
        'DD1Gamma_1_alpha': 2.,
        'DD1Gamma_1_beta': 4e-6,
        'SD1WatsonDistributed_1_SD1Watson_1_odi': 0.4,
        'SD1WatsonDistributed_1_SD1Watson_1_mu': [0., 0.]
    }
    gammacyl = distribute_models.DD1GammaDistributed([cylinder])
    watsongammacyl = distribute_models.SD1WatsonDistributed([gammacyl])

    params2 = {
        'DD1GammaDistributed_1_' + param_name: 1.7e-9,
        'DD1GammaDistributed_1_DD1Gamma_1_alpha': 2.,
        'DD1GammaDistributed_1_DD1Gamma_1_beta': 4e-6,
        'SD1Watson_1_odi': 0.4,
        'SD1Watson_1_mu': [0., 0.]
    }

    assert_array_almost_equal(watsongammacyl(scheme, **params2),
                              gammawatsoncyl(scheme, **params1), 5)
コード例 #3
0
def test_all_models_dispersable():
    scheme = wu_minn_hcp_acquisition_scheme()

    dispersable_models = [
        [cylinder_models.C1Stick()],
        [cylinder_models.C2CylinderStejskalTannerApproximation()],
        [cylinder_models.C3CylinderCallaghanApproximation()],
        [cylinder_models.C4CylinderGaussianPhaseApproximation()],
        [gaussian_models.G1Ball(),
         gaussian_models.G2Zeppelin()], [gaussian_models.G3TemporalZeppelin()],
        [sphere_models.S1Dot(),
         gaussian_models.G2Zeppelin()],
        [
            sphere_models.S2SphereStejskalTannerApproximation(),
            gaussian_models.G2Zeppelin()
        ]
    ]

    spherical_distributions = [
        distribute_models.SD1WatsonDistributed,
        distribute_models.SD2BinghamDistributed
    ]

    for model in dispersable_models:
        for distribution in spherical_distributions:
            dist_mod = distribution(model)
            params = {}
            for param, card in dist_mod.parameter_cardinality.items():
                params[param] = np.random.rand(
                    card) * dist_mod.parameter_scales[param]
            assert_equal(isinstance(dist_mod(scheme, **params), np.ndarray),
                         True)
コード例 #4
0
def test_soderman_equivalent_to_callaghan_with_one_root_and_function(
        samples=100):
    mu = [0, 0]
    lambda_par = .1
    diameter = 10e-5
    diffusion_perpendicular = 1.7e-09

    delta = np.tile(1e-3, samples)  # delta towards zero
    Delta = np.tile(.15e-2, samples)  # Delta towards infinity
    qvals_perp = np.linspace(0, 1e5, samples)
    n_perp = np.tile(np.r_[1., 0., 0.], (samples, 1))
    scheme = acquisition_scheme_from_qvalues(qvals_perp, n_perp, delta, Delta)

    soderman = cylinder_models.C2CylinderStejskalTannerApproximation(
        mu=mu, lambda_par=lambda_par, diameter=diameter)
    callaghan = cylinder_models.C3CylinderCallaghanApproximation(
        number_of_roots=1,
        number_of_functions=1,
        mu=mu,
        lambda_par=lambda_par,
        diameter=diameter,
        diffusion_perpendicular=diffusion_perpendicular)

    E_soderman = soderman(scheme)
    E_callaghan = callaghan(scheme)
    assert_array_almost_equal(E_soderman, E_callaghan)
コード例 #5
0
def test_set_equal_param():
    cylinder = cylinder_models.C2CylinderStejskalTannerApproximation()
    watsoncyl = distribute_models.SD1WatsonDistributed([cylinder])
    p1 = 'C2CylinderStejskalTannerApproximation_1_lambda_par'
    p2 = 'C2CylinderStejskalTannerApproximation_1_diameter'
    watsoncyl.set_equal_parameter(p1, p2)

    isnone = False
    reset = watsoncyl.set_equal_parameter(p1, p2)
    if reset is None:
        isnone = True

    assert_equal(isnone, True)
コード例 #6
0
def test_raise_mixed_parameter_types():
    sphere = sphere_models.S2SphereStejskalTannerApproximation()
    cylinder = cylinder_models.C2CylinderStejskalTannerApproximation()
    assert_raises(AttributeError, distribute_models.DD1GammaDistributed,
                  [sphere, cylinder])
コード例 #7
0
from dmipy.data.saved_acquisition_schemes import (
    wu_minn_hcp_acquisition_scheme)
from dmipy.core.modeling_framework import (MultiCompartmentSphericalMeanModel)
from dmipy.core.acquisition_scheme import acquisition_scheme_from_bvalues
import numpy as np
from dmipy.utils.spherical_mean import (estimate_spherical_mean_shell)
from numpy.testing import assert_equal, assert_almost_equal
from dipy.data import get_sphere

sphere = get_sphere().subdivide()

scheme = wu_minn_hcp_acquisition_scheme()

models = [
    cylinder_models.C1Stick(),
    cylinder_models.C2CylinderStejskalTannerApproximation(),
    cylinder_models.C3CylinderCallaghanApproximation(),
    cylinder_models.C4CylinderGaussianPhaseApproximation(),
    gaussian_models.G1Ball(),
    gaussian_models.G2Zeppelin(),
    gaussian_models.G3TemporalZeppelin(),
    sphere_models.S2SphereStejskalTannerApproximation()
]

distributable_models = [
    cylinder_models.C2CylinderStejskalTannerApproximation(),
    cylinder_models.C3CylinderCallaghanApproximation(),
    cylinder_models.C4CylinderGaussianPhaseApproximation(),
]