def qap_functional_temporal(
    func_motion_correct,
    func_brain_mask,
    coord_xfm_matrix,
    subject_id,
    session_id,
    scan_id,
    site_name=None,
    motion_threshold=1.0,
):

    import sys

    from qap.temporal_qc import (
        mean_dvars_wrapper,
        summarize_fd,
        mean_outlier_timepoints,
        mean_quality_timepoints,
        global_correlation,
    )

    # DVARS
    mean_dvars = mean_dvars_wrapper(func_motion_correct, func_brain_mask)

    # Mean FD (Jenkinson)
    (mean_fd, num_fd, percent_fd) = summarize_fd(coord_xfm_matrix, threshold=motion_threshold)

    # 3dTout
    mean_outlier = mean_outlier_timepoints(func_motion_correct, func_brain_mask)

    # 3dTqual
    mean_quality = mean_quality_timepoints(func_motion_correct)

    # new thing
    gcor = global_correlation(func_motion_correct, func_brain_mask)

    # Compile
    qc = {
        "subject": subject_id,
        "session": session_id,
        "scan": scan_id,
        "dvars": mean_dvars,
        "mean_fd": mean_fd,
        "num_fd": num_fd,
        "perc_fd": percent_fd,
        "outlier": mean_outlier,
        "quality": mean_quality,
        "gcor": gcor,
    }

    if site_name:
        qc["site"] = site_name

    return qc
def qap_functional_temporal(func_motion_correct,
                            func_brain_mask,
                            tsnr_volume,
                            fd_file,
                            subject_id,
                            session_id,
                            scan_id,
                            site_name=None,
                            motion_threshold=1.0):

    import sys
    import nibabel as nb
    import numpy as np

    from qap.temporal_qc import mean_dvars_wrapper, mean_outlier_timepoints, \
        mean_quality_timepoints, global_correlation

    # DVARS
    mean_dvars = mean_dvars_wrapper(func_motion_correct, func_brain_mask)

    # Mean FD (Jenkinson)
    fd = np.loadtxt(fd_file)

    # Calculate Outliers
    # Number and Percent of frames (time points) where
    # movement (FD) exceeded threshold
    num_fd = np.float((fd > motion_threshold).sum())
    percent_fd = (num_fd * 100) / (len(fd) + 1)

    # 3dTout
    mean_outlier = mean_outlier_timepoints(func_motion_correct,
                                           func_brain_mask)

    # 3dTqual
    mean_quality = mean_quality_timepoints(func_motion_correct)

    # new thing
    gcor = global_correlation(func_motion_correct, func_brain_mask)

    # tSNR
    tsnr_data = nb.load(tsnr_volume).get_data()
    msk_data = np.ones_like(tsnr_data)
    try:
        msk_data = nb.load(func_brain_mask).get_data()
    except:
        pass

    # Compile
    qc = {
        "subject": subject_id,
        "session": session_id,
        "scan": scan_id,
        "dvars": mean_dvars,
        "m_tsnr": np.median(tsnr_data[msk_data > 0]),
        "mean_fd": fd.mean(),
        'num_fd': num_fd,
        'perc_fd': percent_fd,
        "outlier": mean_outlier,
        "quality": mean_quality,
        "gcor": gcor
    }

    if site_name:
        qc['site'] = site_name

    return qc
def qap_functional_temporal(
    func_motion_correct,
    func_brain_mask,
    tsnr_volume,
    fd_file,
    subject_id,
    session_id,
    scan_id,
    site_name=None,
    motion_threshold=1.0,
):

    import sys
    import nibabel as nb
    import numpy as np

    from qap.temporal_qc import mean_dvars_wrapper, mean_outlier_timepoints, mean_quality_timepoints, global_correlation

    # DVARS
    mean_dvars = mean_dvars_wrapper(func_motion_correct, func_brain_mask)

    # Mean FD (Jenkinson)
    fd = np.loadtxt(fd_file)

    # Calculate Outliers
    # Number and Percent of frames (time points) where
    # movement (FD) exceeded threshold
    num_fd = np.float((fd > motion_threshold).sum())
    percent_fd = (num_fd * 100) / (len(fd) + 1)

    # 3dTout
    mean_outlier = mean_outlier_timepoints(func_motion_correct, func_brain_mask)

    # 3dTqual
    mean_quality = mean_quality_timepoints(func_motion_correct)

    # new thing
    gcor = global_correlation(func_motion_correct, func_brain_mask)

    # tSNR
    tsnr_data = nb.load(tsnr_volume).get_data()
    msk_data = np.ones_like(tsnr_data)
    try:
        msk_data = nb.load(func_brain_mask).get_data()
    except:
        pass

    # Compile
    qc = {
        "subject": subject_id,
        "session": session_id,
        "scan": scan_id,
        "dvars": mean_dvars,
        "m_tsnr": np.median(tsnr_data[msk_data > 0]),
        "mean_fd": fd.mean(),
        "num_fd": num_fd,
        "perc_fd": percent_fd,
        "outlier": mean_outlier,
        "quality": mean_quality,
        "gcor": gcor,
    }

    if site_name:
        qc["site"] = site_name

    return qc