def new_eve(eve, epochs, eve_dir, rej_dir):
    print 'Running %s' % eve
    eve_d = readTable(eve)
    rej_types = ('blink',) # , 'grad', 'mag', 'eeg'
    type_rep = {'blink':'1000'}
    print 'epochs.keys listed in condCodes:',epochs.keys()
    k = filter(lambda y: y in eve, epochs.keys())  #given your eve file name, see if it contains any paradigm names
    paradigmKey = max(k, key=len)  #In case your filename contained more than one paradigm name, pick the longest one (to avoid substring problems)
    print 'using epoch key:', paradigmKey
    new_eve = eve_d[:]
    
    for type in rej_types:
        #get type from all_rej
        bname = op.basename(eve)
        base, _, _ = bname.rpartition('Mod.eve')
        search = op.join(rej_dir, '%s-Filtered_raw_%s.txt' % (base,type))
        #print 'Search:', search
        rej = glob(search)
        #print rej
        
        if len(rej) < 1:
           raise Exception('No rej of this type found!')
        print epochs[paradigmKey] ##print this line if you want to see what time samples are being used
        
        bad_dict = reject(type, epochs[paradigmKey], new_eve, readTable(rej[0]))
        #print bad_dict
        
        for code, r in bad_dict.items():
            f = lambda x:[x[0], x[1], x[2], str(int(type_rep[type])+int(code))] if x[3] == code and int(x[0]) in r else x
            new_eve[:] = map(f, new_eve)
        pass
    new_fname = op.join(eve_dir, '%s%s.eve' % (op.basename(eve).rpartition('.eve')[0], 'Rej'))
    print("Writing new eve to %s" % new_fname)
    writeTable(new_fname, new_eve)
    print
Example #2
0
def new_eve(eve):
    print 'Starting with %s' % eve
    eve_d = readTable(eve)
    rej_types = ('veog', 'heog')  # , 'grad', 'mag', 'eeg'
    k = filter(lambda y: y in eve, epochs.keys())[0]
    new_eve = eve_d[:]
    for type in rej_types:
        #get type from all_rej
        bname = op.basename(eve)
        base, _, _ = bname.rpartition('Mod.eve')
        search = op.join(temp_d, '%s_raw_%s.txt' % (base, type))
        rej = glob(search)
        if len(rej) < 1:
            raise Exception('No rej of this type found!')
        bad_dict = reject(type, epochs[k], new_eve, readTable(rej[0]))
        for code, r in bad_dict.items():
            f = lambda x: [
                x[0], x[1], x[2],
                str(int(type_rep[type]) + int(code))
            ] if x[3] == code and int(x[0]) in r else x
            new_eve[:] = map(f, new_eve)
        pass
    new_fname = op.join(
        eve_dir, '%s%s.eve' % (op.basename(eve).rpartition('.eve')[0], 'Rej'))
    print("Writing new eve to %s" % new_fname)
    writeTable(new_fname, new_eve)
def equalizeTriggers(subjID):    

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/"+subjID)
    
    expList = ['ATLLoc','MaskedMM','BaleenLP','BaleenHP','AXCPT']
    runDict = { 'ATLLoc':[''],'MaskedMM':['Run1','Run2'],'BaleenLP':['Run1','Run2','Run3','Run4'],'BaleenHP':['Run1','Run2','Run3','Run4'],'AXCPT':['Run1','Run2']}

    codeGroupDict = { 'AXCPT':['AXCPT_prime','AXCPT_target']}

    codeDict = { 'AXCPT_prime':['5','6'],'AXCPT_target':['1','2','3']}
    minDict = {}
    
    if subjID == 'ya3':
        runDict['AXCPT']=['Run1']
    if (subjID == 'ya1' or subjID == 'ya2' or subjID == 'ya4' or subjID == 'ya7' or subjID == 'ya8' or subjID == 'ya16'):
        runDict['AXCPT']=''
                
        
    #########################
    ##EQUALIZE TRIGGER COUNTS###
    print '----equalize triggers'
    for exp in expList:
        for codeGroup in codeGroupDict[exp]:
            evMin = 9999
            for code in codeDict[codeGroup]:
                    print int(code)-1
                    aveName = '/cluster/kuperberg/SemPrMM/MEG/data/%s/ave_projon/%s_%s_All-ave.fif' % (subjID, subjID, exp)
                    print aveName
                    evoked = fiff.Evoked(aveName,setno=int(code)-1) #needs revision
                    print evoked.nave
                    if int(evoked.nave) < evMin:
                        evMin = int(evoked.nave)
            minDict[codeGroup] = evMin
            print codeGroup, evMin, minDict[codeGroup]

            
        for run in runDict[exp]:
            inFile = 'eve/' + subjID + '_'+exp+run+'Mod.eve'
            outFile = 'eve/' + subjID + '_' + exp + run + 'Mod-testeq.eve' #when finalized, this should probably be ModRejEq.eve, and later scripts changed
            print inFile
            if os.path.exists(inFile):
                    data = readInput.readTable(inFile)
                    
                    firstRow = data[0]
                    firstSample = firstRow[0]
                    firstTime = firstRow[1]

                    flag = ''
                    
                    for row in data:
                        trigger = row[3]
                        time = row[1]


                    writeOutput.writeTable(outFile,data)
Example #4
0
def roistats2R(subj_gp, exp):

        tableLength=0
        dataTable=lineTemp=line=Con=dataLine=[]
        allData=[]
        Contrasts = []
        subj = []
        hem = ['lh', 'rh']
        roiName = []
        
        inFile = "/cluster/kuperberg/SemPrMM/MRI/results/roi_fsfast/roi_summary/" + subj_gp +"_" + exp +"FullTable.txt"
        dataTable = readInput.readTable(inFile)
        tableLength = len(dataTable)     
        
        ##parse the data to figure out number of contrasts, rois, and subjects
        for i in range(1, tableLength):   #skip the header row
            lineTemp = dataTable[i]
            Con = dataTable[0]
            if len(lineTemp)<6:
                   roiName.append(str(lineTemp[2]))
            elif len(lineTemp)>4:
                   subj.append(lineTemp[0])
                   
        subj_num = (len(subj)/len(roiName))
        
		##Get out the contrasts
        numContrasts = (len(Con)-1)/2   ##figure out how many contrasts there are
        for c in range(numContrasts):
        	conIndex = c*2+1
        	[Con[conIndex],x] = str.split(str(Con[conIndex]), '_')
        	Contrasts.append(Con[conIndex])
