def extract_frommask_component(realigned_file, mask_file):
    import os
    import nibabel as nb
    import numpy as np
    from utils import mean_roi_signal
    from nipype import logging
    iflogger = logging.getLogger('interface')

    data = nb.load(realigned_file).get_data().astype('float64')
    mask = nb.load(mask_file).get_data().astype('float64')
    iflogger.info('Data and mask loaded.')
    mask_comp = mean_roi_signal(data, mask.astype('bool'))

    components_file = os.path.join(os.getcwd(), 'mask_mean_component.txt')
    iflogger.info('Saving components file:' + components_file)
    np.savetxt(components_file, mask_comp)

    return components_file
def extract_frommask_component(realigned_file, mask_file):
    import os
    import nibabel as nb
    import numpy as np
    from utils import mean_roi_signal
    from nipype import logging
    iflogger = logging.getLogger('interface')

    data = nb.load(realigned_file).get_data().astype('float64')
    mask = nb.load(mask_file).get_data().astype('float64')
    iflogger.info('Data and mask loaded.')
    mask_comp = mean_roi_signal(data, mask.astype('bool'))

    components_file = os.path.join(os.getcwd(), 'mask_mean_component.txt')
    iflogger.info('Saving components file:' + components_file)
    np.savetxt(components_file, mask_comp)

    return components_file
def extract_global_component(realigned_file):
    import os
    import nibabel as nb
    import numpy as np
    from utils import mean_roi_signal

    data = nb.load(realigned_file).get_data().astype('float64')
    mask = (data != 0).sum(-1) != 0  # Global Mask
    print 'Data loaded.'
    #    Y = data[mask].T
    #    Yc = Y - np.tile(Y.mean(0), (Y.shape[0], 1))
    glb_comp = mean_roi_signal(data, mask)

    components_file = os.path.join(os.getcwd(), 'global_component.txt')
    print 'Saving components file:', components_file
    np.savetxt(components_file, glb_comp)

    return components_file
def extract_global_component(realigned_file):
    import os
    import nibabel as nb
    import numpy as np
    from utils import mean_roi_signal

    data = nb.load(realigned_file).get_data().astype('float64')
    mask = (data != 0).sum(-1) != 0  # Global Mask
    print 'Data loaded.'
#    Y = data[mask].T
#    Yc = Y - np.tile(Y.mean(0), (Y.shape[0], 1))
    glb_comp = mean_roi_signal(data, mask)

    components_file = os.path.join(os.getcwd(), 'global_component.txt')
    print 'Saving components file:', components_file
    np.savetxt(components_file, glb_comp)

    return components_file