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)
def test_C3_watson_gamma_equals_gamma_watson(): scheme = wu_minn_hcp_acquisition_scheme() cylinder = cylinder_models.C3CylinderCallaghanApproximation() watsoncyl = distribute_models.SD1WatsonDistributed([cylinder]) gammawatsoncyl = distribute_models.DD1GammaDistributed( [watsoncyl], target_parameter='C3CylinderCallaghanApproximation_1_diameter') params1 = { 'SD1WatsonDistributed_1_C3CylinderCallaghanApproximation_1_lambda_par': 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_C3CylinderCallaghanApproximation_1_lambda_par': 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)
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.C2CylinderSodermanApproximation( 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)
def test_callaghan_profile_narrow_pulse_not_restricted(samples=100): # in short diffusion times the model should approach a Gaussian # profile as np.exp(-b * lambda_perp) mu = [0, 0] lambda_par = .1e-9 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, 3e5, samples) n_perp = np.tile(np.r_[1., 0., 0.], (samples, 1)) scheme = acquisition_scheme_from_qvalues(qvals_perp, n_perp, delta, Delta) # needed to increase the number of roots and functions to approximate # the gaussian function. callaghan = cylinder_models.C3CylinderCallaghanApproximation( number_of_roots=20, number_of_functions=50, mu=mu, lambda_par=lambda_par, diameter=diameter, diffusion_perpendicular=diffusion_perpendicular) E_callaghan = callaghan(scheme) E_free_diffusion = np.exp(-scheme.bvalues * diffusion_perpendicular) assert_equal(np.max(np.abs(E_callaghan - E_free_diffusion)) < 0.01, True)
def test_RTAP_to_diameter_callaghan(samples=10000): 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) callaghan = cylinder_models.C3CylinderCallaghanApproximation( mu=mu, lambda_par=lambda_par, diameter=diameter) E_callaghan = callaghan(scheme) rtap_callaghan = 2 * np.pi * np.trapz(E_callaghan * qvals_perp, x=qvals_perp) diameter_callaghan = 2 / np.sqrt(np.pi * rtap_callaghan) assert_almost_equal(diameter_callaghan, diameter, 7)
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.C2CylinderSodermanApproximation(), cylinder_models.C3CylinderCallaghanApproximation(), cylinder_models.C4CylinderGaussianPhaseApproximation(), gaussian_models.G1Ball(), gaussian_models.G2Zeppelin(), gaussian_models.G3RestrictedZeppelin(), sphere_models.S2SphereSodermanApproximation() ] distributable_models = [ cylinder_models.C2CylinderSodermanApproximation(), cylinder_models.C3CylinderCallaghanApproximation(), cylinder_models.C4CylinderGaussianPhaseApproximation(), ] def test_model_spherical_mean_analytic_vs_numerical(bvalue=1e9,