##        print Contrasts

        i = 0
        for i in range(1, tableLength):  #skip the header row
             line = dataTable[i]
             curr_subj = line[0]
             if len(line) < 4:  ##This is the beginning of a new label block so update current label
                          curr_label = line[2]
##                          print curr_label
             if len(line) > 4:
                          for c in range(numContrasts):
                                        for m in [0, 1]:
													curr_contrast = str(Contrasts[c])
													curr_hem = hem[m]
													curr_signal = line[c*2+1+m]  #for each contrast, this will find correct signal
##													print c*2+1+m
													dataLine = [curr_subj, curr_contrast, curr_label, curr_hem, curr_signal]
													allData.append(dataLine)
													dataLine = []
                                                        

        outFile = "/cluster/kuperberg/SemPrMM/MRI/results/roi_fsfast/R/" + subj_gp +"_" + exp + "_" + "roiTable.txt"                                              
        writeOutput.writeTable(outFile, allData)                                            
def rej_rej2eve_projon(subjID):

    filePrefix = '/cluster/kuperberg/SemPrMM/MEG/data/' + subjID

    ##expList = ['ATLLoc','MaskedMM','BaleenLP','BaleenHP','AXCPT']
    expList = ['BaleenHP']

    runDict = {
        'ATLLoc': [''],
        'MaskedMM': ['Run1', 'Run2'],
        'BaleenLP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'BaleenHP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'AXCPT': ['Run1', 'Run2']
    }

    for exp in expList:
        print exp
        for run in runDict[exp]:
            inFile1 = filePrefix + '/ave_projon/logs/ssp_avelogs/' + subjID + '_' + exp + run + '_ecgeog1-ave.log'
            inFile2 = filePrefix + '/eve/' + subjID + '_' + exp + run + 'ModRej.eve'
            outFile = filePrefix + '/eve/' + subjID + '_' + exp + run + 'ModRej4projoff.eve'
            ##                        print inFile1
            ##                        print inFile2
            ##                        print('Step1 done')
            if os.path.exists(outFile):
                os.remove(outFile)

            if os.path.exists(inFile1) and os.path.exists(inFile2):
                data1 = readInput.readTable(inFile1)
                rowsin1 = len(data1)
                data2 = readInput.readTable(inFile2)
                rowsin2 = len(data2)
                firstLine = data2[0]
                firstTimept = int((firstLine[0]))
                ##                        print(firstTimept)
                timept1 = timept2 = []
                for i in range(0, len(data1)):
                    lineTemp1 = data1[i]
                    if len(lineTemp1) > 10:
                        timept1.append((lineTemp1[0]))
                print(timept1)

                for i in range(0, len(data2)):
                    lineTemp2 = data2[i]
                    timeN = int(lineTemp2[0])
                    timept2 = str(timeN - firstTimept)
                    if str(timept2) in timept1:
                        lineTemp2[3] = 4000 + int(lineTemp2[3])

                writeOutput.writeTable(outFile, data2)
def  rej_rej2eve_projon(subjID):
	
	filePrefix = '/cluster/kuperberg/SemPrMM/MEG/data/'+subjID
	
	##expList = ['ATLLoc','MaskedMM','BaleenLP','BaleenHP','AXCPT']
	expList = ['BaleenHP']
	
	runDict = {'ATLLoc':[''],'MaskedMM':['Run1','Run2'],'BaleenLP':['Run1','Run2','Run3','Run4'],'BaleenHP':['Run1','Run2','Run3','Run4'], 'AXCPT':['Run1','Run2']}
	

	for exp in expList:
                print exp
                for run in runDict[exp]:
                        inFile1 = filePrefix + '/ave_projon/logs/ssp_avelogs/' + subjID + '_' + exp + run + '_ecgeog1-ave.log'
                        inFile2 = filePrefix + '/eve/' + subjID + '_' + exp + run + 'ModRej.eve'
                        outFile = filePrefix + '/eve/' + subjID + '_' + exp + run + 'ModRej4projoff.eve'
##                        print inFile1
##                        print inFile2
##                        print('Step1 done')
                        if os.path.exists(outFile):
                                os.remove(outFile)
                        
                        if os.path.exists(inFile1) and os.path.exists(inFile2):
                                data1 = readInput.readTable(inFile1)
                                rowsin1 = len(data1)
                                data2 = readInput.readTable(inFile2)
                                rowsin2 = len(data2)
                                firstLine = data2[0]
                                firstTimept = int((firstLine[0]))
                ##                        print(firstTimept)
                                timept1=timept2=[]
                                for i in range (0, len(data1)):
                                        lineTemp1 = data1[i]
                                        if len(lineTemp1) > 10:
                                                timept1.append((lineTemp1[0]))
                                print(timept1)

                                for i in range (0, len(data2)):
                                        lineTemp2 = data2[i]
                                        timeN = int(lineTemp2[0])
                                        timept2= str(timeN - firstTimept)
                                        if str(timept2) in timept1:
                                                lineTemp2[3] = 4000 + int(lineTemp2[3])

                                writeOutput.writeTable(outFile,data2)
