Exemple #1
0
def main(argv):
    thisContrast = None
    debug = False
    write = False
    roi = "grayMatter"
    dstype = "raw"
    r = 4  # searchlight radius
    try:
        opts, args = getopt.getopt(argv, "dwhm:c:b:r", ["mfile=", "contrast=", "debug="])
    except getopt.GetoptError:
        print "searchlight.py -m <maskfile> -c <contrast> "
        sys.exit(2)
    for opt, arg in opts:
        if opt == "-h":
            print "searchlight.py -m <maskfile> -c <contrast>  "
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        # elif opt in ("-n", "--niter"):
        #     n = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True
        elif opt in ("-r", "--radius"):
            r = arg
        elif opt in ("-b", "--dstype"):
            dstype = arg

    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
    print "Mask: " + str(roi)
    print "Full Model: " + str(thisContrast)
    print "Searchlight Radius: " + str(r)
    print "Write results: " + str(write)
    sg_params = [49, 2]
    if debug:
        subList = {"LMVPA005": subList["LMVPA005"]}

    for s in subList.keys():
        runsub(
            sub=s,
            thisContrast=thisContrast,
            r=r,
            dstype=dstype,
            write=write,
            filterLen=sg_params[0],
            filterOrd=sg_params[1],
            roi=roi,
        )
Exemple #2
0
def result_hist(scan, masksize):
    paths, subList, contrasts, masks = lmvpa.initpaths(plat)
    bfn = os.path.join(paths[0], 'Maps', 'Encoding', scan + '.nii.gz')
    f, axarr = plt.subplots(len(masks), sharex=True)
    axarr[0].set_title('Model: ' + scan + ' | Mask size: ' + str(masksize))
    for i, m in enumerate(masks):
        mask = os.path.join(paths[0], 'data', s, 'masks', s + '_' + m + '.nii.gz')
        d = fmri_dataset(bfn, mask=mask)
        axarr[i].hist(np.mean(d[0].samples,0), bins=30)
        axarr[i].axvline(x=np.median(d.samples), color='r')
        axarr[i].set_ylabel(m)
Exemple #3
0
def result_hist(scan, masksize):
    paths, subList, contrasts, masks = lmvpa.initpaths(plat)
    bfn = os.path.join(paths[0], 'Maps', 'Encoding', scan + '.nii.gz')
    f, axarr = plt.subplots(len(masks), sharex=True)
    axarr[0].set_title('Model: ' + scan + ' | Mask size: ' + str(masksize))
    for i, m in enumerate(masks):
        mask = os.path.join(paths[0], 'data', s, 'masks',
                            s + '_' + m + '.nii.gz')
        d = fmri_dataset(bfn, mask=mask)
        axarr[i].hist(np.mean(d[0].samples, 0), bins=30)
        axarr[i].axvline(x=np.median(d.samples), color='r')
        axarr[i].set_ylabel(m)
def main(argv):
    roi = 'grayMatter'
    regs = []
    debug=False
    write=False
    try:
        opts, args = getopt.getopt(argv, "dwhm:c:", ["mfile=", "contrast=", "debug=", "write="])
    except getopt.GetoptError:
        print 'encodingAnalysisV4.py -m <maskfile> -c <contrast> '
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'encodingAnalysisV4.py -m <mask> -c <contrast> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        elif opt in ("-c", "--contrast"):
            regs = arg.split(',')
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True

    if not regs:
        print "not a valid contrast... exiting"
        sys.exit(1)
    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)

    regstr = '+'.join(regs)
    print(regstr)
    if 'word2vec' in regs:
        regs.remove('word2vec')
        for i in np.arange(0, 300):
            regs.append('word2vec' + str(i))

    if 'random' in regs:
        regs.remove('random')
        for i in np.arange(0, 302):
            regs.append('random' + str(i))

    sg_params = [49, 2]
    chunklen = 30  # this reflects the length of a complete trial
    paramEst = .25  # this much data to be held out for ridge regression parameter estimation
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    logging.basicConfig(level=logging.DEBUG)
    alphas = np.logspace(-1, 3, 50)
    for s in subList.keys():
        runsub(sub=s, thisContrast=regs, thisContrastStr=regstr,
               filterLen=sg_params[0], filterOrd=sg_params[1], debug=debug,
               paramEst=paramEst, chunklen=chunklen, alphas=alphas, write=write, roi=roi)
