def postpro_boxcox(data, report=None):
    """
    Performs box cox transform on everything in data.

    If report variable is passed, this is added to the report.
    """
    if not report:
        report = {}
    # Note the min value of all time series will now be at least 1.
    mindata = 1 - np.nanmin(data)
    data = data + mindata
    ind = np.triu_indices(data.shape[0], k=1)

    boxcox_list = np.array([sp.stats.boxcox(np.squeeze(
        data[ind[0][n], ind[1][n], :])) for n in range(0, len(ind[0]))])

    boxcox_data = np.zeros(data.shape)
    boxcox_data[ind[0], ind[1], :] = np.vstack(boxcox_list[:, 0])
    boxcox_data[ind[1], ind[0], :] = np.vstack(boxcox_list[:, 0])

    bccheck = np.array(np.transpose(boxcox_data, [2, 0, 1]))
    bccheck = (bccheck - bccheck.mean(axis=0)) / bccheck.std(axis=0)
    bccheck = np.squeeze(np.mean(bccheck, axis=0))
    np.fill_diagonal(bccheck, 0)

    report['boxcox'] = {}
    report['boxcox']['performed'] = 'yes'
    report['boxcox']['lambda'] = [
        tuple([ind[0][n], ind[1][n], boxcox_list[n, -1]]) for n in range(0, len(ind[0]))]
    report['boxcox']['shift'] = mindata
    report['boxcox']['shited_to'] = 1

    if np.sum(np.isnan(bccheck)) > 0:
        report['boxcox'] = {}
        report['boxcox']['performed'] = 'FAILED'
        report['boxcox']['failure_reason'] = (
            'Box cox transform is returning edges with uniform values through time. '
            'This is probabaly due to one or more outliers or a very skewed distribution. '
            'Have you corrected for sources of noise (e.g. movement)? '
            'If yes, some time-series might need additional transforms to approximate to Gaussian.'
        )
        report['boxcox']['failure_consequence'] = (
            'Box cox transform was skipped from the postprocess pipeline.'
        )
        boxcox_data = data - mindata
        error_msg = ('TENETO WARNING: Box Cox transform problem. \n'
                     'Box Cox transform not performed. \n'
                     'See report for more details.')
        print(error_msg)

    return boxcox_data, report
def postpro_boxcox ( data , report = None ) : if not report : report = { } mindata = 1 - np . nanmin ( data ) data = data + mindata ind = np . triu_indices ( data . shape [ 0 ] , k = 1 ) boxcox_list = np . array ( [ sp . stats . boxcox ( np . squeeze ( data [ ind [ 0 ] [ n ] , ind [ 1 ] [ n ] , : ] ) ) for n in range ( 0 , len ( ind [ 0 ] ) ) ] ) boxcox_data = np . zeros ( data . shape ) boxcox_data [ ind [ 0 ] , ind [ 1 ] , : ] = np . vstack ( boxcox_list [ : , 0 ] ) boxcox_data [ ind [ 1 ] , ind [ 0 ] , : ] = np . vstack ( boxcox_list [ : , 0 ] ) bccheck = np . array ( np . transpose ( boxcox_data , [ 2 , 0 , 1 ] ) ) bccheck = ( bccheck - bccheck . mean ( axis = 0 ) ) / bccheck . std ( axis = 0 ) bccheck = np . squeeze ( np . mean ( bccheck , axis = 0 ) ) np . fill_diagonal ( bccheck , 0 ) report [ 'boxcox' ] = { } report [ 'boxcox' ] [ 'performed' ] = 'yes' report [ 'boxcox' ] [ 'lambda' ] = [ tuple ( [ ind [ 0 ] [ n ] , ind [ 1 ] [ n ] , boxcox_list [ n , - 1 ] ] ) for n in range ( 0 , len ( ind [ 0 ] ) ) ] report [ 'boxcox' ] [ 'shift' ] = mindata report [ 'boxcox' ] [ 'shited_to' ] = 1 if np . sum ( np . isnan ( bccheck ) ) > 0 : report [ 'boxcox' ] = { } report [ 'boxcox' ] [ 'performed' ] = 'FAILED' report [ 'boxcox' ] [ 'failure_reason' ] = ( 'Box cox transform is returning edges with uniform values through time. ' 'This is probabaly due to one or more outliers or a very skewed distribution. ' 'Have you corrected for sources of noise (e.g. movement)? ' 'If yes, some time-series might need additional transforms to approximate to Gaussian.' ) report [ 'boxcox' ] [ 'failure_consequence' ] = ( 'Box cox transform was skipped from the postprocess pipeline.' ) boxcox_data = data - mindata error_msg = ( 'TENETO WARNING: Box Cox transform problem. \n' 'Box Cox transform not performed. \n' 'See report for more details.' ) print ( error_msg ) return boxcox_data , report
Performs box cox transform on everything in data.

    If report variable is passed, this is added to the report.