def binary_conversion(exp, subjID, paradigm):

	maxCount = 16777215  #2^24-1, because we use 24 good triggers (162-187, excluding 176 and 177; could go to 188 but more than 2^24 screws MNE conversion)
	filePath = '/Volumes/CUTTLEFISH/MEG_Experiments/'+exp+'/data/' #Lawrence added 'Experiments' 4.23.13
	
	trigSeqDict = {1:162,2:163,3:164,4:165,5:166,6:167,7:168,8:169,9:170,10:171,11:172,12:173,13:174,14:175,15:178,16:179,17:180,18:181,19:182,20:183,21:184,22:185,23:186,24:187}
	
	binaryDict = {maxCount-2**0:1,maxCount-2**1:2,maxCount-2**2:3,maxCount-2**3:4,maxCount-2**4:5,maxCount-2**5:6,maxCount-2**6:7,maxCount-2**7:8,maxCount-2**8:9,maxCount-2**9:10,maxCount-2**10:11,maxCount-2**11:12,maxCount-2**12:13,maxCount-2**13:14,maxCount-2**14:15,maxCount-2**15:16,maxCount-2**16:17,maxCount-2**17:18,maxCount-2**18:19,maxCount-2**19:20,maxCount-2**20:21,maxCount-2**21:22,maxCount-2**22:23,maxCount-2**23:24}
	
	count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
	
	#print binaryDict
	inFile = filePath + subjID + '/eve/' + subjID + '_' + paradigm + '.eve'
	outFile = filePath + subjID + '/eve/' + subjID + '_' + paradigm + 'Mod.eve'

	eveData = readInput.readTable(inFile)
	
	for row in eveData:
		#print row
		if (not row[3] == str(maxCount)) and (not row[3] == '0'):
			#print row
			code = binaryDict[int(row[3])]
			#print trigSeqDict[code]
			count[code-1] = count[code-1]+1
			row[3] = trigSeqDict[code]
			row[2] = 0
	
	for row in eveData:
		if row[3] == str(maxCount):
			#print 'catch'
			eveData.remove(row)
			
	writeOutput.writeTable(outFile,eveData)		
			
	print count
	i=0
	for item in count:
		i = i+1
		print "trigger_"+str(i)+" = "+str(item)
Example #8
0
def new_eve(eve):
    print 'Starting with %s' % eve
    eve_d = readTable(eve)
    rej_types = ('veog', 'heog') # , 'grad', 'mag', 'eeg'
    k = filter(lambda y: y in eve, epochs.keys())[0]
    new_eve = eve_d[:]
    for type in rej_types:
        #get type from all_rej
        bname = op.basename(eve)
        base, _, _ = bname.rpartition('Mod.eve')
        search = op.join(temp_d, '%s_raw_%s.txt' % (base,type))
        rej = glob(search)
        if len(rej) < 1:
            raise Exception('No rej of this type found!')
        bad_dict = reject(type, epochs[k], new_eve, readTable(rej[0]))
        for code, r in bad_dict.items():
            f = lambda x:[x[0], x[1], x[2], str(int(type_rep[type])+int(code))] if x[3] == code and int(x[0]) in r else x
            new_eve[:] = map(f, new_eve)
        pass
    new_fname = op.join(eve_dir, '%s%s.eve' % (op.basename(eve).rpartition('.eve')[0], 'Rej'))
    print("Writing new eve to %s" % new_fname)
    writeTable(new_fname, new_eve)
Example #9
0
def fixTriggersAllUnrelated(subjID):

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/" + subjID)

    expList = ['BaleenLP', 'BaleenHP']

    runDict = {
        'BaleenLP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'BaleenHP': ['Run1', 'Run2', 'Run3', 'Run4']
    }

    ###############################################
    #BALEEN Change all codes to Unrelated

    for exp in expList:
        for run in runDict[exp]:
            inFile = 'eve/' + subjID + '_' + exp + run + 'ModRej.eve'
            outFile = 'eve/' + subjID + '_' + exp + run + 'ModRejAllU.eve'
            if os.path.exists(inFile):
                data = readInput.readTable(inFile)

                rowCount = 0
                flag2 = 0
                for row in data:
                    trigger = row[3]

                    #BaleenLP
                    if trigger == '2':
                        row[3] = '4'

                    #BaleenHP

                    if trigger == '7':
                        row[3] = '9'

                    rowCount += 1

                writeOutput.writeTable(outFile, data)
def fixTriggersAllUnrelated(subjID):    

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/"+subjID)
    
    expList = ['BaleenLP','BaleenHP']
    
    runDict = {'BaleenLP':['Run1','Run2','Run3','Run4'],'BaleenHP':['Run1','Run2','Run3','Run4']}
    
        
    ###############################################
    #BALEEN Change all codes to Unrelated 
    
    for exp in expList:
        for run in runDict[exp]:
			inFile = 'eve/'+subjID+'_'+exp+run+'ModRej.eve'
			outFile = 'eve/'+subjID+'_'+exp+run+'ModRejAllU.eve'
			if os.path.exists(inFile):
				data = readInput.readTable(inFile)
				
				rowCount = 0
				flag2 = 0
				for row in data:
					trigger = row[3]
					
					#BaleenLP
					if trigger == '2':
						row[3] = '4'
					
					#BaleenHP

					if trigger == '7':
						row[3] = '9'
						
					rowCount +=1
				
				writeOutput.writeTable(outFile, data)
##You should only check samples 100ms from beginning/end of file, to have the full window
samples2Check = range(winSizeSamp,len(times)-winSizeSamp) 

for currSample in samples2Check:
	preWinMean = np.mean( blink_data_rms[currSample-winSizeSamp : currSample] )	
	postWinMean = np.mean( blink_data_rms[currSample : currSample+winSizeSamp] ) 

	stepTest = postWinMean - preWinMean    
	
	if stepTest > thresh or stepTest < -thresh:
		badSample = currSample 
		badSampleList.append([badSample,3]) #The 3 should be deprecated once we fully shift to this script
		

##Write out text file containing rejected samples
writeOutput.writeTable(outfile_fname, badSampleList)
print
print 'Artifact rejection complete'
print

##Run rej_blink2eve.py which applies the rejected samples to marking rejected epochs in eve file

import rej_blink2eve
rej_blink2eve.main(args.exp, args.subjID, args.par)


##Make a plot of the RMS
cm = plt.get_cmap('cool') # this chooses the colors to use for data lines
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(times[0:50000],blink_data_rms[0:50000],linewidth=2)
	#label = 'S_temporal_sup-'+hem
	#label = 'G_pariet_inf-Angular-'+hem
	
	#values, times, vertices = mne.label_time_courses(label_fname, stc_fname)
	
	#vtv = [mne.label_time_courses(label_fname, stc_fname) for stc_fname in stcs_fname]
	
	valuesAll = []
	for stc_fname in stcs_fname:
		values, times, vertices = mne.label_time_courses(label_fname, stc_fname)
		values = np.mean(values,0)
		values = values[sample1:sample2]
		values = np.mean(values,0)
		#print values
		valuesAll.append(values)
	valuesHem.append(valuesAll)
	print "mean",np.mean(valuesAll)

outTable = []
for x in range(len(stcs_fname)):
	temp = []
	temp.append(valuesHem[0][x])
	temp.append(valuesHem[1][x])
	temp.append(valuesHem[0][x]-valuesHem[1][x])
	outTable.append(temp)