Exemple #5
0
def main(argv):
    thisContrast = None
    debug = False
    write = False
    roi = 'grayMatter'
    dstype='raw'
    r = 4  # searchlight radius
    try:
        opts, args = getopt.getopt(argv, "dwhm:c:b:r", ["mfile=", "contrast=", "debug="])
    except getopt.GetoptError:
        print 'searchlight.py -m <maskfile> -c <contrast> '
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'searchlight.py -m <maskfile> -c <contrast>  '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        # elif opt in ("-n", "--niter"):
        #     n = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True
        elif opt in ("-r", "--radius"):
            r = arg
        elif opt in ("-b", "--dstype"):
            dstype = arg

    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
    print "Mask: " + str(roi)
    print "Full Model: " + str(thisContrast)
    print "Searchlight Radius: " + str(r)
    print "Write results: " + str(write)
    sg_params = [63, 2]
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    for s in subList.keys():
        runsub(sub=s, thisContrast=thisContrast, r=r, dstype=dstype, write=write,
               filterLen=sg_params[0], filterOrd=sg_params[1], roi=roi)
Exemple #6
0
def main(argv):
    roi = 'grayMatter'
    thisContrast = []

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)

    try:
        opts, args = getopt.getopt(argv, "hm:c:", ["mfile=", "contrast="])
    except getopt.GetoptError:
        print 'linearEncoding.py -r <roi> -m <maskfile> -c <contrast> '
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'linearEncoding.py -m <mask> -c <contrast> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg.split(',')

    debug = False
    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    thisContrastStr = '+'.join(thisContrast)
    print(thisContrastStr)
    if 'word2vec' in thisContrast:
        thisContrast.remove('word2vec')
        for i in np.arange(0, 300):
            thisContrast.append('word2vec' + str(i))

    sg_params = [49, 2]
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    # ds_all = lmvpa.loadsubdata(paths, subList, m=roi, c='trial_type')
    # motion parameters for all subjects
    # events for beta extraction
    # add everything as a sample attribute

    for s in subList.keys():
        runsub(sub=s,
               thisContrast=thisContrast,
               thisContrastStr=thisContrastStr,
               filterLen=sg_params[0],
               filterOrd=sg_params[1],
               roi='grayMatter')
def main(argv):
    roi = 'grayMatter'
    thisContrast = []

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)

    try:
      opts, args = getopt.getopt(argv, "hm:c:", ["mfile=", "contrast="])
    except getopt.GetoptError:
      print 'linearEncoding.py -r <roi> -m <maskfile> -c <contrast> '
      sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'linearEncoding.py -m <mask> -c <contrast> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg.split(',')

    debug=False
    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    thisContrastStr = '+'.join(thisContrast)
    print(thisContrastStr)
    if 'word2vec' in thisContrast:
        thisContrast.remove('word2vec')
        for i in np.arange(0, 300):
            thisContrast.append('word2vec' + str(i))

    sg_params = [49, 2]
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    # ds_all = lmvpa.loadsubdata(paths, subList, m=roi, c='trial_type')
    # motion parameters for all subjects
    # events for beta extraction
    # add everything as a sample attribute

    for s in subList.keys():
        runsub(sub=s, thisContrast=thisContrast, thisContrastStr=thisContrastStr,
               filterLen=sg_params[0], filterOrd=sg_params[1], roi='grayMatter')
Exemple #8
0
    # plat = 'mac'
    sys.path.append('/Users/njchiang/GitHub/LanguageMVPA/multivariate/python/analysis')
    sys.path.append('/Users/njchiang/GitHub/python-fmri-utils/utils')
    debug = True
