2. Data preparation/EEG/compute_alpha_theta_beta_csv.py
def external_baseline(arr_as_base : np.ndarray,
                      arr_to_base : np.ndarray,
                      arr_time    : np.ndarray,
                      baseline    : tuple = (-1, 0), 
                      keep_orig   : bool  = False) -> np.ndarray:
    """
    Takes an array with power values and a TFR, and baselines the inputted TFR
    with the provided array. Currently on "logratio" supported.

    Parameters
    ----------
    arr_as_base : np.ndarray
        The data adapted from the TFR of the Epoch that will be used as a 
        baseline.
    arr_to_base : np.ndarray
        The data adapted from the TFR of the Epoch we wish to baseline.
    arr_time : np.ndarray
        The time array, indicating the time in seconds for the Epoch. A list 
        will probably also work. Type stability is not enforced.
    baseline : tuple, optional
        The period in arr_as_base that will be used to baseline arr_to_base. 
        Time is expressed in seconds. The default is (-1, 0).
    keep_orig : bool, optional
        Will return the original data (i.e. no baseline applied), along with
        the baselined data. The default is False.
    
    Returns
    -------
    np.ndarray
        Returns arr_to_base that was baselined using the data between baseline 
        in arr_as_base. This array can then be used to replace TFR.data.
    """   
    
    # check whether the types match
    assert type(arr_as_base) == type(arr_to_base) == np.ndarray
    
    # make a copy of the original
    orig = arr_to_base.copy()
    
    # get the baseline values and the points in the array
    bmin, bmax = baseline
    i_min, i_max = int(np.where(arr_time == bmin)[0]), \
                   int(np.where(arr_time == bmax)[0]) + 1

    # compute the baselined power values
    average = np.mean(arr_as_base[..., i_min:i_max], 
                      axis     = -1,
                      keepdims = True)
    
    arr_to_base  /= average
    arr_baselined = np.log10(arr_to_base)

    if keep_orig:
        return orig, arr_baselined
    else:
        return arr_baselined

    Takes an array with power values and a TFR, and baselines the inputted TFR
    with the provided array. Currently on "logratio" supported.

    Parameters
    ----------
    arr_as_base : np.ndarray
        The data adapted from the TFR of the Epoch that will be used as a 
        baseline.
    arr_to_base : np.ndarray
        The data adapted from the TFR of the Epoch we wish to baseline.
    arr_time : np.ndarray
        The time array, indicating the time in seconds for the Epoch. A list 
        will probably also work. Type stability is not enforced.
    baseline : tuple, optional
        The period in arr_as_base that will be used to baseline arr_to_base. 
        Time is expressed in seconds. The default is (-1, 0).
    keep_orig : bool, optional
        Will return the original data (i.e. no baseline applied), along with
        the baselined data. The default is False.
    
    Returns
    -------
    np.ndarray
        Returns arr_to_base that was baselined using the data between baseline 
        in arr_as_base. This array can then be used to replace TFR.data.
    
Takes an array with power values and a TFR, and baselines the inputted TFR
with the provided array. Currently on "logratio" supported.

Parameters

arr_as_base : np.ndarray
The data adapted from the TFR of the Epoch that will be used as a
baseline.
arr_to_base : np.ndarray
The data adapted from the TFR of the Epoch we wish to baseline.
arr_time : np.ndarray
The time array, indicating the time in seconds for the Epoch. A list
will probably also work. Type stability is not enforced.
baseline : tuple, optional
The period in arr_as_base that will be used to baseline arr_to_base.
Time is expressed in seconds. The default is (-1, 0).
keep_orig : bool, optional
Will return the original data , along with
the baselined data. The default is False.

Returns

np.ndarray
Returns arr_to_base that was baselined using the data between baseline
in arr_as_base. This array can then be used to replace TFR.data.
Takes an array with power values and a TFR and baselines the inputted TFR with the provided array . Currently on " logratio " supported . Parameters arr_as_base : np . ndarray The data adapted from the TFR of the Epoch that will be used as a baseline . arr_to_base : np . ndarray The data adapted from the TFR of the Epoch we wish to baseline . arr_time : np . ndarray The time array indicating the time in seconds for the Epoch . A list will probably also work . Type stability is not enforced . baseline : tuple optional The period in arr_as_base that will be used to baseline arr_to_base . Time is expressed in seconds . The default is ( - 1 0 ) . keep_orig : bool optional Will return the original data along with the baselined data . The default is False . Returns np . ndarray Returns arr_to_base that was baselined using the data between baseline in arr_as_base . This array can then be used to replace TFR . data .
def external_baseline(arr_as_base : np.ndarray,
                      arr_to_base : np.ndarray,
                      arr_time    : np.ndarray,
                      baseline    : tuple = (-1, 0), 
                      keep_orig   : bool  = False) -> np.ndarray:
    assert type(arr_as_base) == type(arr_to_base) == np.ndarray
    orig = arr_to_base.copy()
    bmin, bmax = baseline
    i_min, i_max = int(np.where(arr_time == bmin)[0]), \
                   int(np.where(arr_time == bmax)[0]) + 1
    average = np.mean(arr_as_base[..., i_min:i_max], 
                      axis     = -1,
                      keepdims = True)
    arr_to_base  /= average
    arr_baselined = np.log10(arr_to_base)
    if keep_orig:
        return orig, arr_baselined
    else:
        return arr_baselined
def external_baseline ( arr_as_base : np . ndarray , arr_to_base : np . ndarray , arr_time : np . ndarray , baseline : tuple = ( - 1 , 0 ) , keep_orig : bool = False ) -> np . ndarray : assert type ( arr_as_base ) == type ( arr_to_base ) == np . ndarray orig = arr_to_base . copy ( ) bmin , bmax = baseline i_min , i_max = int ( np . where ( arr_time == bmin ) [ 0 ] ) , int ( np . where ( arr_time == bmax ) [ 0 ] ) + 1 average = np . mean ( arr_as_base [ ... , i_min : i_max ] , axis = - 1 , keepdims = True ) arr_to_base /= average arr_baselined = np . log10 ( arr_to_base ) if keep_orig : return orig , arr_baselined else : return arr_baselined
Takes an array with power values and a TFR, and baselines the inputted TFR
with the provided array.
Takes an array with power values and a TFR and baselines the inputted TFR with the provided array .
"""
    Takes an array with power values and a TFR, and baselines the inputted TFR
    with the provided array. Currently on "logratio" supported.

    Parameters
    ----------
    arr_as_base : np.ndarray
        The data adapted from the TFR of the Epoch that will be used as a 
        baseline.
    arr_to_base : np.ndarray
        The data adapted from the TFR of the Epoch we wish to baseline.
    arr_time : np.ndarray
        The time array, indicating the time in seconds for the Epoch. A list 
        will probably also work. Type stability is not enforced.
    baseline : tuple, optional
        The period in arr_as_base that will be used to baseline arr_to_base. 
        Time is expressed in seconds. The default is (-1, 0).
    keep_orig : bool, optional
        Will return the original data (i.e. no baseline applied), along with
        the baselined data. The default is False.
    
    Returns
    -------
    np.ndarray
        Returns arr_to_base that was baselined using the data between baseline 
        in arr_as_base. This array can then be used to replace TFR.data.
    """ # check whether the types match # make a copy of the original # get the baseline values and the points in the array # compute the baselined power values
arr_as_base
np.ndarray
arr_to_base
np.ndarray
arr_time
np.ndarray
baseline
tuple
keep_orig
bool