outFile = '/cluster/kuperberg/SemPrMM/MEG/results/source_space/hem_measures/ya.n'+str(len(stcs_fname))+'.'+args.protocol+'_c'+args.set+'_'+args.label+str(int(args.t1))+'-'+str(int(args.t2))+'.txt'
writeOutput.writeTable(outFile, outTable)

Example #13
0
def equalizeTriggers(subjID):

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/" + subjID)

    expList = ['ATLLoc', 'MaskedMM', 'BaleenLP', 'BaleenHP', 'AXCPT']
    runDict = {
        'ATLLoc': [''],
        'MaskedMM': ['Run1', 'Run2'],
        'BaleenLP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'BaleenHP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'AXCPT': ['Run1', 'Run2']
    }

    codeGroupDict = {'AXCPT': ['AXCPT_prime', 'AXCPT_target']}

    codeDict = {'AXCPT_prime': ['5', '6'], 'AXCPT_target': ['1', '2', '3']}
    minDict = {}

    if subjID == 'ya3':
        runDict['AXCPT'] = ['Run1']
    if (subjID == 'ya1' or subjID == 'ya2' or subjID == 'ya4'
            or subjID == 'ya7' or subjID == 'ya8' or subjID == 'ya16'):
        runDict['AXCPT'] = ''

    #########################
    ##EQUALIZE TRIGGER COUNTS###
    print '----equalize triggers'
    for exp in expList:
        for codeGroup in codeGroupDict[exp]:
            evMin = 9999
            for code in codeDict[codeGroup]:
                print int(code) - 1
                aveName = '/cluster/kuperberg/SemPrMM/MEG/data/%s/ave_projon/%s_%s_All-ave.fif' % (
                    subjID, subjID, exp)
                print aveName
                evoked = fiff.Evoked(aveName,
                                     setno=int(code) - 1)  #needs revision
                print evoked.nave
                if int(evoked.nave) < evMin:
                    evMin = int(evoked.nave)
            minDict[codeGroup] = evMin
            print codeGroup, evMin, minDict[codeGroup]

        for run in runDict[exp]:
            inFile = 'eve/' + subjID + '_' + exp + run + 'Mod.eve'
            outFile = 'eve/' + subjID + '_' + exp + run + 'Mod-testeq.eve'  #when finalized, this should probably be ModRejEq.eve, and later scripts changed
            print inFile
            if os.path.exists(inFile):
                data = readInput.readTable(inFile)

                firstRow = data[0]
                firstSample = firstRow[0]
                firstTime = firstRow[1]

                flag = ''

                for row in data:
                    trigger = row[3]
                    time = row[1]

                writeOutput.writeTable(outFile, data)
Example #14
0
def fixTriggers(subjID):

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/" + subjID)

    expList = ['ATLLoc', 'MaskedMM', 'BaleenLP', 'BaleenHP', 'AXCPT']

    runDict = {
        'ATLLoc': [''],
        'MaskedMM': ['Run1', 'Run2'],
        'BaleenLP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'BaleenHP': ['Run1', 'Run2', 'Run3', 'Run4'],
        'AXCPT': ['Run1', 'Run2']
    }

    if subjID == 'ya3':
        runDict['AXCPT'] = ['Run1']

    if (subjID == 'ya1' or subjID == 'ya2' or subjID == 'ya4'
            or subjID == 'ya7' or subjID == 'ya8' or subjID == 'ya16'):
        runDict['AXCPT'] = ''

    print '----subject specific fixes'

    #########################
    ##FIX RANDOM YA19 ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile = 'eve/ya19_BaleenLPRun2.eve'
    outFile = 'eve/ya19_BaleenLPRun2.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for row in data:
            trigger = row[3]
            time = row[1]
            if (time == '162.257' and trigger == '2'):
                print row
                row[3] = 14
                print row
        writeOutput.writeTable(outFile, data)

###########################FIX RANDOM YA22 ERROR
##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile = 'eve/ya22_BaleenHPRun3.eve'
    outFile = 'eve/ya22_BaleenHPRun3.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for row in data:
            trigger = row[3]
            time = row[1]
            if (time == '71.100' and trigger == '6'):
                print row
                row[3] = 14
                print row
        writeOutput.writeTable(outFile, data)

    #########################
    ##FIX RANDOM YA6 ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    ##NOt clear what this code was originally so changing to 600
    inFile = 'eve/ya6_BaleenHPRun3.eve'
    outFile = 'eve/ya6_BaleenHPRun3.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for row in data:
            trigger = row[3]
            time = row[1]
            if (time == '163.827' and trigger == '6'):
                print row
                row[3] = 600
                print row
            writeOutput.writeTable(outFile, data)

    #########################
    ##FIX RANDOM YA16 MASKEDMM ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile = 'eve/ya16_MaskedMMRun1.eve'
    outFile = 'eve/ya16_MaskedMMRun1.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for row in data:
            trigger = row[3]
            time = row[1]
            if (time == '232.349' and trigger == '2'):
                print row
                row[3] = 3
                print row
        writeOutput.writeTable(outFile, data)

##########################
##FIX UNKNOWN YA3 LPRUN3 ERROR
#Although no documentation to explain, vtsd logs and raw datafiles show run3 restarted after one minute (54 events), so responses to the stimuli that had already been shown should not be counted.

    inFile = 'eve/ya3_BaleenLPRun3.eve'
    outFile = 'eve/ya3_BaleenLPRun3.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for i in range(1, 54):
            row = data[i]
            row[3] = int(row[3]) + 900
        writeOutput.writeTable(outFile, data)

