-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpha_code_USETHIS.py
1747 lines (1122 loc) · 65 KB
/
alpha_code_USETHIS.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##############ver 11/28/18 1:53PM##################
# added the flexible v blocked mixed trials
# after looking at data collected around thanksgiving, we want to run a final piloting version w/ flex v blocked blocks and only bilateral cues and a neutral cond
# no cue and no distractor cond -- only got as far as line 1221, finish later
# changing target and dis cond to have only chance and 'other,' ie .95, validities. And adding a unilateral cue condition
# had a typo which doubled num_reps, fixed
# Hwang Lab alpha study #
from __future__ import absolute_import, division
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle,uniform
import os # handy system and path functions
import sys # to get file system encoding
import serial #for sending triggers from this computer to biosemi computer
import csv
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
expName = 'alpha_pilot' # from the Builder filename that created this script
expInfo = {'subject': '', 'session': '01','f and b?':'y','no stim':'6', 'lat?':'n','COMPUTER (b,e,d,m)':'b','neutral?':'y','how many validities':'1','noDis':'n'}
# where 'f or b?' is flexible v blocked. blocked is default
#'no stim' refers to number of potential cued locations (12 by default)
#'d in t?' refers to having trials where distractor appears in a target cued location some portion of the time (resp should be y or n)
# lat?' lateralized stim. default is non lat stim. resp should be y or n.. THIS FLAG IS NOT YET CODED
# COMPUTER is the flag for which computer you're using, because this will influence the path to the I and T stimuli. Default is the behavioral computer. b=behavioral Dell, e=EEG dell, d=Dillan's laptop, m=Mac in Dillan's office
# 'neutral?' if == y turns on the neutralFlag, engaging the neutral cue condition. if ==n, the neutralFlag is false and there will be 2 cue types and 3 types of validity
# high low or no refers to the validity conditions. High= [.65,.95], low= [.5,.8], no=??
# noDis is referring to the option of having a neutral cue condition with no distractor, as a point of comparison for whether the distractor cue is even distracting
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
from psychopy import visual, core
win = visual.Window([1680,1050],units='deg',fullscr=False,monitor='testMonitor')
# ###############Flags####################################################################################
# this is where we'll flag the different piloted conditions
if expInfo['how many validities']=='2':
vFlag=1 #2 cues, 95%,65% or 80 and 50
elif expInfo['how many validities']=='1':
vFlag=-1 #1 cue, 95%
if expInfo['neutral?']=='y':
neutralFlag=1
else:
neutralFlag=0
#will blocks be flexbile or predictable?
if expInfo['f and b?']=='n':
flex_cond_flag = True
else:
flex_cond_flag = False
#will our probe include non-singleton distractors? #yellow distractor and red everything else.
allCircsFlag=1
#number of cue locations
no_stim = float(expInfo['no stim'])
# target in the distractor location condition?
TarindistFlag=True
#lateralized stim presentation?
if expInfo['lat?']=='y':
lat_stim_flag=True
else:
lat_stim_flag=False
# neutral cue and no distractor condition?
if (expInfo['noDis']=='y') and neutralFlag:
noDisflag=True
else:
noDisflag=False
# # MAKE SURE PATH TO STIMULI IS THE RIGHT ONE FOR THE COMPUTER YOU'RE USING
if expInfo['COMPUTER (b,e,d,m)']=='b':
redT=visual.ImageStim(win, image='C:\Stimuli\T2.png')
redI=visual.ImageStim(win, image='C:\Stimuli\I3.png') #behavioral stimulus presentation Dell
yellowT=visual.ImageStim(win, image='C:\Stimuli\YellowT.png')
redLpath='C:\Stimuli'
filename='Z:/AlphaStudy_Data/behavData'+u'/%s_%s_%s_%s' % (expInfo['subject'], expName, expInfo['session'],expInfo['date'])
refresh_rate=60
elif expInfo['COMPUTER (b,e,d,m)']=='d':
redT=visual.ImageStim(win, image='C:\\Users\\dillc\\Downloads\\T2.png')
redI=visual.ImageStim(win, image='C:\\Users\\dillc\\Downloads\\I3.png') #dillan's computer
filename='C:/Users/dillc/Documents'+u'/%s_%s_%s_%s' % (expInfo['subject'], expName, expInfo['session'],expInfo['date'])
refresh_rate=50
elif expInfo['COMPUTER (b,e,d,m)']=='m':
redT=visual.ImageStim(win, image='/Users/dcellier/Documents/GitHub/Alpha-Study/stimuli/T2.png')
redI=visual.ImageStim(win, image='/Users/dcellier/Documents/GitHub/Alpha-Study/stimuli/I3.png')
yellowT=visual.ImageStim(win, image='/Users/dcellier/Documents/GitHub/Alpha-Study/stimuli/YellowT.png')
redLpath='/Users/dcellier/Documents/GitHub/Alpha-Study/stimuli/'
filename='/Users/Shared/'+u'data/%s_%s_%s_%s' % (expInfo['subject'], expName, expInfo['session'],expInfo['date'])
refresh_rate=50 #not sure what the real refresh rate is
elif expInfo['COMPUTER (b,e,d,m)']=='e':
redT=visual.ImageStim(win, image='C:\Stimuli\T2.png')
redI=visual.ImageStim(win, image='C:\Stimuli\I3.png') #EEG stimulus presentation Dell
yellowT=visual.ImageStim(win, image='C:\Stimuli\YellowT.png')
redLpath='C:\Stimuli'
filename='Z:/AlphaStudy_Data/eegData'+u'/%s_%s_%s_%s' % (expInfo['subject'], expName, expInfo['session'],expInfo['date'])
refresh_rate=50
else:
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s_%s' % (expInfo['subject'], expName, expInfo['session'],expInfo['date'])
if (expInfo['COMPUTER (b,e,d,m)']=='b') or (expInfo['COMPUTER (b,e,d,m)']=='e'):
redL=[visual.ImageStim(win, image=redLpath+'\RedL copy 0.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 1.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 2.png'),
visual.ImageStim(win, image=redLpath+'\RedL copy 3.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 4.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 5.png'),
visual.ImageStim(win, image=redLpath+'\RedL copy 6.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 7.png'),visual.ImageStim(win, image=redLpath+'\RedL copy 8.png')]
else:
redL=[visual.ImageStim(win, image=redLpath+'RedL copy 0.png'),visual.ImageStim(win, image=redLpath+'RedL copy 1.png'),visual.ImageStim(win, image=redLpath+'RedL copy 2.png'),
visual.ImageStim(win, image=redLpath+'RedL copy 3.png'),visual.ImageStim(win, image=redLpath+'RedL copy 4.png'),visual.ImageStim(win, image=redLpath+'RedL copy 5.png'),
visual.ImageStim(win, image=redLpath+'RedL copy 6.png'),visual.ImageStim(win, image=redLpath+'RedL copy 7.png'),visual.ImageStim(win, image=redLpath+'RedL copy 8.png')]
if not allCircsFlag:
distractor_stim=redI
target_stim=redT
else:
distractor_stim=yellowT
target_stim=redT
other_stim=redL
cue_types=['target','distractor'] # distractor or target or neutral cues
if vFlag==1:
lo=.65
hi=.95
other=np.nan
elif vFlag==-1:
other=.95
lo=np.nan
hi=np.nan
if vFlag != -1:
cue_valid=[lo,hi] # cue validity
else:
cue_valid=[other]
if (not neutralFlag):
chance= ((1/no_stim)*2) #the random likelihood of the target ending up in one circle is equal to 1/(# of circles), and there are 2 cued circles
cue_valid.append(chance)
else:
chance=np.nan
num_trials=33 # change later to 33
num_reps=3 #the number of repeats for each condition, should be 3 in experiment
#if lat_stim_flag:
# num_reps=num_reps*2 #if we're having some blocks with a uni lateral cue we want to include in the # of blocks we're running through
stimList=[]
for cue in cue_types:
for num in cue_valid:
stimList.append({'cue':cue,'validity':num})
if neutralFlag:
stimList.append({'cue':'neutral','validity':0})
if noDisflag:
stimList.append({'cue':'neutral','validity':-1})
print(stimList)
EEGflag=0
if expInfo['COMPUTER (b,e,d,m)']=='e':
EEGflag=1
#added trigs
startSaveflag=bytes([254])
stopSaveflag=bytes([255])
delay1trig=bytes([101])
probetrig=bytes([103])
ITItrig=bytes([115])
tIdtrig=bytes([117])
targetLtrig=bytes([105]) #the low validity trial, such as .5 or .65
targetHtrig=bytes([107]) # high valid, ie 80 or 95
disLtrig=bytes([109])
disHtrig=bytes([111])
targetCtrig=bytes([123]) # the chance validity trial, ie .33
targetOtrig=bytes([125]) # the 'other' validity trial, ie when there is only one validity (combined w neutral condition or chance valid cond) and it can be set to anything
disCtrig=bytes([127])
disOtrig=bytes([129])
neutraltrig=bytes([113])
subRespTrig=bytes([119])
subNonRespTrig=bytes([121])
port=serial.Serial('COM4',baudrate=115200) # based on the biosemi website-- may be wrong?
# ####stimulus##############################################################################################
def wait_here(t):
interval=1/refresh_rate
num_frames=int(t/interval)
for n in range(num_frames):
draw_fixation()
win.flip()
def draw_fixation(): #0 to 1, for the opacity
fixation.draw()
def pracCond(thisBlock,n_practrials=10,demo=False):
pracDataList=[]
for n in range(n_practrials):
ITI=make_ITI('b')
# info for this block --for subject ######################################
if n==0:
for circs in stimuli:
circs.opacity = 0
if demo:
info_msg3=visual.TextStim(win,pos=[0,0],units='norm',text=thisBlock['cue']+' cue demonstration')
info_msg3.draw()
else:
info_msg3=visual.TextStim(win,pos=[0,0],units='norm',text='Begin practice block')
info_msg3.draw()
win.update()
core.wait(2)
draw_fixation()
win.flip()
core.wait(3)# pre-block pause
for circs in stimuli:
circs.opacity=1
circs.setLineColor([0,0,0])
circs.setFillColor([0,0,0])
cue_target_1=np.random.choice(right_stim,1)
cue_target_2=np.random.choice(left_stim,1)
#ensure that cue'd circles don't end up too close to each other, ie at clock positions 12 and 1, or 6 and 7
if no_stim==12:
while ((cue_target_1[0] is noon)and(cue_target_2[0] is one_oclock)) or ((cue_target_1[0] is six_oclock) and (cue_target_2[0] is seven_oclock)):
cue_target_1=np.random.choice(stimuli[:6],1)
cue_target_2=np.random.choice(stimuli[6:],1)
color_ind=cue_types_scramble.index(thisBlock['cue'])
cue_target_1[0].setLineColor(colors_scramble[color_ind])
cue_target_2[0].setLineColor(colors_scramble[color_ind])
draw_fixation()
win.flip()
core.wait(.5) # CUE PERIOD #################################################
draw_fixation()
# ## SOA period
for circs in stimuli:
circs.setLineColor([0,0,0])
win.flip()
core.wait(1.5) # DELAY #####################################################
draw_fixation()
target_loc1 = list(right_stim).index(cue_target_1[0]) #where are the two cued circles?
stim_minus_one = np.delete(right_stim, target_loc1)
target_loc2 = list(left_stim).index(cue_target_2[0])
stim_minus_two = np.delete(left_stim,target_loc2) #get a list of stimuli that don't include cued circles
# if thisBlock['validity']==lo: # THIS GIVES HALF THE CHANCE TO EITHER CUED SPOT, SO ANY ONE CUED SPOT HAS .25 or .40 chance of selection
#
# which_circle= np.random.choice([cue_target_1[0], cue_target_2[0], stim_minus_two],1,p=[(lo/2),(lo/2),(1-lo)]) #decide if cue is valid, using validity % of this condition
#
# elif thisBlock['validity']==hi:
#
# which_circle= np.random.choice([cue_target_1[0], cue_target_2[0], stim_minus_two],1,p=[(hi/2),(hi/2),(1-hi)])
if thisBlock['validity']==1:
which_circle = np.random.choice([cue_target_1[0], cue_target_2[0], stim_minus_two],1,p=[0.5,0.5,0.0])
if thisBlock['cue']=='neutral':#since the neutral cue is neutral, it isn't going to be valid and targets/distractors will be randomly assigned
trial_type='n/a'
elif (which_circle[0] in cue_target_1):
trial_type='valid'
cue_side='R'
elif (which_circle[0] in cue_target_2): #if the dis or target is in one of the circles cued, it was a predictive trial. SAVE OUT this info later!!!!!
trial_type='valid'
cue_side='L'
else:
trial_type='invalid'
trial_tarInDist=0
if thisBlock['cue']=='target':
if trial_type=='valid': #if this trial's cued locations are valid, put the target in one of them
target_stim.pos= which_circle[0].pos
if cue_side=='L': #if the target is on the Left side of the clock, we want the dist on the right and vice versa
distractor_stim.pos=(np.random.choice(stim_minus_one,1))[0].pos
else:
distractor_stim.pos= (np.random.choice(stim_minus_two,1))[0].pos
else: #if this trial is invalid
tar=np.random.choice(stim_minus_one,1,replace=False) #select two circles that aren't the cued circles
dist=np.random.choice(stim_minus_two,1,replace=False)
distractor_stim.pos=dist[0].pos #put the distractor in one and the target in the other
target_stim.pos=tar[0].pos
elif thisBlock['cue']=='distractor':
if trial_type=='valid': #if this trial's cued locations are valid, put the distractor in one of them
distractor_stim.pos=which_circle[0].pos
if cue_side=='L': #if the dist is on the Left side of the clock, we want the target on the right and vice versa
target_stim.pos=(np.random.choice(stim_minus_one,1))[0].pos
else:
target_stim.pos= (np.random.choice(stim_minus_two,1))[0].pos
else:
probe1=np.random.choice(stim_minus_one,1,replace=False) #select two circles that aren't the cued circles
probe2=np.random.choice(stim_minus_two,1,replace=False)
tarNdist=np.random.choice([probe1[0],probe2[0]],2,replace=False) #them randomly assign the target to one and dist to another
distractor_stim.pos=tarNdist[0].pos
target_stim.pos=tarNdist[1].pos
elif thisBlock['cue']=='neutral':
probe1=np.random.choice(stim_minus_one,1,replace=False) #select two circles that aren't the cued circles
probe2=np.random.choice(stim_minus_two,1,replace=False)
tarNdist=np.random.choice([probe1[0],probe2[0]],2,replace=False) #them randomly assign the target to one and dist to another
distractor_stim.pos=tarNdist[0].pos
target_stim.pos=tarNdist[1].pos
distractor_stim.ori= (np.random.choice([0,90,180,270],1))[0] #choose the orientation of the distractor
distractor_stim.draw()
target_stim.ori= (np.random.choice([0,90,180,270],1))[0] #choose the orientation of the target
target_stim.draw()
if target_stim.ori==0:
corrKey='up'
elif target_stim.ori==90:
corrKey='right'
elif target_stim.ori==180:
corrKey='down'
elif target_stim.ori==270:
corrKey='left'
for n in range(len(stimuli)):
circs=stimuli[n]
if not allCircsFlag:
if not (((circs.pos[0]==target_stim.pos[0]) and (circs.pos[1]==target_stim.pos[1])) or ((circs.pos[0]==distractor_stim.pos[0]) and (circs.pos[1]==distractor_stim.pos[1]))): #if the circle isn't a target or distractor, its grey
circs.setLineColor([0,0,0])
circs.setFillColor(None)
else:
circs.setLineColor([1,-1,-1])
circs.setFillColor(None)
else:
if not (((circs.pos[0]==target_stim.pos[0]) and (circs.pos[1]==target_stim.pos[1])) or ((circs.pos[0]==distractor_stim.pos[0]) and (circs.pos[1]==distractor_stim.pos[1]))): #if the circle is not a target or distractor then put other_stim in it
circs.setLineColor([1,-1,-1]) #if the circle is a non singleton distractor make it red
circs.setFillColor(None)
redL[n].ori=(np.random.choice([0,90,180,270],1))[0]
redL[n].pos=circs.pos
redL[n].draw()
elif (circs.pos[0]==target_stim.pos[0] and circs.pos[1]==target_stim.pos[1]):
circs.setLineColor([1,-1,-1]) #if the circle is a target we want it to be red, too
circs.setFillColor(None)
else: #if the circle is a chosen distractor, make it yellow
circs.lineColorSpace='rgb255'
circs.setLineColor([255,255,0])
circs.setFillColor(None)
win.update()
clock=core.Clock()
if not demo:
subResp= event.waitKeys(1.5,keyList=['up','down','left','right'],timeStamped=clock)
if subResp==None:
trial_corr=0
RT=-1
key="None"
else:
if subResp[0][0]==corrKey:
trial_corr=1
else:
trial_corr=0
RT=subResp[0][1]
key=subResp[0][0]
else:
core.wait(1.5)
#core.wait(0) # PROBE AND RESP ##############################################
draw_fixation()
for circs in stimuli:
circs.lineColorSpace='rgb'
circs.setLineColor([0,0,0])
circs.setFillColor([0,0,0])
#this my have to be rounded up or down depending on refresh rate? see: https://discourse.psychopy.org/t/jittering-iti-by-code-in-the-builder/4116
#ITI=round(1,ITI)
if not demo:
Thistrial_data= trial_corr
pracDataList.append(Thistrial_data)
#print(trialDataList)
win.flip()
core.wait(ITI)
for circs in stimuli:
circs.opacity=0
if not demo:
acc_feedback=visual.TextStim(win, pos=[0,0],units='norm',text='Your accuracy for the practice round was %i percent. Practice again? (y/n)' %(100*(np.sum(pracDataList)/n_practrials)))
acc_feedback.draw()
win.update()
cont=event.waitKeys(keyList=['y','n'])
if cont[0]=='y':
pracCond(thisBlock,n_practrials)
def make_csv(filename):
with open(filename+'.csv', mode='w') as csv_file:
fieldnames=['flex and blocked?','no stim','allCircsFlag','TarInDistFlag','lateralized?','neutral?','block','cue','validity','uni or bi lat?','flex or blocked?','trialNum','trial_type','corrResp','subResp','trialCorr?','RT','stim_loc(T,D)','tarinDisCond','ITI']
#fieldnames is simply asserting the categories at the top of the CSV
writer=csv.DictWriter(csv_file,fieldnames=fieldnames)
writer.writeheader()
#writer.writerow({'flex or blocked?': flex_cond_flag,'no stim':expInfo['no stim'],'TarInDistFlag':TarindistFlag,'lateralized?':lat_stim_flag})
#This is just to give info about the session overall: was the session blocked or flexibly cued? How many stim? etc.
print('\n\n\n')
for n in range(len(blocks.keys())): # loop through each block
blocks_data = list(blocks.keys())[n]
ThisBlock=blocks[blocks_data] #grabbing the block info for this block
#print(ThisBlock)
#print('\n')
for k in range(len(ThisBlock['trialsData'])): #this should be the # of trials
ThisTrial=ThisBlock['trialsData'][k] #grabbing the trial info out of data for this trial
#print(ThisTrial)
writer.writerow({'flex and blocked?': expInfo['f and b?'],'no stim':expInfo['no stim'],
'allCircsFlag':allCircsFlag,'TarInDistFlag':TarindistFlag,'lateralized?':lat_stim_flag,
'neutral?':expInfo['neutral?'],'block':ThisBlock['block'],'cue':ThisBlock['cueType'],'validity':ThisBlock['validity'],
'uni or bi lat?':ThisBlock['blockLat'],'flex or blocked?':ThisBlock['blockFlex'],'trialNum':ThisTrial['trialNum'],'trial_type':ThisTrial['trial_type'],
'corrResp':ThisTrial['corrResp'],'subResp':ThisTrial['subjectResp'],'trialCorr?':ThisTrial['trialCorr?'],
'RT':ThisTrial['RT'],'stim_loc(T,D)':ThisTrial['stim_loc'],'tarinDisCond':ThisTrial['tarinDisCond'],
'ITI':ThisTrial['ITI']})
def make_ITI(exp_type):
if exp_type=='b' or exp_type=='m' or exp_type=='d':
ITI=np.random.choice([1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6],1)[0] #averages to around 2 second?
elif exp_type=='e':
ITI=np.random.choice([3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6],1)[0] # averages to around 4 seconds?
return ITI
intro_msg= visual.TextStim(win, pos=[0, .5],units='norm', text='Welcome to the experiment!')
intro_msg2= visual.TextStim(win, pos=[0, 0], units='norm',text='You will see a series of circles that will indicate the location of the target "T" or of the distractor "T" some portion of the time')
intro_msg3=visual.TextStim(win, pos=[0,-0.5],units='norm',text='Press any key to continue')
intro_msg.draw()
intro_msg2.draw()
intro_msg3.draw()
win.flip()
event.waitKeys()
intro_mesg4= visual.TextStim(win,pos=[0,.5],units='norm',text='Please remain focused on the cross in the middle of the screen whenever there are NOT circles on the screen.')
intro_mesg5=visual.TextStim(win,pos=[0,0], units='norm',text='Respond to the orientation of the RED capital "T" using the arrow keys on the keyboard')
intro_mesg6=visual.TextStim(win,pos=[0,-0.5],units='norm',text='You will also see a YELLOW capital "T." Do NOT respond to the orientation of the YELLOW T. Press any key to continue.')
intro_mesg4.draw()
intro_mesg5.draw()
intro_mesg6.draw()
win.flip()
event.waitKeys()
#draw_fixation()
win.flip()
vis_deg=3.5
if no_stim==12:
noon = visual.Circle(
win=win, name='12',
size=(0.60, 0.60),
ori=0, pos=(0, vis_deg),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
noon.setAutoDraw(True)
one_oclock = visual.Circle(
win=win, name='1',
size=(0.09, 0.15),
ori=0, pos=((vis_deg/2), (sqrt(3)/2)*vis_deg),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-1.0, interpolate=True)
one_oclock.setAutoDraw(True)
two_oclock = visual.Circle(
win=win, name='2',
size=(0.09, 0.15),
ori=0, pos=(((sqrt(3)/2)*vis_deg), (vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-2.0, interpolate=True)
two_oclock.setAutoDraw(True)
three_oclock = visual.Circle(
win=win, name='3',
size=(0.09, 0.15),
ori=0, pos=(vis_deg, 0),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-3.0, interpolate=True)
three_oclock.setAutoDraw(True)
four_oclock = visual.Circle(
win=win, name='4',
size=(0.09, 0.15),
ori=0, pos=(((sqrt(3)/2)*vis_deg), -(vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-4.0, interpolate=True)
four_oclock.setAutoDraw(True)
five_oclock = visual.Circle(
win=win, name='5',
size=(0.09, 0.15),
ori=0, pos=((vis_deg/2), -((sqrt(3)/2)*vis_deg)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-5.0, interpolate=True)
five_oclock.setAutoDraw(True)
six_oclock = visual.Circle(
win=win, name= '6',
size=(.09,0.15), ori=0, pos=(0, -vis_deg),
lineWidth=7, lineColor=None, fillColor=None)
six_oclock.setAutoDraw(True)
eleven_oclock = visual.Circle(
win=win, name='11',
size=(0.09, 0.15),
ori=0, pos=(-(vis_deg/2), ((sqrt(3)/2)*vis_deg)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-1.0, interpolate=True)
eleven_oclock.setAutoDraw(True)
ten_oclock = visual.Circle(
win=win, name='10',
size=(0.09, 0.15),
ori=0, pos=(-((sqrt(3)/2)*vis_deg), (vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-2.0, interpolate=True)
ten_oclock.setAutoDraw(True)
nine_oclock = visual.Circle(
win=win, name='9',
size=(0.09, 0.15),
ori=0, pos=(-vis_deg, 0),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-3.0, interpolate=True)
nine_oclock.setAutoDraw(True)
eight_oclock = visual.Circle(
win=win, name='8',
size=(0.09, 0.15),
ori=0, pos=(-((sqrt(3)/2)*vis_deg), -(vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-4.0, interpolate=True)
eight_oclock.setAutoDraw(True)
seven_oclock = visual.Circle(
win=win, name='7',
size=(0.09, 0.15),
ori=0, pos=(-(vis_deg/2), -((sqrt(3)/2)*vis_deg)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-5.0, interpolate=True)
seven_oclock.setAutoDraw(True)
stimuli=[one_oclock,two_oclock,three_oclock,four_oclock,five_oclock,six_oclock,seven_oclock,eight_oclock,nine_oclock,ten_oclock,eleven_oclock,noon]
right_stim=stimuli[:6]
left_stim=stimuli[6:]
if no_stim==10:
one_oclock = visual.Circle(
win=win, name='1',
size=(0.09, 0.15),
ori=0, pos=((vis_deg/2), (sqrt(3)/2)*vis_deg),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-1.0, interpolate=True)
one_oclock.setAutoDraw(True)
two_oclock = visual.Circle(
win=win, name='2',
size=(0.09, 0.15),
ori=0, pos=(((sqrt(3)/2)*vis_deg), (vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-2.0, interpolate=True)
two_oclock.setAutoDraw(True)
three_oclock = visual.Circle(
win=win, name='3',
size=(0.09, 0.15),
ori=0, pos=(vis_deg, 0),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-3.0, interpolate=True)
three_oclock.setAutoDraw(True)
four_oclock = visual.Circle(
win=win, name='4',
size=(0.09, 0.15),
ori=0, pos=(((sqrt(3)/2)*vis_deg), -(vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-4.0, interpolate=True)
four_oclock.setAutoDraw(True)
five_oclock = visual.Circle(
win=win, name='5',
size=(0.09, 0.15),
ori=0, pos=((vis_deg/2), -((sqrt(3)/2)*vis_deg)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-5.0, interpolate=True)
five_oclock.setAutoDraw(True)
eleven_oclock = visual.Circle(
win=win, name='11',
size=(0.09, 0.15),
ori=0, pos=(-(vis_deg/2), ((sqrt(3)/2)*vis_deg)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-1.0, interpolate=True)
eleven_oclock.setAutoDraw(True)
ten_oclock = visual.Circle(
win=win, name='10',
size=(0.09, 0.15),
ori=0, pos=(-((sqrt(3)/2)*vis_deg), (vis_deg/2)),
lineWidth=7, lineColor=None, lineColorSpace='rgb',
fillColor=None, fillColorSpace='rgb',
opacity=1, depth=-2.0, interpolate=True)
ten_oclock.setAutoDraw(True)
nine_oclock = visual.Circle(
win=win, name='9',