コード例 #1
0
def test_calling_cartesian_laplacian_with_precomputed_matrices(
        radial_order=4, time_order=2, ut=2e-3, us=np.r_[1e-3, 2e-3, 3e-3]):
    ind_mat = qtdmri.qtdmri_index_matrix(radial_order, time_order)
    part4_reg_mat_tau = qtdmri.part4_reg_matrix_tau(ind_mat, 1.)
    part23_reg_mat_tau = qtdmri.part23_reg_matrix_tau(ind_mat, 1.)
    part1_reg_mat_tau = qtdmri.part1_reg_matrix_tau(ind_mat, 1.)
    S_mat, T_mat, U_mat = mapmri.mapmri_STU_reg_matrices(radial_order)

    laplacian_matrix_precomputed = qtdmri.qtdmri_laplacian_reg_matrix(
        ind_mat, us, ut, S_mat, T_mat, U_mat, part1_reg_mat_tau,
        part23_reg_mat_tau, part4_reg_mat_tau)
    laplacian_matrix_regular = qtdmri.qtdmri_laplacian_reg_matrix(
        ind_mat, us, ut)
    assert_array_almost_equal(laplacian_matrix_precomputed,
                              laplacian_matrix_regular)
コード例 #2
0
ファイル: test_qtdmri.py プロジェクト: StongeEtienne/dipy
def test_calling_cartesian_laplacian_with_precomputed_matrices(
        radial_order=4, time_order=2, ut=2e-3, us=np.r_[1e-3, 2e-3, 3e-3]):
    ind_mat = qtdmri.qtdmri_index_matrix(radial_order, time_order)
    part4_reg_mat_tau = qtdmri.part4_reg_matrix_tau(ind_mat, 1.)
    part23_reg_mat_tau = qtdmri.part23_reg_matrix_tau(ind_mat, 1.)
    part1_reg_mat_tau = qtdmri.part1_reg_matrix_tau(ind_mat, 1.)
    S_mat, T_mat, U_mat = mapmri.mapmri_STU_reg_matrices(radial_order)

    laplacian_matrix_precomputed = qtdmri.qtdmri_laplacian_reg_matrix(
        ind_mat, us, ut, S_mat, T_mat, U_mat,
        part1_reg_mat_tau, part23_reg_mat_tau, part4_reg_mat_tau
    )
    laplacian_matrix_regular = qtdmri.qtdmri_laplacian_reg_matrix(
        ind_mat, us, ut)
    assert_array_almost_equal(laplacian_matrix_precomputed,
                              laplacian_matrix_regular)
コード例 #3
0
ファイル: test_mapmri.py プロジェクト: theNaavik/dipy
def test_signal_fitting_equality_anisotropic_isotropic(radial_order=6):
    gtab = get_gtab_taiwan_dsi()
    l1, l2, l3 = [0.0015, 0.0003, 0.0003]
    S, _ = generate_signal_crossing(gtab, l1, l2, l3, angle2=60)
    gridsize = 17
    radius_max = 0.02
    r_points = mapmri.create_rspace(gridsize, radius_max)

    tenmodel = dti.TensorModel(gtab)
    evals = tenmodel.fit(S).evals
    tau = 1 / (4 * np.pi**2)

    # estimate isotropic scale factor
    u0 = mapmri.isotropic_scale_factor(evals * 2 * tau)
    mu = np.array([u0, u0, u0])

    qvals = np.sqrt(gtab.bvals / tau) / (2 * np.pi)
    q = gtab.bvecs * qvals[:, None]

    M_aniso = mapmri.mapmri_phi_matrix(radial_order, mu, q)
    K_aniso = mapmri.mapmri_psi_matrix(radial_order, mu, r_points)

    M_iso = mapmri.mapmri_isotropic_phi_matrix(radial_order, u0, q)
    K_iso = mapmri.mapmri_isotropic_psi_matrix(radial_order, u0, r_points)

    coef_aniso = np.dot(np.linalg.pinv(M_aniso), S)
    coef_iso = np.dot(np.linalg.pinv(M_iso), S)
    # test if anisotropic and isotropic implementation produce equal results
    # if the same isotropic scale factors are used
    s_fitted_aniso = np.dot(M_aniso, coef_aniso)
    s_fitted_iso = np.dot(M_iso, coef_iso)
    assert_array_almost_equal(s_fitted_aniso, s_fitted_iso)

    # the same test for the PDF
    pdf_fitted_aniso = np.dot(K_aniso, coef_aniso)
    pdf_fitted_iso = np.dot(K_iso, coef_iso)

    assert_array_almost_equal(pdf_fitted_aniso / pdf_fitted_iso,
                              np.ones_like(pdf_fitted_aniso), 3)

    # test if the implemented version also produces the same result
    mapm = MapmriModel(gtab,
                       radial_order=radial_order,
                       laplacian_regularization=False,
                       anisotropic_scaling=False)
    s_fitted_implemented_isotropic = mapm.fit(S).fitted_signal()

    # normalize non-implemented fitted signal with b0 value
    s_fitted_aniso_norm = s_fitted_aniso / s_fitted_aniso.max()

    assert_array_almost_equal(s_fitted_aniso_norm,
                              s_fitted_implemented_isotropic)

    # test if norm of signal laplacians are the same
    laplacian_matrix_iso = mapmri.mapmri_isotropic_laplacian_reg_matrix(
        radial_order, mu[0])
    ind_mat = mapmri.mapmri_index_matrix(radial_order)
    S_mat, T_mat, U_mat = mapmri.mapmri_STU_reg_matrices(radial_order)
    laplacian_matrix_aniso = mapmri.mapmri_laplacian_reg_matrix(
        ind_mat, mu, S_mat, T_mat, U_mat)

    norm_aniso = np.dot(coef_aniso, np.dot(coef_aniso, laplacian_matrix_aniso))
    norm_iso = np.dot(coef_iso, np.dot(coef_iso, laplacian_matrix_iso))
    assert_almost_equal(norm_iso, norm_aniso)
