def create(mask, path, niipartial, newname, restart=False):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.

    Input
    -----
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    path - the base path where all the BOLD data lives
    niipartial - a string the matches all data of interest
    newname - a name for all the combined roi data.  Note: all roi data is 
        saved in ./roinii/
    """
    
    try:
        os.mkdir("./roinii")
    except OSError:
        pass
    
    # Get and order the nii files
    print("Finding nii files.")
    niis = findallnii(path, niipartial)
    niis, bysub = _ordernii_butterfly(niis)

    # Mask and combine
    roinames = {}
    for sub in sorted(bysub.keys()):
        roinames[sub] = []
        for scan in bysub[sub]:
            if scan != None:
                roiname = _mask_butterfly(mask, scan, newname, restart)
                roinames[sub].append(roiname)
            else:
                roinames[sub].append(None)
    
    print("Combining all roi data by subject.")
    for sub, scans in roinames.items():
        scans = [scan for scan in scans if scan != None]
            ## Drop None

        # Init combinedniis then add the 
        # remaining scans to it and save 
        # the result
        print("Combining {0}.".format(sub))
        combinedniis = nb.load(scans.pop(0))
        for scan in scans:
            combinedniis = join_time(combinedniis, nb.load(scan))
        
        print("Saving {0}.".format(sub))
        nb.save(combinedniis, 
                os.path.join(
                "./roinii", "{0}_{1}.nii.gz".format(newname, sub)))
def create(mask, path, niipartial, newname, restart=False):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.

    Input
    -----
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    path - the base path where all the BOLD data lives
    niipartial - a string the matches all data of interest
    newname - a name for all the combined roi data.  Note: all roi data is 
        saved in ./roinii/
    """

    try:
        os.mkdir("./roinii")
    except OSError:
        pass

    # Get and order the nii files
    print("Finding nii files.")
    niis = findallnii(path, niipartial)
    niis, bysub = _ordernii_butterfly(niis)

    # Mask and combine
    roinames = {}
    for sub in sorted(bysub.keys()):
        roinames[sub] = []
        for scan in bysub[sub]:
            if scan != None:
                roiname = _mask_butterfly(mask, scan, newname, restart)
                roinames[sub].append(roiname)
            else:
                roinames[sub].append(None)

    print("Combining all roi data by subject.")
    for sub, scans in roinames.items():
        scans = [scan for scan in scans if scan != None]
        ## Drop None

        # Init combinedniis then add the
        # remaining scans to it and save
        # the result
        print("Combining {0}.".format(sub))
        combinedniis = nb.load(scans.pop(0))
        for scan in scans:
            combinedniis = join_time(combinedniis, nb.load(scan))

        print("Saving {0}.".format(sub))
        nb.save(
            combinedniis,
            os.path.join("./roinii", "{0}_{1}.nii.gz".format(newname, sub)))
def create(args):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.
    
    Input
    -----
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    path - the base path where all the BOLD data lives
    niipartial - a string the matches all data of interest
    newname - a name for all the combined roi data.  Note: all roi data is 
        saved in ./roinii/
    """
    
    # Process args, a dunmb way to make this function
    # compatible with pool.map()
    mask = args[0]
    path = args[1]
    niipartial = args[2]
    newname = args[3]
    restart = args[4]
    
    try:
        os.mkdir("./roinii")
    except OSError:
        pass
    
    # Get and order the nii files
    print("Finding nii files.")
    niis = findallnii(path, niipartial)
    niis, bysub = _ordernii_butterfly(niis)
    
    # Mask and combine
    roinames = {}
    for sub in sorted(bysub.keys()):
        roinames[sub] = []
        for scan in bysub[sub]:
            if scan != None:
                roiname = _mask_butterfly(mask, scan, newname, restart)
                roinames[sub].append(roiname)
            else:
                roinames[sub].append(None)
    
    print("Combining all roi data by subject.")
    for sub, scans in roinames.items():
        scans = [scan for scan in scans if scan != None]
            ## Drop None

        # Init combinedniis then add the 
        # remaining scans to it and save 
        # the result
        print("Combining {0}.".format(sub))

        combinedniis = nb.load(scans.pop(0))
        cname = os.path.join(
                "./roinii", "{0}_{1}.nii.gz".format(newname, sub))
        
        # If the combinedniis exists, move on (if we're
        # in restart mode)
        if restart and os.path.isfile(cname):
            print("{0} exists, continuing on.".format(cname))
        else:
            for scan in scans:
                combinedniis = join_time(combinedniis, nb.load(scan))
            
            print("Saving {0}.".format(sub))
            nb.save(combinedniis, cname)
Ejemplo n.º 4
0
def create(args):
    """Create a roi dataset using all Ploran 2007 (i.e. butterfly) 
    datasets.
    
    Input
    -----
    mask - name of a roi found in the Harvard Oxford atlas (see roi 
    package for details)
    path - the base path where all the BOLD data lives
    niipartial - a string the matches all data of interest
    newname - a name for all the combined roi data.  Note: all roi data is 
        saved in ./roinii/
    """

    # Process args, a dunmb way to make this function
    # compatible with pool.map()
    mask = args[0]
    path = args[1]
    niipartial = args[2]
    newname = args[3]
    restart = args[4]

    try:
        os.mkdir("./roinii")
    except OSError:
        pass

    # Get and order the nii files
    print("Finding nii files.")
    niis = findallnii(path, niipartial)
    niis, bysub = _ordernii_butterfly(niis)

    # Mask and combine
    roinames = {}
    for sub in sorted(bysub.keys()):
        roinames[sub] = []
        for scan in bysub[sub]:
            if scan != None:
                roiname = _mask_butterfly(mask, scan, newname, restart)
                roinames[sub].append(roiname)
            else:
                roinames[sub].append(None)

    print("Combining all roi data by subject.")
    for sub, scans in roinames.items():
        scans = [scan for scan in scans if scan != None]
        ## Drop None

        # Init combinedniis then add the
        # remaining scans to it and save
        # the result
        print("Combining {0}.".format(sub))

        combinedniis = nb.load(scans.pop(0))
        cname = os.path.join("./roinii", "{0}_{1}.nii.gz".format(newname, sub))

        # If the combinedniis exists, move on (if we're
        # in restart mode)
        if restart and os.path.isfile(cname):
            print("{0} exists, continuing on.".format(cname))
        else:
            for scan in scans:
                combinedniis = join_time(combinedniis, nb.load(scan))

            print("Saving {0}.".format(sub))
            nb.save(combinedniis, cname)