else:
    plat = 'win'
    sys.path.append('D:\\GitHub\\LanguageMVPA\\multivariate\\python\\analysis')
    sys.path.append('D:\\GitHub\\python-fmri-utils\\utils')
    debug = False
import lmvpautils as lmvpa
from sklearn import linear_model as lm
from mvpa2.clfs.skl import SKLLearnerAdapter
from mvpa2.clfs import svm
# debug = True

paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
if debug:
    subList = {'LMVPA005': subList['LMVPA005']}

import numpy as np
import os
from mvpa2.datasets.mri import map2nifti
from mvpa2.mappers.zscore import zscore
import SavGolFilter as sg
import mvpa2.datasets.eventrelated as er
from mvpa2.measures.base import CrossValidation
from mvpa2.generators.partition import NFoldPartitioner
import searchlightutils as sl

# for sub in subList.keys():
def runsub(sub, thisContrast, r, dstype='raw', roi='grayMatter', filterLen=49, filterOrd=3, write=False):
    # plat = 'mac'
    sys.path.append('/Users/njchiang/GitHub/LanguageMVPA/multivariate/python/analysis')
    sys.path.append('/Users/njchiang/GitHub/python-fmri-utils/utils')
    debug = True
else:
    plat = 'win'
    sys.path.append('D:\\GitHub\\LanguageMVPA\\multivariate\\python\\analysis')
    sys.path.append('D:\\GitHub\\python-fmri-utils\\utils')
    debug = False

import os

print "Initializing..."
# initialize paths
import lmvpautils as lmvpa
paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
# nVox = 100
# initialize subjects, masks, contrast
roi = "left_IFG_operc"
con = "syntax"
chance = .25
dsType = "Lang"
nVox = 500
# dsType = "Pic"

cname = 'LinearSVM'
from mvpa2.clfs import svm
clf = svm.LinearCSVMC()
preproc = 'None'
# feature selection
# preproc = 'fsel-'+str(nVox)
Exemple #10
0
def main(argv):
    roi = 'grayMatter'
    thisContrast = []
    testContrast = []
    debug=False
    write=False
    n = 100
    alphas = [1, 2.69, 2.62] # 1.68, 3.56]

    try:
        opts, args = getopt.getopt(argv, "dwhm:c:t:a", ["mfile=", "contrast=", "test=", "alpha=", "debug="])
    except getopt.GetoptError:
        print 'encodingAnalysisV5.py -m <maskfile> -c <contrast> -t <testcontrasts> -a <alphas>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'encodingAnalysisV5.py -m <maskfile> -c <contrast> -t <testcontrasts> -a <alphas> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        # elif opt in ("-n", "--niter"):
        #     n = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg.split(',')
        elif opt in ("-t", "--test"):
            tmp = arg.split(',')
            testContrast.append(tmp)
        elif opt in ("-a", "--alpha"):
            tmp = arg.split(',')
            alphas = [float(i) for i in tmp]
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True

    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
    print "Mask: " + str(roi)
    print "Full Model: " + str(thisContrast)
    print "Model test: " + str(testContrast)
    print "Alphas: " + str(alphas)

    thisContrastStr = '+'.join(thisContrast)
    print(thisContrastStr)
    if 'word2vec' in thisContrast:
        thisContrast.remove('word2vec')
        for i in np.arange(0, 300):
            thisContrast.append('word2vec' + str(i))

    if 'random' in thisContrast:
        thisContrast.remove('random')
        for i in np.arange(0, 302):
            thisContrast.append('random' + str(i))

    sg_params = [49, 2]
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    logging.basicConfig(level=logging.DEBUG)
    for s in subList.keys():
        runsub(sub=s, thisContrast=thisContrast, thisContrastStr=thisContrastStr, debug=debug, write=write,
               testContrast=testContrast, filterLen=sg_params[0], filterOrd=sg_params[1],
               alphas=alphas, roi=roi)
