def _mask_butterfly(mask, nii, newname, restart):
    """Apply mask to nii, save as newname."""
    
    print("Masking {0} with {1}.".format(os.path.basename(nii), mask))
    
    # Create a name for the temp roi data
    # then use the mask, saving with the tmpname
    name = newname + "_" + os.path.basename(nii)
    name = os.path.join(path, "roinii", name)
    
    # Ensure we are compressing the 
    # data by adding .nii.gz instead of, 
    # say, .nii
    fullname = os.path.basename(name)
    filename, fileextension = os.path.splitext(fullname)
    name = os.path.join(
            os.path.dirname(name), "{0}.nii.gz".format(filename))
    
    # If the file exists and we are
    # restarting continue on.
    if restart and os.path.isfile(name):
        print("{0} exists, continuing on.".format(name))
    else:
        # Mask! Save as name
        masknii(mask, nii, save=name)

    return name
Example #2
0
def _mask_butterfly(mask, nii, newname, restart):
    """Apply mask to nii, save as newname."""

    print("Masking {0} with {1}.".format(os.path.basename(nii), mask))

    # Create a name for the temp roi data
    # then use the mask, saving with the tmpname
    name = newname + "_" + os.path.basename(nii)
    name = os.path.join(path, "roinii", name)

    # Ensure we are compressing the
    # data by adding .nii.gz instead of,
    # say, .nii
    fullname = os.path.basename(name)
    filename, fileextension = os.path.splitext(fullname)
    name = os.path.join(os.path.dirname(name), "{0}.nii.gz".format(filename))

    # If the file exists and we are
    # restarting continue on.
    if restart and os.path.isfile(name):
        print("{0} exists, continuing on.".format(name))
    else:
        # Mask! Save as name
        masknii(mask, nii, save=name)

    return name
def create(args):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.
    
    Parameters
    ----------
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    newname - what (if anything) to rename the roi data as,
        often the default name (i.e. mask) are rather long
    subdatatable - a dictionary whose keys are subject numbers
        and whose values are absoluate paths to that Ss
        whole brain (functional) data.
    basepath - the top-level directory where all the Ss BOLD 
        (and other) data lives.
    """
     
    # Process args, a dunmb way to make 
    # this function compatible with pool.map()
    mask, newname, subdatatable, basepath = args
    print("Mask is {0}.".format(mask))

    maskednames = []
    for s in sorted(subdatatable.keys()):
        print("Running subject {0}.".format(s))

        # Look up the location of that Ss data, 
        # and mask it, finally save the masked 
        # file to disk
        datadir = subdatatable[s]
        saveas = os.path.join(basepath, 
                'roinii', "{0}_{1}.nii.gz".format(newname, s))
        masknii(mask, datadir, save=saveas)
def create(args):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.
    
    Parameters
    ----------
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    newname - what (if anything) to rename the roi data as,
        often the default name (i.e. mask) are rather long
    subdatatable - a dictionary whose keys are subject numbers
        and whose values are absoluate paths to that Ss
        whole brain (functional) data.
    basepath - the top-level directory where all the Ss BOLD 
        (and other) data lives.
    """

    # Process args, a dunmb way to make
    # this function compatible with pool.map()
    mask, newname, subdatatable, basepath = args
    print("Mask is {0}.".format(mask))

    maskednames = []
    for s in sorted(subdatatable.keys()):
        print("Running subject {0}.".format(s))

        # Look up the location of that Ss data,
        # and mask it, finally save the masked
        # file to disk
        datadir = subdatatable[s]
        saveas = os.path.join(basepath, 'roinii',
                              "{0}_{1}.nii.gz".format(newname, s))
        masknii(mask, datadir, save=saveas)