
datasink_qap_head_mask = 
_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_headmask_combine_masks = 
args = -bin
environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
ignore_exception = False
internal_datatype = <undefined>
nan2zeros = <undefined>
operand_value = <undefined>
operation = add
out_file = <undefined>
output_datatype = <undefined>
output_type = NIFTI_GZ
terminal_output = stream

qap_headmask_dilate = 
args = -dilM -dilM -dilM -dilM -dilM -dilM
environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
ignore_exception = False
internal_datatype = <undefined>
nan2zeros = <undefined>
out_file = <undefined>
output_datatype = <undefined>
output_type = NIFTI_GZ
terminal_output = stream

qap_headmask_erode = 
args = -eroF -eroF -eroF -eroF -eroF -eroF
environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
ignore_exception = False
internal_datatype = <undefined>
nan2zeros = <undefined>
out_file = <undefined>
output_datatype = <undefined>
output_type = NIFTI_GZ
terminal_output = stream

qap_headmask_select_thresh = 
function_str = S'def select_thresh(input_skull):\n\n    import os\n    import commands\n\n    avg_in = "3dmaskave %s" % input_skull\n\n    avg_out = commands.getoutput(avg_in)\n\n\n    avg = int(float(avg_out.split("\\n")[-1].split(" ")[0]))\n    max_limit = int(avg * 3)\n\n\n    # get the voxel intensity bins\n    cmd_in = "3dHist -input %s -nbin 10 -max %d -showhist" % \\\n             (input_skull, max_limit)\n\n    cmd_out = commands.getoutput(cmd_in)\n\n    os.system("rm HistOut.niml.hist")\n\n    bins = {}\n\n    for line in cmd_out.split("\\n"):\n\n        if "*" in line:\n\n            vox_bin = line.replace(" ","").split(":")[0]\n\n            voxel_value = int(float(vox_bin.split(",")[0]))\n\n            bins[int(vox_bin.split(",")[1])] = voxel_value\n\n\n    thresh_out = bins[min(bins.keys())]\n\n    return thresh_out\n'
.
ignore_exception = False
input_skull = input_skull_here

qap_headmask_slice_head_mask = 
function_str = S'def slice_head_mask(infile, transform, standard):\n\n    import os\n    import sys\n\n    import nibabel as nb\n    import numpy as np\n    import commands\n\n    import pkg_resources as p\n\n\n    # get file info\n    infile_img = nb.load(infile)\n    infile_header = infile_img.get_header()\n    infile_affine = infile_img.get_affine()\n\n    infile_dims = infile_header.get_data_shape()\n\n    # these are stored in the files listed below, just here for reference\n    inpoint_a = "78 -110 -72"\n    inpoint_b = "-78 -110 -72"\n    inpoint_c = "0 88 -72" # nose, apparently\n\n\n    # these each contain a set of coordinates for drawing the plane across\n    # the image (to "slice" it)\n    inpoint_files = [p.resource_filename("qap", "inpoint_a.txt"),\n                     p.resource_filename("qap", "inpoint_b.txt"),\n                     p.resource_filename("qap", "inpoint_c.txt")]\n\n\n    # let\'s convert the coordinates into voxel coordinates\n\n    coords = []\n\n    for inpoint in inpoint_files:\n\n        coord_cmd = "std2imgcoord -img %s -std %s -xfm %s -vox %s" \\\n                    % (infile, standard, transform, inpoint)\n\n        try:\n\n            coord_out = commands.getoutput(coord_cmd)\n\n        except:\n\n            raise Exception\n\n\n        if "Could not" in coord_out:\n\n            raise Exception(coord_out)\n\n\n        coords.append(coord_out)\n\n\n    # get the converted coordinates into a list format, and also check to make\n    # sure they are not "out of bounds"\n    new_coords = []\n\n    for coord in coords:\n\n        co_nums = coord.split(" ")\n\n        co_nums_newlist = []\n\n        for num in co_nums:\n\n            if num != "":\n                co_nums_newlist.append(int(num.split(".")[0]))\n\n        for ind in range(0,3):\n\n            if co_nums_newlist[ind] > infile_dims[ind]:\n                co_nums_newlist[ind] = infile_dims[ind]\n\n            elif co_nums_newlist[ind] < 1:\n                co_nums_newlist[ind] = 1\n\n        new_coords.append(co_nums_newlist)\n\n\n    # get the vectors connecting the points\n\n    u = []\n\n    for a_pt, c_pt in zip(new_coords[0], new_coords[2]):\n\n        u.append(int(a_pt - c_pt))\n\n\n    v = []\n\n    for b_pt, c_pt in zip(new_coords[1], new_coords[2]):\n\n        v.append(int(b_pt - c_pt))\n\n\n    u_vector = np.asarray(u)\n    v_vector = np.asarray(v)\n\n\n    # vector cross product\n    n = np.cross(u,v)\n\n    # normalize the vector\n    n = n / np.linalg.norm(n,2)\n\n\n    constant = np.dot(n, np.asarray(new_coords[0]))\n\n\n    # now determine the z-coordinate for each pair of x,y\n    plane_dict = {}\n\n    for yvox in range(0,infile_dims[1]):\n\n        for xvox in range(0, infile_dims[0]):\n\n            zvox = (constant - (n[0]*xvox + n[1]*yvox))/n[2]\n\n            zvox = np.floor(zvox)\n\n            if zvox < 1:\n                zvox = 1\n            elif zvox > infile_dims[2]:\n                zvox = infile_dims[2]\n\n            plane_dict[(xvox,yvox)] = zvox\n\n\n\n    # create the mask\n    mask_array = np.zeros(infile_dims)\n\n    for x in range(0, infile_dims[0]):\n\n        for y in range(0, infile_dims[1]):\n\n            for z in range(0, infile_dims[2]):\n\n                if plane_dict[(x,y)] > z:\n                    mask_array[x,y,z] = 1\n\n\n    new_mask_img = nb.Nifti1Image(mask_array, infile_affine, infile_header)\n\n    infile_filename = infile.split("/")[-1].split(".")[0]\n\n    outfile_name = infile_filename + "_slice_mask.nii.gz"\n    outfile_path = os.path.join(os.getcwd(), outfile_name)\n\n    nb.save(new_mask_img, outfile_path)\n\n\n    return outfile_path\n'
.
ignore_exception = False
infile = infile_here
standard = standard_here
transform = transform_here

qap_headmask_thresh = 
args = -bin
direction = below
environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
ignore_exception = False
in_file = in_file_here
internal_datatype = <undefined>
nan2zeros = <undefined>
out_file = <undefined>
output_datatype = <undefined>
output_type = NIFTI_GZ
terminal_output = stream
use_nonzero_voxels = <undefined>
use_robust_range = <undefined>