##########################
##FIX YA24 MASKEDMMRUN1 LOSS OF DISPLAY ERROR
#Scan log notes that MaskedMMRun1 was ended early because display got disconnected. This probably happened several seconds before presentation was ended. The last moment at which the subject responded was 316.707, so to be conservative we are removing triggers in the 16 subsequent seconds, in which the subject did not respond to several probe trials

    inFile = 'eve/ya24_MaskedMMRun1.eve'
    outFile = 'eve/ya24_MaskedMMRun1.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        for row in data:
            trigger = row[3]
            time = row[1]
            if (float(time) > 316.707):
                row[3] = int(row[3]) + 900
                print row
        writeOutput.writeTable(outFile, data)

    #########################
    ##FIX TIMING IN ALL SCRIPTS###
    print '----fix Timing'
    for exp in expList:
        for run in runDict[exp]:
            inFile = 'eve/' + subjID + '_' + exp + run + '.eve'
            outFile = 'eve/' + subjID + '_' + exp + run + 'Mod.eve'
            print inFile
            if os.path.exists(inFile):
                data = readInput.readTable(inFile)

                firstRow = data[0]
                firstSample = firstRow[0]
                firstTime = firstRow[1]

                wordCount = 0  ##for ATLLoc
                flag = ''

                for row in data:
                    trigger = row[3]
                    time = row[1]
                    sampleRate = float(row[0]) / float(row[1])
                    trueSample = float(
                        row[0]
                    ) + 19  ## compensate for the time lag between projector and trigger
                    trueTime = trueSample / sampleRate
                    row[0] = str(int(round(trueSample, 0)))
                    row[1] = str(round(trueTime, 3))
                    finalRow = row

                ##Undo the timing change for the first row in file because this row indicates the beginning of the scan, not a visual event, so it shouldn't be changed

                firstRow[0] = firstSample
                firstRow[1] = firstTime

                ###add extra trigger to get around MNE bug that ignores last row
                extraRow = [
                    str(int(finalRow[0]) + 1),
                    str(round(float(finalRow[1]) + 1, 3)), '0', '99'
                ]
                data.append(extraRow)
                writeOutput.writeTable(outFile, data)

    print '-----fix codes'

    ###############################
    ###CHANGE CODES IN ATLLOC
    inFile = 'eve/' + subjID + '_ATLLocMod.eve'
    outFile = 'eve/' + subjID + '_ATLLocMod.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        print inFile
        wordCount = 0
        flag = ''

        for row in data:
            trigger = row[3]

            if trigger == '1' or trigger == '2' or trigger == '3':
                flag = trigger
                wordCount = 0
            else:
                wordCount += 1

            if trigger == '4' and wordCount <= 9:
                row[3] = trigger + flag

        writeOutput.writeTable(outFile, data)

    ###############################################
    #MASKEDMM

    for x in runDict['MaskedMM']:
        inFile = 'eve/' + subjID + '_MaskedMM' + x + 'Mod.eve'
        outFile = 'eve/' + subjID + '_MaskedMM' + x + 'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile

            ########################
            ##Change trigger for incorrect button presses ('go' responses)
            rowCount = 0
            for row in data:
                trigger = row[3]
                if (trigger == '1' or trigger == '2' or trigger == '3'):
                    nextRow = data[rowCount + 1]
                    nextTrigger = nextRow[3]
                    #print 'hello', trigger, row, nextRow
                    if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
                        print "false positive: ", row, nextRow
                        row[3] = '500' + row[3]
                rowCount += 1

    ###############################################
    #BALEENLP

    for x in runDict['BaleenLP']:
        inFile = 'eve/' + subjID + '_BaleenLP' + x + 'Mod.eve'
        outFile = 'eve/' + subjID + '_BaleenLP' + x + 'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            rowCount = 0
            for row in data:
                trigger = row[3]

                ##This part fixes the coding for the probe primes. Originally the trigger 11 was sent for the target when the prime was a probe. This recodes the target as 111 and codes the prime itself as 11
                if trigger == '11':  ##change the target to '111'
                    row[3] = '1' + trigger
                    #print row

                    for i in [
                            1, 2, 3
                    ]:  ## look through the previous three events to try to find the prime
                        compRow = data[rowCount - i]
                        #print 'Comparison', compRow

                        compTrigger = compRow[3]
                        compSOA = float(row[1]) - float(compRow[1])
                        if compTrigger == '14' and (
                                compSOA > .580 and compSOA < .620
                        ):  ##check for a prime with correct SOA
                            compRow[3] = trigger
                            #print 'new ', compRow, row
                            break

                rowCount += 1

            ########################
            ##Change trigger for incorrect button presses ('go' responses)
            rowCount = 0
            for row in data:
                trigger = row[3]
                if (trigger == '1' or trigger == '2' or trigger == '4'):
                    nextRow = data[rowCount + 1]
                    nextTrigger = nextRow[3]
                    #print row, nextRow
                    if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
                        print "false positive: ", row, nextRow
                        row[3] = '500' + row[3]
                rowCount += 1

            writeOutput.writeTable(outFile, data)

    ###############################################
    #BALEENHP

    for x in runDict['BaleenHP']:
        inFile = 'eve/' + subjID + '_BaleenHP' + x + 'Mod.eve'
        outFile = 'eve/' + subjID + '_BaleenHP' + x + 'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            rowCount = 0
            flag2 = 0
            for row in data:
                trigger = row[3]

                if trigger == '12':  ##change the target to '112'
                    row[3] = '1' + trigger
                    #print row

                    for i in [
                            1, 2, 3
                    ]:  ## look through the previous three events to try to find the prime
                        compRow = data[rowCount - i]
                        #print 'Comparison', compRow

                        compTrigger = compRow[3]
                        compSOA = float(row[1]) - float(compRow[1])
                        if compTrigger == '14' and (
                                compSOA > .580 and compSOA < .620
                        ):  ##check for a prime with correct SOA
                            compRow[3] = trigger
                            #print 'new ', compRow, row
                            break

                ##Flip half of the related filler triggers to '18' to get equal number of related and unrelated
                if trigger == '8':
                    if flag2 == 1:
                        row[3] = '18'
                        flag2 = 0
                    elif flag2 == 0:
                        flag2 = 1

                rowCount += 1

            ########################
            ##Change trigger for incorrect button presses ('go' responses)
            rowCount = 0
            for row in data:
                trigger = row[3]

                if (trigger == '6' or trigger == '7' or trigger == '8'
                        or trigger == '9' or trigger == '18'):
                    nextRow = data[rowCount + 1]
                    nextTrigger = nextRow[3]
                    #print row, nextRow
                    if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
                        print "false positive: ", row, nextRow
                        row[3] = '500' + row[3]
                rowCount += 1

            ##########################################write it all out
            writeOutput.writeTable(outFile, data)

    #########################
    ###AXCPT

    for x in runDict['AXCPT']:
        x
        inFile = 'eve/' + subjID + '_AXCPT' + x + 'Mod.eve'
        outFile = 'eve/' + subjID + '_AXCPT' + x + 'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            ###############################################################
            if subjID == 'ya6':  ####Fix error in triggers for this subject
                logFile = '../../vtsd_logs/ya6/AXCPT_ya6_List101_' + x + '.vtsd_log'
                print logFile
                logData = readInput.readTable(logFile)
                firstPrimeRow = data[2]
                firstPrimeTime = firstPrimeRow[1]
                count = 0

                ##Fix timing due to error in trigger coding
                for row in data:
                    trueTime = round(float(row[1]) - float(firstPrimeTime))
                    if row[3] == '8':
                        for logRow in logData:
                            logTime = round(float(logRow[5]) + 1)
                            if logTime == trueTime:
                                #print logRow[5], logTime, trueTime, row[3], logRow[9]
                                row[3] = logRow[9]
                                #print logRow
            ################################################################

            rowCount = 0
            flag3 = 0
            for row in data:
                trigger = row[3]
                if len(data) > rowCount + 1:
                    nextRow = data[rowCount + 1]
                    nextTrigger = nextRow[3]
                else:
                    break

                #############################################
                ##change blinks triggered as 6 to 7s

                if trigger == '6':
                    if nextTrigger == '7':
                        row[3] = '7'


