algorithm/vol_tools.py
def data_preprocess(data, outlier_method = None, outlier_range = [-3,3], mergehemi = None):
    """
    Pipline to merge hemisphere and do outlier removed.
    ---------------------------------------------------------
    Parameters:
        data: raw data. Notes that when the dimension is 1, data means regions. When the dimension is 2, data is the form of nsubj*regions. When the dimension is 3, data is the form of timeseries*regions*nsubj.
        outlier_method: 'iqr' or 'std' or 'abs'. By default is None
        outlier_range: outlier standard threshold
        mergehemi: merge hemisphere or not. By default is False. Input bool expression to indicate left or right factor. True means left hemisphere, False means right hemisphere
    Output:
        n_removed: outlier_numbers
        residue_data: output data

    Example:
        >>> a = np.array([[1,2,3,4],[5,6,7,8]])
        >>> b = array([True,True,False,False], dtype=bool)
        >>> n_removed, residue_data = dataprocess(a,mergehemi = b)
    """
    if mergehemi is not None:
        if not len(mergehemi[mergehemi]) == len(mergehemi[~mergehemi]):
            raise Exception("length of left data should equal to right data")

    if data.ndim == 1:
        data = data[np.newaxis,...]
    if data.ndim == 2:
        data = data[...,np.newaxis]
    if data.ndim != 3:
        raise Exception('data dimensions should be 2 or 3!')
    if mergehemi is None:
        data_comb = data
        n_removed = np.empty((data.shape[1], data.shape[2]))
        data_removed = np.zeros_like(data)
        for i in range(data.shape[1]):
            for j in range(data.shape[2]):
                n_removed[i,j], data_removed[:,i,j] = tools.removeoutlier(data_comb[:,i,j], meth = outlier_method, thr = outlier_range)
    else:
        if not mergehemi.dtype == np.bool:
            mergehemi = mergehemi.astype('bool')
        n_removed = np.empty((data.shape[1]/2, data.shape[2]))
        data_comb = np.empty((data.shape[0], data.shape[1]/2, data.shape[2]))
        data_removed = np.empty((data.shape[0], data.shape[1]/2, data.shape[2]))
        for i in range(data.shape[0]):
            for j in range(data.shape[2]):
                data_comb[i,:,j] = tools.hemi_merge(data[i,mergehemi,j], data[i,~mergehemi,j])
        for i in range(data.shape[1]/2):
            for j in range(data.shape[2]):
                n_removed[i,j], data_removed[:,i,j] = tools.removeoutlier(data_comb[:,i,j], meth = outlier_method, thr = outlier_range)
    if n_removed.shape[-1] == 1:
        n_removed = n_removed[...,0]
    if data_removed.shape[-1] == 1:
        data_removed = data_removed[...,0]
    return n_removed, data_removed

    Pipline to merge hemisphere and do outlier removed.
    ---------------------------------------------------------
    Parameters:
        data: raw data. Notes that when the dimension is 1, data means regions. When the dimension is 2, data is the form of nsubj*regions. When the dimension is 3, data is the form of timeseries*regions*nsubj.
        outlier_method: 'iqr' or 'std' or 'abs'. By default is None
        outlier_range: outlier standard threshold
        mergehemi: merge hemisphere or not. By default is False. Input bool expression to indicate left or right factor. True means left hemisphere, False means right hemisphere
    Output:
        n_removed: outlier_numbers
        residue_data: output data

    Example:
        >>> a = np.array([[1,2,3,4],[5,6,7,8]])
        >>> b = array([True,True,False,False], dtype=bool)
        >>> n_removed, residue_data = dataprocess(a,mergehemi = b)
    
Pipline to merge hemisphere and do outlier removed.
Pipline to merge hemisphere and do outlier removed .
def data_preprocess(data, outlier_method = None, outlier_range = [-3,3], mergehemi = None):
    if mergehemi is not None:
        if not len(mergehemi[mergehemi]) == len(mergehemi[~mergehemi]):
            raise Exception("length of left data should equal to right data")
    if data.ndim == 1:
        data = data[np.newaxis,...]
    if data.ndim == 2:
        data = data[...,np.newaxis]
    if data.ndim != 3:
        raise Exception('data dimensions should be 2 or 3!')
    if mergehemi is None:
        data_comb = data
        n_removed = np.empty((data.shape[1], data.shape[2]))
        data_removed = np.zeros_like(data)
        for i in range(data.shape[1]):
            for j in range(data.shape[2]):
                n_removed[i,j], data_removed[:,i,j] = tools.removeoutlier(data_comb[:,i,j], meth = outlier_method, thr = outlier_range)
    else:
        if not mergehemi.dtype == np.bool:
            mergehemi = mergehemi.astype('bool')
        n_removed = np.empty((data.shape[1]/2, data.shape[2]))
        data_comb = np.empty((data.shape[0], data.shape[1]/2, data.shape[2]))
        data_removed = np.empty((data.shape[0], data.shape[1]/2, data.shape[2]))
        for i in range(data.shape[0]):
            for j in range(data.shape[2]):
                data_comb[i,:,j] = tools.hemi_merge(data[i,mergehemi,j], data[i,~mergehemi,j])
        for i in range(data.shape[1]/2):
            for j in range(data.shape[2]):
                n_removed[i,j], data_removed[:,i,j] = tools.removeoutlier(data_comb[:,i,j], meth = outlier_method, thr = outlier_range)
    if n_removed.shape[-1] == 1:
        n_removed = n_removed[...,0]
    if data_removed.shape[-1] == 1:
        data_removed = data_removed[...,0]
    return n_removed, data_removed
