-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmo_onsets.py
More file actions
executable file
·72 lines (52 loc) · 3.4 KB
/
Copy pathEmo_onsets.py
File metadata and controls
executable file
·72 lines (52 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import argparse
import csv
#Pull the data in based on a parameter entered at the command line
parser = argparse.ArgumentParser()
parser.add_argument('--input', '-i', required=True, help='Name of tab-delimited text file to import')
parser.add_argument('--output', '-o', required=True, help='Output path')
filename = parser.parse_args().input
Output=parser.parse_args().output
#Get the data into an array
data=np.genfromtxt(filename, dtype=None, delimiter='\t', names=True, autostrip=True)
for Run in ['1','2']:
#Find trials that need to be regressed out
GameStim = 'GameStim' + str(Run)
GameStimOnset=((data[GameStim + '_OnsetTime'][data[GameStim + '_OnsetTime']>0]-data['TriggerWAIT_RTTime'][data[GameStim + '_OnsetTime']>0])/float(1000))[0]
GameStimDuration=((data[GameStim + '_OnsetToOnsetTime'][data[GameStim + '_OnsetTime']>0])/float(1000))[0]
print 'GameStim' + str(Run) + 'Onset: ' + str(GameStimOnset)
print 'GameStim' + str(Run) + 'Duration: ' + str(GameStimDuration)
OutputFile=open((Output + 'Emo' + str(Run) + '_GameStim.txt'), "w")
writer = csv.writer(OutputFile, delimiter=' ')
writer.writerow([str(GameStimOnset), str(GameStimDuration), str(1)])
OutputFile.close()
#Get Block Onsets
ProcBlock = 'ThreatReactivity'+str(Run)
for List in ['CalmList','HappyList','FearList','ScrambledListOne','ScrambledListTwo']:
print List
NumBlocks = len((data['ReactivityITI_OnsetTime'][np.logical_and(np.logical_and(data['ProcedureBlock']==str(ProcBlock),data['RunningSubTrial']==List),data['SubTrial']==1)]))
#print NumBlocks
FirstTriggerWaitRTTime = (data['TriggerWAIT_RTTime'][np.logical_and(np.logical_and(data['ProcedureBlock']==str(ProcBlock),data['RunningSubTrial']==List),data['SubTrial']==1)])
#print FirstTriggerWaitRTTime
FirstReactivityITIOnsetTime = (data['ReactivityITI_OnsetTime'][np.logical_and(np.logical_and(data['ProcedureBlock']==str(ProcBlock),data['RunningSubTrial']==List),data['SubTrial']==1)])
#print FirstReactivityITIOnsetTime
BlockOnsets = (FirstReactivityITIOnsetTime - FirstTriggerWaitRTTime) / float(1000)
print BlockOnsets
LastTriggerWaitRTTime = (data['TriggerWAIT_RTTime'][np.logical_and(np.logical_and(data['ProcedureBlock']==str(ProcBlock),data['RunningSubTrial']==List),data['SubTrial']==36)])
#print LastTriggerWaitRTTime
LastReactivityITIOnsetTime = (data['ReactivityITI_OnsetTime'][np.logical_and(np.logical_and(data['ProcedureBlock']==str(ProcBlock),data['RunningSubTrial']==List),data['SubTrial']==36)])
#print LastReactivityITIOnsetTime
BlockOffsets = (LastReactivityITIOnsetTime - LastTriggerWaitRTTime) / float(1000)
#print BlockOffsets
BlockDurations = BlockOffsets - BlockOnsets
print BlockDurations
#Make short name for conditions
ShortCon = str(List)[0]
if (ShortCon == 'S' ):
OutputFile=open(Output + 'Emo' + str(Run) + '_' + str(ShortCon) + '.txt', "a")
else:
OutputFile=open(Output + 'Emo' + str(Run) + '_' + str(ShortCon) + '.txt', "w")
writer = csv.writer(OutputFile, delimiter=' ')
for row in range(0,len(BlockOnsets)):
writer.writerow([str(BlockOnsets[row]), str(BlockDurations[row]), str(1)])
OutputFile.close()