##                #################################################
##                ##Flip 3/4 of the 'A' triggers to 15, to match number of As and Bs
##                if trigger == '5':
##                    if flag3 == 3:
##                        flag3 = 0
##                    elif flag3 != 3:
##                        flag3 = flag3 + 1
##                        row[3] = '15'
##
###########################################
##change triggers for incorrect trials#####

##AX case
                if trigger == '4':
                    if len(nextTrigger
                           ) < 2:  ###Test for response (16, 32, 64 or 128)
                        row[3] = '9' + trigger
                        print 'miss:', row

                ##BX, BY, AY case
                if (trigger == '1' or trigger == '2' or trigger == '3'):

                    if len(nextTrigger
                           ) > 1:  ###Test for response (16, 32, 64 or 128)
                        row[3] = '9' + trigger
                        print 'false positive:', row

                rowCount += 1

            writeOutput.writeTable(outFile, data)
	print protocolList[x]
	
	for label in labelList:
		for hem in hemList:
		
			stcs_fname = ['/cluster/kuperberg/SemPrMM/MEG/data/ya%s/ave_projon/stc/%s/ya%s_%s_c%sM-%s-%s.stc' % (s, protocolList[x], s, protocolList[x],condList[x],args.model,hem) for s in subjects]
			
			label_fname = data_path + '/label/%s-%s.label' % (label, hem)
			if os.access(label_fname, os.F_OK):
				print label, hem
				valuesAll = []
				for stc_fname in stcs_fname:
					values, times, vertices = mne.label_time_courses(label_fname, stc_fname)
					values = np.mean(values,0)
					values = values[sample1:sample2]
					values = np.mean(values,0)
					valuesAll.append(values)
					
				##Update output table	
				count = 0
				for s in subjects:
					data = valuesAll[count]
					row = [s, protocolList[x]+condList[x], label, hem, data]
					dataTable.append(row)
					count = count + 1
		
fileName = '/cluster/kuperberg/SemPrMM/MEG/results/source_space/R/'+args.prefix+'.MaskedMMAll.'+args.model+'.'+str(int(args.t1))+'-'+str(int(args.t2))+'.txt'

writeOutput.writeTable(fileName, dataTable)