コード例 #4
0
ファイル: test_mapmri.py プロジェクト: gauvinalexandre/dipy
def test_signal_fitting_equality_anisotropic_isotropic(radial_order=6):
    gtab = get_gtab_taiwan_dsi()
    l1, l2, l3 = [0.0015, 0.0003, 0.0003]
    S, _ = generate_signal_crossing(gtab, l1, l2, l3, angle2=60)
    gridsize = 17
    radius_max = 0.02
    r_points = mapmri.create_rspace(gridsize, radius_max)

    tenmodel = dti.TensorModel(gtab)
    evals = tenmodel.fit(S).evals
    tau = 1 / (4 * np.pi ** 2)

    # estimate isotropic scale factor
    u0 = mapmri.isotropic_scale_factor(evals * 2 * tau)
    mu = np.array([u0, u0, u0])

    qvals = np.sqrt(gtab.bvals / tau) / (2 * np.pi)
    q = gtab.bvecs * qvals[:, None]

    M_aniso = mapmri.mapmri_phi_matrix(radial_order, mu, q)
    K_aniso = mapmri.mapmri_psi_matrix(radial_order, mu, r_points)

    M_iso = mapmri.mapmri_isotropic_phi_matrix(radial_order, u0, q)
    K_iso = mapmri.mapmri_isotropic_psi_matrix(radial_order, u0, r_points)

    coef_aniso = np.dot(np.linalg.pinv(M_aniso), S)
    coef_iso = np.dot(np.linalg.pinv(M_iso), S)
    # test if anisotropic and isotropic implementation produce equal results
    # if the same isotropic scale factors are used
    s_fitted_aniso = np.dot(M_aniso, coef_aniso)
    s_fitted_iso = np.dot(M_iso, coef_iso)
    assert_array_almost_equal(s_fitted_aniso, s_fitted_iso)

    # the same test for the PDF
    pdf_fitted_aniso = np.dot(K_aniso, coef_aniso)
    pdf_fitted_iso = np.dot(K_iso, coef_iso)

    assert_array_almost_equal(pdf_fitted_aniso / pdf_fitted_iso,
                              np.ones_like(pdf_fitted_aniso), 3)

    # test if the implemented version also produces the same result
    mapm = MapmriModel(gtab, radial_order=radial_order,
                       laplacian_regularization=False,
                       anisotropic_scaling=False)
    s_fitted_implemented_isotropic = mapm.fit(S).fitted_signal()

    # normalize non-implemented fitted signal with b0 value
    s_fitted_aniso_norm = s_fitted_aniso / s_fitted_aniso.max()

    assert_array_almost_equal(s_fitted_aniso_norm,
                              s_fitted_implemented_isotropic)

    # test if norm of signal laplacians are the same
    laplacian_matrix_iso = mapmri.mapmri_isotropic_laplacian_reg_matrix(
                           radial_order, mu[0])
    ind_mat = mapmri.mapmri_index_matrix(radial_order)
    S_mat, T_mat, U_mat = mapmri.mapmri_STU_reg_matrices(radial_order)
    laplacian_matrix_aniso = mapmri.mapmri_laplacian_reg_matrix(
        ind_mat, mu, S_mat, T_mat, U_mat)

    norm_aniso = np.dot(coef_aniso, np.dot(coef_aniso, laplacian_matrix_aniso))
    norm_iso = np.dot(coef_iso, np.dot(coef_iso, laplacian_matrix_iso))
    assert_almost_equal(norm_iso, norm_aniso)