
datasink_qap_anatomical_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_anatomical_spatial = 
anatomical_csf_mask = anatomical_csf_mask_here
anatomical_gm_mask = anatomical_gm_mask_here
anatomical_reorient = anatomical_reorient_here
anatomical_wm_mask = anatomical_wm_mask_here
function_str = S"def qap_anatomical_spatial(anatomical_reorient, head_mask_path, \\\n                               anatomical_gm_mask, anatomical_wm_mask, \\\n                               anatomical_csf_mask, subject_id, session_id, \\\n                               scan_id, site_name=None, out_vox=True):\n\n    import os\n    import sys\n\n    from qap.spatial_qc import summary_mask, snr, cnr, fber, efc, \\\n                               artifacts, fwhm\n    from qap.qap_utils import load_image, load_mask\n\n    # Load the data\n    anat_data = load_image(anatomical_reorient)\n    fg_mask = load_mask(head_mask_path, anatomical_reorient)\n    bg_mask = 1 - fg_mask\n\n    gm_mask = load_mask(anatomical_gm_mask, anatomical_reorient)\n    wm_mask = load_mask(anatomical_wm_mask, anatomical_reorient)\n    csf_mask = load_mask(anatomical_csf_mask, anatomical_reorient)\n\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    # Artifact\n    qc['qi1'], _    = artifacts(anat_data, fg_mask, calculate_qi2=False)\n\n    # Smoothness in voxels\n    tmp             = fwhm(anatomical_reorient, head_mask_path, out_vox=out_vox)\n    qc['fwhm_x'], qc['fwhm_y'], qc['fwhm_z'], qc['fwhm'] = tmp\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    qc['gm_mean'], qc['gm_std'], qc['gm_size']      = (None, None, None)\n    qc['wm_mean'], qc['wm_std'], qc['wm_size']      = (None, None, None)\n    qc['csf_mean'], qc['csf_std'], qc['csf_size']   = (None, None, None)\n    qc['cnr']   = None\n    qc['snr']   = None\n\n    # More Summary Measures\n    qc['gm_mean'], qc['gm_std'], qc['gm_size']      = summary_mask(anat_data, gm_mask)\n    qc['wm_mean'], qc['wm_std'], qc['wm_size']      = summary_mask(anat_data, wm_mask)\n    qc['csf_mean'], qc['csf_std'], qc['csf_size']   = summary_mask(anat_data, csf_mask)\n\n    # SNR\n    qc['snr']       = snr(qc['fg_mean'], qc['bg_std'])\n\n    # CNR\n    qc['cnr']   = cnr(qc['gm_mean'], qc['wm_mean'], qc['bg_std'])\n\n\n    return qc\n"
.
head_mask_path = head_mask_path_here
ignore_exception = False
scan_id = anat_1
session_id = session_1
site_name = site_1
subject_id = 1019436

qap_anatomical_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


