def compute_dti(fname_in, fname_bvals, fname_bvecs, prefix, method, file_mask):
    # Open file.
    from msct_image import Image
    nii = Image(fname_in)
    data = nii.data
    print('data.shape (%d, %d, %d, %d)' % data.shape)

    # open bvecs/bvals
    from dipy.io import read_bvals_bvecs
    bvals, bvecs = read_bvals_bvecs(fname_bvals, fname_bvecs)
    from dipy.core.gradients import gradient_table
    gtab = gradient_table(bvals, bvecs)

    # mask and crop the data. This is a quick way to avoid calculating Tensors on the background of the image.
    if not file_mask == '':
        printv('Open mask file...', param.verbose)
        # open mask file
        nii_mask = Image(file_mask)
        mask = nii_mask.data

    # fit tensor model
    printv('Computing tensor using "'+method+'" method...', param.verbose)
    import dipy.reconst.dti as dti
    if method == 'standard':
        tenmodel = dti.TensorModel(gtab)
        if file_mask == '':
            tenfit = tenmodel.fit(data)
        else:
            tenfit = tenmodel.fit(data, mask)
    elif method == 'restore':
        import dipy.denoise.noise_estimate as ne
        sigma = ne.estimate_sigma(data)
        dti_restore = dti.TensorModel(gtab, fit_method='RESTORE', sigma=sigma)
        if file_mask == '':
            tenfit = dti_restore.fit(data)
        else:
            tenfit = dti_restore.fit(data, mask)

    # Compute metrics
    printv('Computing metrics...', param.verbose)
    # FA
    from dipy.reconst.dti import fractional_anisotropy
    nii.data = fractional_anisotropy(tenfit.evals)
    nii.setFileName(prefix+'FA.nii.gz')
    nii.save('float32')
    # MD
    from dipy.reconst.dti import mean_diffusivity
    nii.data = mean_diffusivity(tenfit.evals)
    nii.setFileName(prefix+'MD.nii.gz')
    nii.save('float32')
    # RD
    from dipy.reconst.dti import radial_diffusivity
    nii.data = radial_diffusivity(tenfit.evals)
    nii.setFileName(prefix+'RD.nii.gz')
    nii.save('float32')
    # AD
    from dipy.reconst.dti import axial_diffusivity
    nii.data = axial_diffusivity(tenfit.evals)
    nii.setFileName(prefix+'AD.nii.gz')
    nii.save('float32')

    return True


# # Get bvecs
# # ==========================================================================================
# def get_bvecs(fname):
#     """
#     Read bvecs file and output array
#     :param fname: bvecs file
#     :return: (nx3) array
#     """
#     text_file = open(fname, 'r')
#     list_bvecs = text_file.readlines()
#     text_file.close()
#     # parse txt file and transform to array
#     from numpy import array
#     bvecs = array([[float(j.strip("\n")) for j in list_bvecs[i].split(" ")] for i in range(len(list_bvecs))])
#     # make sure one dimension is "3"
#     if not 3 in bvecs.shape:
#         printv('ERROR: bvecs should be text file with 3 lines (or columns).', 1, 'error')
#     return bvecs
#


# START PROGRAM
# ==========================================================================================
Compares a received view size with this sides' view size.... if they don't match a resync event is
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/sct_dmri_compute_dti.py/compute_dti--crossover with--dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/sub_collab/peer/basic.py/BasicPeer.checkViewSyncState