algorithm/vol_tools.py
def calc_dvars(infile, maskfile=None):
    """
    Calculate DVARS from NIFTI Images
    ----------------------------------
    infile [str]: input volume time series.

    Return: DVARS
    """
    imgdata = nib.load(infile).get_data()
    if maskfile is not None:
        maskdata = nib.load(maskfile).get_data()
    else:
        maskdata = np.ones_like(imgdata[...,0])
    maskvox = np.where(maskdata>0)
    nonmaskvox = np.where(maskdata==0)
    maskmean = np.zeros(imgdata.shape[3])
    maskmad = np.zeros(imgdata.shape[3])
    for t in range(imgdata.shape[3]):
        tmp = imgdata[...,t]
        tmp_brain = tmp[maskvox]
        maskmad[t] = _MAD(tmp_brain)
        maskmean[t] = np.mean(tmp_brain)
    scaledmean = (maskmean - np.mean(maskmean))/np.std(maskmean)
    mean_running_diff = np.zeros(maskmad.shape)
    mean_running_diff = 10*(maskmean[1:]-maskmean[:-1])/((maskmean[1:]+maskmean[:-1])/2.0)
    DVARS = [0]
    DVARS_tmp = list(np.sqrt(mean_running_diff**2)*100.0)
    DVARS.extend(DVARS_tmp)
    return np.array(DVARS)

    Calculate DVARS from NIFTI Images
    ----------------------------------
    infile [str]: input volume time series.

    Return: DVARS
    
Calculate DVARS from NIFTI Images
infile [str]: input volume time series.

DVARS
Calculate DVARS from NIFTI Images infile [ str ] : input volume time series . DVARS
def calc_dvars(infile, maskfile=None):
    imgdata = nib.load(infile).get_data()
    if maskfile is not None:
        maskdata = nib.load(maskfile).get_data()
    else:
        maskdata = np.ones_like(imgdata[...,0])
    maskvox = np.where(maskdata>0)
    nonmaskvox = np.where(maskdata==0)
    maskmean = np.zeros(imgdata.shape[3])
    maskmad = np.zeros(imgdata.shape[3])
    for t in range(imgdata.shape[3]):
        tmp = imgdata[...,t]
        tmp_brain = tmp[maskvox]
        maskmad[t] = _MAD(tmp_brain)
        maskmean[t] = np.mean(tmp_brain)
    scaledmean = (maskmean - np.mean(maskmean))/np.std(maskmean)
    mean_running_diff = np.zeros(maskmad.shape)
    mean_running_diff = 10*(maskmean[1:]-maskmean[:-1])/((maskmean[1:]+maskmean[:-1])/2.0)
    DVARS = [0]
    DVARS_tmp = list(np.sqrt(mean_running_diff**2)*100.0)
    DVARS.extend(DVARS_tmp)
    return np.array(DVARS)
def calc_dvars ( infile , maskfile = None ) : imgdata = nib . load ( infile ) . get_data ( ) if maskfile is not None : maskdata = nib . load ( maskfile ) . get_data ( ) else : maskdata = np . ones_like ( imgdata [ ... , 0 ] ) maskvox = np . where ( maskdata > 0 ) nonmaskvox = np . where ( maskdata == 0 ) maskmean = np . zeros ( imgdata . shape [ 3 ] ) maskmad = np . zeros ( imgdata . shape [ 3 ] ) for t in range ( imgdata . shape [ 3 ] ) : tmp = imgdata [ ... , t ] tmp_brain = tmp [ maskvox ] maskmad [ t ] = _MAD ( tmp_brain ) maskmean [ t ] = np . mean ( tmp_brain ) scaledmean = ( maskmean - np . mean ( maskmean ) ) / np . std ( maskmean ) mean_running_diff = np . zeros ( maskmad . shape ) mean_running_diff = 10 * ( maskmean [ 1 : ] - maskmean [ : - 1 ] ) / ( ( maskmean [ 1 : ] + maskmean [ : - 1 ] ) / 2.0 ) DVARS = [ 0 ] DVARS_tmp = list ( np . sqrt ( mean_running_diff ** 2 ) * 100.0 ) DVARS . extend ( DVARS_tmp ) return np . array ( DVARS )
Calculate DVARS from NIFTI Images
infile [str]: input volume time series.
Calculate DVARS from NIFTI Images infile [ str ] : input volume time series .
"""
    Calculate DVARS from NIFTI Images
    ----------------------------------
    infile [str]: input volume time series.

    Return: DVARS
    """
infile
maskfile