Example #16
0
def fixTriggers(subjID):    

    os.chdir("/cluster/kuperberg/SemPrMM/MEG/data/"+subjID)
    
    expList = ['ATLLoc','MaskedMM','BaleenLP','BaleenHP','AXCPT']
    
    runDict = { 'ATLLoc':[''],'MaskedMM':['Run1','Run2'],'BaleenLP':['Run1','Run2','Run3','Run4'],'BaleenHP':['Run1','Run2','Run3','Run4'],'AXCPT':['Run1','Run2']}
    
    if subjID == 'ya3':
        runDict['AXCPT']=['Run1']

        
    if (subjID == 'ya1' or subjID == 'ya2' or subjID == 'ya4' or subjID == 'ya7' or subjID == 'ya8' or subjID == 'ya16'):
        runDict['AXCPT']=''
    
    print '----subject specific fixes'
    
        
        
    #########################
    ##FIX RANDOM YA19 ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile= 'eve/ya19_BaleenLPRun2.eve'
    outFile = 'eve/ya19_BaleenLPRun2.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for row in data:
    		trigger = row[3]
    		time = row[1]
    		if (time == '162.257' and trigger == '2'):
    			print row
    			row[3] = 14
    			print row
    	writeOutput.writeTable(outFile,data)		

 
	###########################FIX RANDOM YA22 ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile= 'eve/ya22_BaleenHPRun3.eve'
    outFile = 'eve/ya22_BaleenHPRun3.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for row in data:
    		trigger = row[3]
    		time = row[1]
    		if (time == '71.100' and trigger == '6'):
    			print row
    			row[3] = 14
    			print row
    	writeOutput.writeTable(outFile,data)		

    #########################
    ##FIX RANDOM YA6 ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    ##NOt clear what this code was originally so changing to 600
    inFile= 'eve/ya6_BaleenHPRun3.eve'
    outFile = 'eve/ya6_BaleenHPRun3.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for row in data:
    		trigger = row[3]
    		time = row[1]
    		if (time == '163.827' and trigger == '6'):
    			print row
    			row[3] = 600
    			print row
    		writeOutput.writeTable(outFile,data)
    		
    #########################
    ##FIX RANDOM YA16 MASKEDMM ERROR
    ##This is only case where original .eve files gets changed, because somehow incorrect trigger got sent on a single trial (how could this happen? spooky)
    inFile= 'eve/ya16_MaskedMMRun1.eve'
    outFile = 'eve/ya16_MaskedMMRun1.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for row in data:
    		trigger = row[3]
    		time = row[1]
    		if (time == '232.349' and trigger == '2'):
    			print row
    			row[3] = 3
    			print row
    	writeOutput.writeTable(outFile,data)	
    
	##########################
	##FIX UNKNOWN YA3 LPRUN3 ERROR
	#Although no documentation to explain, vtsd logs and raw datafiles show run3 restarted after one minute (54 events), so responses to the stimuli that had already been shown should not be counted. 
	
    inFile = 'eve/ya3_BaleenLPRun3.eve'
    outFile = 'eve/ya3_BaleenLPRun3.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for i in range(1,54):
    		row = data[i]
    		row[3] = int(row[3])+900
    	writeOutput.writeTable(outFile,data)	
    	
    	
	##########################
	##FIX YA24 MASKEDMMRUN1 LOSS OF DISPLAY ERROR
	#Scan log notes that MaskedMMRun1 was ended early because display got disconnected. This probably happened several seconds before presentation was ended. The last moment at which the subject responded was 316.707, so to be conservative we are removing triggers in the 16 subsequent seconds, in which the subject did not respond to several probe trials
	
    inFile= 'eve/ya24_MaskedMMRun1.eve'
    outFile = 'eve/ya24_MaskedMMRun1.eve'
    if os.path.exists(inFile):
    	data = readInput.readTable(inFile)
    	for row in data:
    		trigger = row[3]
    		time = row[1]
    		if (float(time) > 316.707):
    			row[3] = int(row[3])+900
    			print row
    	writeOutput.writeTable(outFile,data)	
	
    	
    	
    	
    	
    	
    	
    #########################
    ##FIX TIMING IN ALL SCRIPTS###
    print '----fix Timing'
    for exp in expList:
        for run in runDict[exp]:
                inFile = 'eve/' + subjID + '_'+exp+run+'.eve'
                outFile = 'eve/' + subjID + '_' + exp + run + 'Mod.eve'
                print inFile
                if os.path.exists(inFile):
                    data = readInput.readTable(inFile)
                    
                    firstRow = data[0]
                    firstSample = firstRow[0]
                    firstTime = firstRow[1]
                    
                    wordCount = 0   ##for ATLLoc
                    flag = ''
                    
                    for row in data:
                        trigger = row[3]
                        time = row[1]   
                        sampleRate = float(row[0])/float(row[1])
                        trueSample = float(row[0]) + 19 ## compensate for the time lag between projector and trigger
                        trueTime = trueSample/sampleRate
                        row[0] = str(int(round(trueSample,0)))
                        row[1] = str(round(trueTime,3))
                        finalRow = row
                
                    ##Undo the timing change for the first row in file because this row indicates the beginning of the scan, not a visual event, so it shouldn't be changed
                        
                    firstRow[0] = firstSample
                    firstRow[1] = firstTime
    
                    ###add extra trigger to get around MNE bug that ignores last row
                    extraRow = [str(int(finalRow[0])+1),str(round(float(finalRow[1])+1,3)),'0','99']
                    data.append(extraRow)
                    writeOutput.writeTable(outFile,data)
        
        
    print '-----fix codes'    
    
        
        
    ###############################
    ###CHANGE CODES IN ATLLOC
    inFile = 'eve/' + subjID + '_ATLLocMod.eve'
    outFile = 'eve/' + subjID + '_ATLLocMod.eve'
    if os.path.exists(inFile):
        data = readInput.readTable(inFile)
        print inFile
        wordCount = 0
        flag = ''
        
        for row in data:
            trigger = row[3]
    
            if trigger == '1' or trigger == '2' or trigger == '3':
                flag = trigger
                wordCount = 0
            else: wordCount +=1
        
            if trigger == '4' and wordCount <= 9:
                row[3] = trigger+flag
        
        writeOutput.writeTable(outFile,data)
        
    ###############################################
    #MASKEDMM
    
    for x in runDict['MaskedMM']:
    	inFile = 'eve/'+subjID+'_MaskedMM'+x+'Mod.eve'
    	outFile = 'eve/'+subjID+'_MaskedMM'+x+'Mod.eve'
    	if os.path.exists(inFile):
    		data = readInput.readTable(inFile)
    		print inFile
    		
    		########################
    		##Change trigger for incorrect button presses ('go' responses)
    		rowCount = 0
    		for row in data:
    			trigger = row[3]
    			if (trigger == '1' or trigger == '2' or trigger == '3'):
    				nextRow = data[rowCount+1]
    				nextTrigger = nextRow[3]
    				#print 'hello', trigger, row, nextRow
    				if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
    					print "false positive: ", row, nextRow
    					row[3] = '500' + row[3]
    			rowCount +=1

    
    
    ###############################################
    #BALEENLP
    
    for x in runDict['BaleenLP']:
        inFile = 'eve/'+subjID+'_BaleenLP'+x+'Mod.eve'
        outFile = 'eve/'+subjID+'_BaleenLP'+x+'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            rowCount = 0
            for row in data:
                trigger = row[3]
                
                ##This part fixes the coding for the probe primes. Originally the trigger 11 was sent for the target when the prime was a probe. This recodes the target as 111 and codes the prime itself as 11
                if trigger == '11':   ##change the target to '111'
                    row[3] = '1'+trigger
                    #print row
                    
                    for i in [1,2,3]:                 ## look through the previous three events to try to find the prime
                        compRow = data[rowCount-i]
                        #print 'Comparison', compRow
        
                        compTrigger = compRow[3]
                        compSOA = float(row[1])-float(compRow[1])
                        if compTrigger == '14' and ( compSOA > .580 and compSOA < .620 ):  ##check for a prime with correct SOA
                            compRow[3] = trigger
                            #print 'new ', compRow, row
                            break
                    
                rowCount +=1
                
            ########################
            ##Change trigger for incorrect button presses ('go' responses)
            rowCount = 0
            for row in data:
                trigger = row[3]
                if (trigger == '1' or trigger == '2' or trigger == '4'):
                	nextRow = data[rowCount+1]
                	nextTrigger = nextRow[3]
                	#print row, nextRow
                	if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
                		print "false positive: ", row, nextRow
                		row[3] = '500' + row[3]
                rowCount +=1

            writeOutput.writeTable(outFile, data)

    ###############################################
    #BALEENHP
    
    for x in runDict['BaleenHP']:
        inFile = 'eve/'+subjID+'_BaleenHP'+x+'Mod.eve'
        outFile = 'eve/'+subjID+'_BaleenHP'+x+'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            rowCount = 0
            flag2 = 0
            for row in data:
                trigger = row[3]
                
                if trigger == '12':   ##change the target to '112'
                    row[3] = '1'+trigger
                    #print row
                    
                    for i in [1,2,3]:                 ## look through the previous three events to try to find the prime
                        compRow = data[rowCount-i]
                        #print 'Comparison', compRow
        
                        compTrigger = compRow[3]
                        compSOA = float(row[1])-float(compRow[1])
                        if compTrigger == '14' and ( compSOA > .580 and compSOA < .620 ):  ##check for a prime with correct SOA
                            compRow[3] = trigger
                            #print 'new ', compRow, row
                            break
                    
                ##Flip half of the related filler triggers to '18' to get equal number of related and unrelated
                if trigger == '8':
                    if flag2 == 1:
                        row[3] = '18'
                        flag2 = 0
                    elif flag2 == 0:
                        flag2 = 1   
                                            
                rowCount +=1          
            
            ########################
            ##Change trigger for incorrect button presses ('go' responses)
            rowCount = 0
            for row in data:
                trigger = row[3]

                if (trigger == '6' or trigger == '7' or trigger == '8' or trigger == '9' or trigger == '18'):
                	nextRow = data[rowCount+1]
                	nextTrigger = nextRow[3]
                	#print row, nextRow
                	if nextTrigger == '16' or nextTrigger == '32' or nextTrigger == '64' or nextTrigger == '128':
                		print "false positive: ", row, nextRow
                		row[3] = '500' + row[3]
                rowCount +=1
                		
                            
            ##########################################write it all out    
            writeOutput.writeTable(outFile, data)


    #########################   
    ###AXCPT
            
    for x in runDict['AXCPT']:
        x
        inFile = 'eve/'+subjID+'_AXCPT'+x+'Mod.eve'
        outFile = 'eve/'+subjID+'_AXCPT'+x+'Mod.eve'
        if os.path.exists(inFile):
            data = readInput.readTable(inFile)
            print inFile
            ###############################################################
            if subjID == 'ya6':  ####Fix error in triggers for this subject
                logFile = '../../vtsd_logs/ya6/AXCPT_ya6_List101_'+x+'.vtsd_log'
                print logFile
                logData = readInput.readTable(logFile)
                firstPrimeRow = data[2]
                firstPrimeTime = firstPrimeRow[1]       
                count = 0
                
                ##Fix timing due to error in trigger coding
                for row in data:
                    trueTime =  round(float(row[1]) - float(firstPrimeTime))
                    if row[3] == '8':
                        for logRow in logData:
                            logTime = round(float(logRow[5])+1)
                            if logTime == trueTime:
                                #print logRow[5], logTime, trueTime, row[3], logRow[9]
                                row[3] = logRow[9]
                                #print logRow
            ################################################################
    
            rowCount = 0
            flag3 = 0
            for row in data:
                trigger = row[3]
                if len(data) > rowCount +1:
                    nextRow = data[rowCount+1]
                    nextTrigger = nextRow[3]
                else:
                    break
        
                #############################################
                ##change blinks triggered as 6 to 7s
                
                if trigger == '6':   
                    if nextTrigger == '7':  
                            row[3] = '7'
                
