Example #1
0
def snr_ls_fit(data, bvals, mask, unique_b):
    """
    Fits a first order least squares solution to the SNR data versus b value
    
    Parameters
    ----------
    data: 4 dimensional array
        Diffusion MRI data
    bvals: 1 dimensional array
        All b values
    mask: 3 dimensional array
        Brain mask of the data
    unique_b: 1 dimensional array
        Array of all the unique b values found
        
    Returns
    -------
    ls_fit_bsnr: 1 dimensional array
        An array with the results from the least squares fit to the SNR data
    """
    if 0 in unique_b:
        unique_b = sort(unique_b)[1:]
        
    data, mask = obtain_data(data, mask)
    
    all_bsnr = list()         
    for bi in np.arange(len(unique_b)):
        all_bsnr.append(snr.b_snr(data, bvals, unique_b[bi], mask)[np.where(mask)])
    
    ls_fit_bsnr = ls_fit_b(all_bsnr, unique_b)
    
    return ls_fit_bsnr
Example #2
0
def test_b_snr():
    
    idx_mask_t = (np.array([0, 0, 1, 1]), np.array([0, 1, 0, 1]), np.array([1, 1, 1, 1]))
    test_data = data_t[idx_mask_t]
    
    snr_unbiased_t = snr.calculate_snr(test_data[:,np.array([0,1,2])],test_data[:,np.array([3,6])])
    bsnr_t = np.zeros([2,2,2])
    
    bsnr_t[idx_mask_t] = np.squeeze(snr_unbiased_t)
    bsnr_t[np.where(~np.isfinite(bsnr_t))] = 0
    
    npt.assert_equal(bsnr_t, snr.b_snr(data_t, bvals_t, 2, mask_t))
Example #3
0
def scat_prop_snr(log_prop, data, bvals, mask):
    """
    Displays a scatter density plot of SNR versus the slope of the desired property
    
    Parameters
    ----------
    log_prop: list
        List of all the log of the desired property values
    data: 4 dimensional array
        Diffusion MRI data
    bvals: 1 dimensional array
        All b values
    mask: 3 dimensional array
        Brain mask of the data
    """    
    bval_list, bval_ind, unique_b, _ = ozu.separate_bvals(bvals)
    
    if 0 in unique_b:
        unique_b = unique_b[1:]
    
    bsnr = snr.b_snr(data, bvals, unique_b[0], mask)[np.where(mask)]
    ls_fit_prop = ls_fit_b(log_prop, unique_b)
    
    mpl.scatter_density(bsnr, ls_fit_prop[0,:])