def data_preprocess ( data , outlier_method = None , outlier_range = [ - 3 , 3 ] , mergehemi = None ) : if mergehemi is not None : if not len ( mergehemi [ mergehemi ] ) == len ( mergehemi [ ~ mergehemi ] ) : raise Exception ( "length of left data should equal to right data" ) if data . ndim == 1 : data = data [ np . newaxis , ... ] if data . ndim == 2 : data = data [ ... , np . newaxis ] if data . ndim != 3 : raise Exception ( 'data dimensions should be 2 or 3!' ) if mergehemi is None : data_comb = data n_removed = np . empty ( ( data . shape [ 1 ] , data . shape [ 2 ] ) ) data_removed = np . zeros_like ( data ) for i in range ( data . shape [ 1 ] ) : for j in range ( data . shape [ 2 ] ) : n_removed [ i , j ] , data_removed [ : , i , j ] = tools . removeoutlier ( data_comb [ : , i , j ] , meth = outlier_method , thr = outlier_range ) else : if not mergehemi . dtype == np . bool : mergehemi = mergehemi . astype ( 'bool' ) n_removed = np . empty ( ( data . shape [ 1 ] / 2 , data . shape [ 2 ] ) ) data_comb = np . empty ( ( data . shape [ 0 ] , data . shape [ 1 ] / 2 , data . shape [ 2 ] ) ) data_removed = np . empty ( ( data . shape [ 0 ] , data . shape [ 1 ] / 2 , data . shape [ 2 ] ) ) for i in range ( data . shape [ 0 ] ) : for j in range ( data . shape [ 2 ] ) : data_comb [ i , : , j ] = tools . hemi_merge ( data [ i , mergehemi , j ] , data [ i , ~ mergehemi , j ] ) for i in range ( data . shape [ 1 ] / 2 ) : for j in range ( data . shape [ 2 ] ) : n_removed [ i , j ] , data_removed [ : , i , j ] = tools . removeoutlier ( data_comb [ : , i , j ] , meth = outlier_method , thr = outlier_range ) if n_removed . shape [ - 1 ] == 1 : n_removed = n_removed [ ... , 0 ] if data_removed . shape [ - 1 ] == 1 : data_removed = data_removed [ ... , 0 ] return n_removed , data_removed
Pipline to merge hemisphere and do outlier removed.
Pipline to merge hemisphere and do outlier removed .
"""
    Pipline to merge hemisphere and do outlier removed.
    ---------------------------------------------------------
    Parameters:
        data: raw data. Notes that when the dimension is 1, data means regions. When the dimension is 2, data is the form of nsubj*regions. When the dimension is 3, data is the form of timeseries*regions*nsubj.
        outlier_method: 'iqr' or 'std' or 'abs'. By default is None
        outlier_range: outlier standard threshold
        mergehemi: merge hemisphere or not. By default is False. Input bool expression to indicate left or right factor. True means left hemisphere, False means right hemisphere
    Output:
        n_removed: outlier_numbers
        residue_data: output data

    Example:
        >>> a = np.array([[1,2,3,4],[5,6,7,8]])
        >>> b = array([True,True,False,False], dtype=bool)
        >>> n_removed, residue_data = dataprocess(a,mergehemi = b)
    """
data
raw data. Notes that when the dimension is 1, data means regions. When the dimension is 2, data is the form of nsubj*regions. When the dimension is 3, data is the form of timeseries*regions*nsubj.
raw data . Notes that when the dimension is 1 data means regions . When the dimension is 2 data is the form of nsubj * regions . When the dimension is 3 data is the form of timeseries * regions * nsubj .
outlier_method
'iqr' or 'std' or 'abs'. By default is None
' iqr ' or ' std ' or ' abs ' . By default is None
outlier_range
outlier standard threshold
outlier standard threshold
mergehemi
merge hemisphere or not. By default is False. Input bool expression to indicate left or right factor. True means left hemisphere, False means right hemisphere
merge hemisphere or not . By default is False . Input bool expression to indicate left or right factor . True means left hemisphere False means right hemisphere
examples
None