##                #################################################
##                ##Flip 3/4 of the 'A' triggers to 15, to match number of As and Bs
##                if trigger == '5':
##                    if flag3 == 3:
##                        flag3 = 0
##                    elif flag3 != 3:
##                        flag3 = flag3 + 1   
##                        row[3] = '15'
##                                    
                ###########################################
                ##change triggers for incorrect trials#####
                
                ##AX case
                if trigger == '4': 
                     if len(nextTrigger) < 2:  ###Test for response (16, 32, 64 or 128)
                         row[3] = '9' + trigger
                         print 'miss:',row
                        
                ##BX, BY, AY case
                if (trigger == '1' or trigger == '2' or trigger == '3'):
                     
                     if len(nextTrigger) > 1:  ###Test for response (16, 32, 64 or 128)
                         row[3] = '9' + trigger
                         print 'false positive:',row
                             
                rowCount +=1
            
            
            writeOutput.writeTable(outFile,data)
Example #17
0
    #values, times, vertices = mne.label_time_courses(label_fname, stc_fname)

    #vtv = [mne.label_time_courses(label_fname, stc_fname) for stc_fname in stcs_fname]

    valuesAll = []
    for stc_fname in stcs_fname:
        values, times, vertices = mne.label_time_courses(
            label_fname, stc_fname)
        values = np.mean(values, 0)
        values = values[sample1:sample2]
        values = np.mean(values, 0)
        #print values
        valuesAll.append(values)
    valuesHem.append(valuesAll)
    print "mean", np.mean(valuesAll)

outTable = []
for x in range(len(stcs_fname)):
    temp = []
    temp.append(valuesHem[0][x])
    temp.append(valuesHem[1][x])
    temp.append(valuesHem[0][x] - valuesHem[1][x])
    outTable.append(temp)

outFile = '/cluster/kuperberg/SemPrMM/MEG/results/source_space/hem_measures/ya.n' + str(
    len(stcs_fname
        )) + '.' + args.protocol + '_c' + args.set + '_' + args.label + str(
            int(args.t1)) + '-' + str(int(args.t2)) + '.txt'
writeOutput.writeTable(outFile, outTable)
                '/cluster/kuperberg/SemPrMM/MEG/data/ya%s/ave_projon/stc/%s/ya%s_%s_c%sM-%s-%s.stc'
                % (s, protocolList[x], s, protocolList[x], condList[x],
                   args.model, hem) for s in subjects
            ]

            label_fname = data_path + '/label/%s-%s.label' % (label, hem)
            if os.access(label_fname, os.F_OK):
                print label, hem

                valuesAll = []
                for stc_fname in stcs_fname:
                    values, times, vertices = mne.label_time_courses(
                        label_fname, stc_fname)
                    values = np.mean(values, 0)
                    values = values[sample1:sample2]
                    values = np.mean(values, 0)
                    valuesAll.append(values)

                ##Update output table
                count = 0
                for s in subjects:
                    data = valuesAll[count]
                    row = [s, protocolList[x] + condList[x], label, hem, data]
                    dataTable.append(row)
                    count = count + 1

fileName = '/cluster/kuperberg/SemPrMM/MEG/results/source_space/R/' + args.prefix + '.Baleen_fillers' + args.model + '.' + str(
    int(args.t1)) + '-' + str(int(args.t2)) + '.txt'

writeOutput.writeTable(fileName, dataTable)