
datasink_qap_functional_spatial = 
_outputs = {}
base_directory = base_directory_here
container = <undefined>
ignore_exception = False
parameterization = True
regexp_substitutions = <undefined>
remove_dest_dir = False
strip_dir = <undefined>
substitutions = <undefined>

qap_functional_spatial = 
direction = x
func_brain_mask = func_brain_mask_here
function_str = S'def qap_functional_spatial(mean_epi, func_brain_mask, direction, subject_id, \\\n                               session_id, scan_id, site_name=None, \\\n                               out_vox=True):\n\n    import os\n    import sys\n\n    from qap.spatial_qc import summary_mask, snr, fber, efc, fwhm, \\\n                               ghost_direction\n    from qap.qap_utils import load_image, load_mask\n\n    # Load the data\n    anat_data = load_image(mean_epi)\n    fg_mask = load_mask(func_brain_mask, mean_epi)\n    bg_mask = 1 - fg_mask\n\n    # Initialize QC\n    qc              = dict()\n\n    qc[\'subject\'] = subject_id\n\n    qc[\'session\'] = session_id\n\n    qc[\'scan\'] = scan_id\n\n    if site_name:\n        qc[\'site\'] = site_name\n\n\n    # FBER\n    qc[\'fber\'] = fber(anat_data, fg_mask)\n\n    # EFC\n    qc[\'efc\'] = efc(anat_data)\n\n\n    # Smoothness in voxels\n    tmp             = fwhm(mean_epi, func_brain_mask, out_vox=out_vox)\n    qc[\'fwhm_x\'], qc[\'fwhm_y\'], qc[\'fwhm_z\'], qc[\'fwhm\'] = tmp\n\n    # Ghosting\n    if (direction == "all"):\n        qc[\'ghost_x\'] = ghost_direction(anat_data, fg_mask, "x")\n        qc[\'ghost_y\'] = ghost_direction(anat_data, fg_mask, "y")\n        qc[\'ghost_z\'] = ghost_direction(anat_data, fg_mask, "z")\n\n    else:\n        qc[\'ghost_%s\' % direction] = ghost_direction(anat_data, fg_mask, \\\n                                         direction)\n\n\n    # Summary Measures\n    qc[\'fg_mean\'], qc[\'fg_std\'], qc[\'fg_size\'] = summary_mask(anat_data, fg_mask)\n    qc[\'bg_mean\'], qc[\'bg_std\'], qc[\'bg_size\'] = summary_mask(anat_data, bg_mask)\n\n\n    qc[\'snr\']   = None\n\n\n    # SNR\n    qc[\'snr\']       = snr(qc[\'fg_mean\'], qc[\'bg_std\'])\n\n\n    return qc\n'
.
ignore_exception = False
mean_epi = mean_epi_here
scan_id = rest_1
session_id = session_1
site_name = site_1
subject_id = 1019436

qap_functional_spatial_to_csv = 
function_str = S'def write_to_csv(sub_qap_dict):  #, outfile):\n\n    import os\n    import csv\n\n    fields = sub_qap_dict.keys()\n\n    # put these at the forefront of the list of header items, to make the\n    # output CSV\'s more readable\n\n    fields = sorted(fields)\n\n    if "subject" in fields:\n        fields.remove("subject")\n        fields.insert(0, "subject")\n\n    if "session" in fields:\n        fields.remove("session")\n        fields.insert(1, "session")\n\n    if "scan" in fields:\n        fields.remove("scan")\n        fields.insert(2, "scan")\n\n    if "site" in fields:\n        fields.remove("site")\n        fields.insert(3, "site")\n\n\n    outfile = os.path.join(os.getcwd(), "qap_measures.csv")\n\n\n    with open(outfile, "wt") as out_f:\n\n        csv_writer = csv.DictWriter(out_f, fields)\n\n        csv_writer.writeheader()\n\n        csv_writer.writerow(sub_qap_dict)\n\n\n    return outfile\n'
.
ignore_exception = False