def main(argv):
    roi = 'grayMatter'
    thisContrast = []
    testContrast = []
    debug=False
    write=False
    n = 100
    alphas = [1, 2.69, 2.62] # 1.68, 3.56]

    try:
        opts, args = getopt.getopt(argv, "dwhm:c:t:a", ["mfile=", "contrast=", "test=", "alpha=", "debug="])
    except getopt.GetoptError:
        print 'encodingAnalysisV5.py -m <maskfile> -c <contrast> -t <testcontrasts> -a <alphas>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'encodingAnalysisV5.py -m <maskfile> -c <contrast> -t <testcontrasts> -a <alphas> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        # elif opt in ("-n", "--niter"):
        #     n = arg
        elif opt in ("-c", "--contrast"):
            thisContrast = arg.split(',')
        elif opt in ("-t", "--test"):
            tmp = arg.split(',')
            testContrast.append(tmp)
        elif opt in ("-a", "--alpha"):
            tmp = arg.split(',')
            alphas = [float(i) for i in tmp]
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True

    if not thisContrast:
        print "not a valid contrast... exiting"
        sys.exit(1)

    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)
    print "Mask: " + str(roi)
    print "Full Model: " + str(thisContrast)
    print "Model test: " + str(testContrast)
    print "Alphas: " + str(alphas)

    thisContrastStr = '+'.join(thisContrast)
    print(thisContrastStr)
    if 'word2vec' in thisContrast:
        thisContrast.remove('word2vec')
        for i in np.arange(0, 300):
            thisContrast.append('word2vec' + str(i))

    if 'random' in thisContrast:
        thisContrast.remove('random')
        for i in np.arange(0, 302):
            thisContrast.append('random' + str(i))

    sg_params = [49, 2]
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    logging.basicConfig(level=logging.DEBUG)
    for s in subList.keys():
        runsub(sub=s, thisContrast=thisContrast, thisContrastStr=thisContrastStr, debug=debug, write=write,
               testContrast=testContrast, filterLen=sg_params[0], filterOrd=sg_params[1],
               alphas=alphas, roi=roi)
Exemple #12
0
def main(argv):
    roi = 'grayMatter'
    regs = []
    debug = False
    write = False
    try:
        opts, args = getopt.getopt(argv, "dwhm:c:",
                                   ["mfile=", "contrast=", "debug=", "write="])
    except getopt.GetoptError:
        print 'encodingAnalysisV4.py -m <maskfile> -c <contrast> '
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'encodingAnalysisV4.py -m <mask> -c <contrast> '
            sys.exit()
        elif opt in ("-m", "--mask"):
            roi = arg
        elif opt in ("-c", "--contrast"):
            regs = arg.split(',')
        elif opt in ("-d", "--debug"):
            print "debug mode"
            debug = True
        elif opt in ("-w", "--write"):
            write = True

    if not regs:
        print "not a valid contrast... exiting"
        sys.exit(1)
    paths, subList, contrasts, maskList = lmvpa.initpaths(plat)

    regstr = '+'.join(regs)
    print(regstr)
    if 'word2vec' in regs:
        regs.remove('word2vec')
        for i in np.arange(0, 300):
            regs.append('word2vec' + str(i))

    if 'random' in regs:
        regs.remove('random')
        for i in np.arange(0, 302):
            regs.append('random' + str(i))

    sg_params = [49, 2]
    chunklen = 30  # this reflects the length of a complete trial
    paramEst = .25  # this much data to be held out for ridge regression parameter estimation
    if debug:
        subList = {'LMVPA005': subList['LMVPA005']}

    logging.basicConfig(level=logging.DEBUG)
    alphas = np.logspace(-1, 3, 50)
    for s in subList.keys():
        runsub(sub=s,
               thisContrast=regs,
               thisContrastStr=regstr,
               filterLen=sg_params[0],
               filterOrd=sg_params[1],
               debug=debug,
               paramEst=paramEst,
               chunklen=chunklen,
               alphas=alphas,
               write=write,
               roi=roi)