Example #1
0
def test_SphericalHarmonicsModel():
    """
    Test the estimation of SH models.
    """

    model_coeffs = ni.load(data_path + 'CSD10.nii.gz').get_data()

    mask = np.zeros(model_coeffs.shape[:3])
    # Do this in only one voxel:
    mask[40, 40, 40] = 1
    response_file = (data_path +
                     '0009_01_DWI_2mm150dir_2x_b1000_aligned_trilin_ER.mif')

    for response in [response_file, None]:
        SHM1 = SphericalHarmonicsModel(data_path + 'dwi.nii.gz',
                                       data_path + 'dwi.bvecs',
                                       data_path + 'dwi.bvals',
                                       model_coeffs,
                                       response_file=response,
                                       mask=mask)

        # Can also provide the input as a string:
        model_coeffs = data_path + 'CSD10.nii.gz'

        SHM2 = SphericalHarmonicsModel(data_path + 'dwi.nii.gz',
                                       data_path + 'dwi.bvecs',
                                       data_path + 'dwi.bvals',
                                       model_coeffs,
                                       response_file=response,
                                       mask=mask)

        # Smoke testing:
        SHM1.fit
        SHM1.odf_peaks
        SHM1.crossing_index
        pdd_reliab = ma.pdd_reliability(SHM1, SHM2)
        npt.assert_almost_equal(pdd_reliab[40, 40, 40], 0)

    # Check error-handling
    # In this one, the input is not a proper array (why I am testing this
    # here?):
    npt.assert_raises(ValueError, SphericalHarmonicsModel, [1, 2, 3],
                      data_path + 'dwi.bvecs', data_path + 'dwi.bvals',
                      model_coeffs, None, None, None, response_file)

    # In this one, both a response function coefficients file and AD/RD for the
    # calculation of a tensor are provided:
    npt.assert_raises(ValueError, SphericalHarmonicsModel,
                      data_path + 'dwi.nii.gz', data_path + 'dwi.bvecs',
                      data_path + 'dwi.bvals', model_coeffs, None, 1.5, 0.5,
                      response_file)
Example #2
0
def tensor_reliability(SD_1, SD_2, wm_mask):
    """ 
    given two SD models, calculate the reliability of the PDD of the derived
    tensor models

    Parameters
    ----------

    SD_1, SD_2 : SparseDeconvolutionModel class instances

    wm_mask : ndarray

    Returns
    -------

    pdd_rel : ndarray
       The angular difference between the PDD of the two tensor models fit to
       the predicted data from each of the SD models.
    
    """
    pred1 = np.concatenate([SD_1.S0[..., np.newaxis], SD_1.fit], -1)
    pred2 = np.concatenate([SD_2.S0[..., np.newaxis], SD_2.fit], -1)

    new_bvecs1 = np.concatenate(
        [np.array([[0, 0, 0]]).T, SD_1.bvecs[:, SD_1.b_idx]], -1)
    new_bvecs2 = np.concatenate(
        [np.array([[0, 0, 0]]).T, SD_2.bvecs[:, SD_2.b_idx]], -1)

    # Freely assume that the bvals are the same
    new_bvals = np.hstack([0, SD_1.bvals[:, SD_1.b_idx]])

    #
    TM1 = dti.TensorModel(pred1,
                          new_bvecs1,
                          new_bvals,
                          mask=wm_mask,
                          params_file="temp")
    TM2 = dti.TensorModel(pred2,
                          new_bvecs2,
                          new_bvals,
                          mask=wm_mask,
                          params_file="temp")

    pdd_rel = oza.pdd_reliability(TM1, TM2)
    return pdd_rel
def tensor_reliability(SD_1, SD_2, wm_mask):
    """ 
    given two SD models, calculate the reliability of the PDD of the derived
    tensor models

    Parameters
    ----------

    SD_1, SD_2 : SparseDeconvolutionModel class instances

    wm_mask : ndarray

    Returns
    -------

    pdd_rel : ndarray
       The angular difference between the PDD of the two tensor models fit to
       the predicted data from each of the SD models.
    
    """
    pred1 = np.concatenate([SD_1.S0[...,np.newaxis], SD_1.fit], -1)
    pred2 = np.concatenate([SD_2.S0[...,np.newaxis], SD_2.fit], -1)
    
    new_bvecs1 = np.concatenate([np.array([[0,0,0]]).T,
                                 SD_1.bvecs[:, SD_1.b_idx]], -1)
    new_bvecs2 = np.concatenate([np.array([[0,0,0]]).T,
                                 SD_2.bvecs[:, SD_2.b_idx]], -1)
    
    # Freely assume that the bvals are the same 
    new_bvals = np.hstack([0, SD_1.bvals[:,SD_1.b_idx]])

    # 
    TM1 = dti.TensorModel(pred1, new_bvecs1, new_bvals,
                          mask=wm_mask, params_file="temp")
    TM2 = dti.TensorModel(pred2, new_bvecs2, new_bvals, mask=wm_mask,
                          params_file="temp")

    pdd_rel = oza.pdd_reliability(TM1, TM2)
    return pdd_rel
Example #4
0
def test_SphericalHarmonicsModel():
    """
    Test the estimation of SH models.
    """

    model_coeffs = ni.load(data_path + "CSD10.nii.gz").get_data()

    mask = np.zeros(model_coeffs.shape[:3])
    # Do this in only one voxel:
    mask[40, 40, 40] = 1
    response_file = data_path + "0009_01_DWI_2mm150dir_2x_b1000_aligned_trilin_ER.mif"

    for response in [response_file, None]:
        SHM1 = SphericalHarmonicsModel(
            data_path + "dwi.nii.gz",
            data_path + "dwi.bvecs",
            data_path + "dwi.bvals",
            model_coeffs,
            response_file=response,
            mask=mask,
        )

        # Can also provide the input as a string:
        model_coeffs = data_path + "CSD10.nii.gz"

        SHM2 = SphericalHarmonicsModel(
            data_path + "dwi.nii.gz",
            data_path + "dwi.bvecs",
            data_path + "dwi.bvals",
            model_coeffs,
            response_file=response,
            mask=mask,
        )

        # Smoke testing:
        SHM1.fit
        SHM1.odf_peaks
        SHM1.crossing_index
        pdd_reliab = ma.pdd_reliability(SHM1, SHM2)
        npt.assert_almost_equal(pdd_reliab[40, 40, 40], 0)

    # Check error-handling
    # In this one, the input is not a proper array (why I am testing this
    # here?):
    npt.assert_raises(
        ValueError,
        SphericalHarmonicsModel,
        [1, 2, 3],
        data_path + "dwi.bvecs",
        data_path + "dwi.bvals",
        model_coeffs,
        None,
        None,
        None,
        response_file,
    )

    # In this one, both a response function coefficients file and AD/RD for the
    # calculation of a tensor are provided:
    npt.assert_raises(
        ValueError,
        SphericalHarmonicsModel,
        data_path + "dwi.nii.gz",
        data_path + "dwi.bvecs",
        data_path + "dwi.bvals",
        model_coeffs,
        None,
        1.5,
        0.5,
        response_file,
    )
Example #5
0
def test_pdd_reliability():
    """
    Test the calculation of model reliability by PDD
    """
    reliab = ozm.pdd_reliability(TM1, TM2)
    npt.assert_equal(reliab, np.zeros(reliab.shape))