forked from BDMLab/FramingExperiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFramingOriginal.py
1778 lines (1543 loc) · 83.1 KB
/
FramingOriginal.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
This is a Psychopy adaptation of the experimental design from the paper:
De Martino et al (2006) Frames, Biases, and Rational Decision-Making in the Human Brain. Science, 313(5787), 684-687.
The code is written by Tomas Folke.
This experiment was created using PsychoPy2 Experiment Builder (v1.81.00), Thu Oct 16 13:34:11 2014
If you publish work using this script please cite the relevant PsychoPy publications
Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13.
Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"""
from __future__ import division # so that 1/3=0.333 instead of 1/3=0
from psychopy import visual, core, data, event, logging, sound, gui
from psychopy.constants import * # things like STARTED, FINISHED
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
import os # handy system and path functions
# 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 = 'FramingOriginal' # from the Builder filename that created this script
expInfo = {'participant':'', 'session':'001'}
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
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + 'data/%s_%s_%s' %(expInfo['participant'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath=None,
savePickle=True, saveWideText=True,
dataFileName=filename)
#save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
# Start Code - component code to be run before the window creation
# Setup the Window
win = visual.Window(size=(1920, 1080), fullscr=True, screen=0, allowGUI=False, allowStencil=True,
monitor='testMonitor', color='black', colorSpace='rgb',
blendMode='avg', useFBO=True,
)
# store frame rate of monitor if we can measure it successfully
expInfo['frameRate']=win.getActualFrameRate()
if expInfo['frameRate']!=None:
frameDur = 1.0/round(expInfo['frameRate'])
else:
frameDur = 1.0/60.0 # couldn't get a reliable measure so guess
################################################ Setup Routines ##########################################
# Initialize components for Routine "InstrStart"
InstrStartClock = core.Clock()
InstrStartText = visual.TextStim(win=win, ori=0, name='InstrMainText',
text=u'Welcome to this experiment.\n\nFirst you will do a number of practice trials to familiarise yourself with the task. You use the left arrow key to choose the left option and the right arrow key to choose the right option. \n\nPlease press space to begin.', font=u'Arial',
pos=[0, 0], height=1.5, wrapWidth=30, units='cm',
color=u'white', colorSpace='rgb', opacity=1,
depth=0.0)
# Initialize components for Routine "InstrMain"
InstrMainClock = core.Clock()
InstrMainText = visual.TextStim(win=win, ori=0, name='InstrMainText',
text=u'You have now finished the practice trials.\n\nPlease press space when you are ready to start the main part of the experiment.', font=u'Arial',
pos=[0, 0], height=1.5, wrapWidth=30, units='cm',
color=u'white', colorSpace='rgb', opacity=1,
depth=0.0)
# Initialize components for Routine "OriginalValue"
OriginalValueClock = core.Clock()
FixationCross = visual.TextStim(win=win, ori=0, name='FixationCross',
text='+', font='Arial', units='cm', alignHoriz='center',
pos=[0, 0], height=3, wrapWidth=20,
color='white', colorSpace='rgb', opacity=1,
depth=0.0)
BaseValue = visual.TextStim(win=win, ori=0, name='BaseValue',
text='1', font='Arial', units='cm', alignHoriz='center',
pos=[0, 0], height=3, wrapWidth=20,
color='white', colorSpace='rgb', opacity=1,
depth=0.0)
# Initialize components for Routine "trial"
trialClock = core.Clock()
ISI = core.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='ISI')
ProbabilityLeft = visual.ImageStim(win=win, name='ProbabilityLeft',
image=u'Stimuli/Original/Keep80.jpg', mask=None, units='cm',
ori=0, pos=[-15, 0], size=[22, 17],
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True)
ProbabilityRight = visual.ImageStim(win=win, name='ProbabilityRight',
image=u'Stimuli/Original/Keep80.jpg', mask=None, units='cm',
ori=0, pos=[15, 0], size=[22, 17],
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True)
FixedLeft = visual.TextStim(win=win, ori=0, name='FixedLeft',
text=cos, font='Arial',
pos=[-15, 0], height=3, wrapWidth=None, units='cm',
color='white', colorSpace='rgb', opacity=1)
FixedRight = visual.TextStim(win=win, ori=0, name='FixedRight',
text='', font='Arial',
pos=[15, 0], height=3, wrapWidth=None, units='cm',
color='white', colorSpace='rgb', opacity=1)
MiddleLine = visual.Line(win, start=(0, -14), end=(0, 14), units='cm', lineWidth=5, lineColor=[1,1,1], lineColorSpace='rgb')
# Initialize components for Routine "Outcome"
OutcomeClock = core.Clock()
SelectLeft = visual.Rect(win=win, name='SelectLeft',
width=[17, 17][0], height=[17, 17][1], units='cm',
ori=0, pos=[-15, 0],
lineWidth=3, lineColor='yellow', lineColorSpace='rgb',
opacity=1,interpolate=True)
SelectRight = visual.Rect(win=win, name='SelectRight',
width=[17, 17][0], height=[17, 17][1],units='cm',
ori=0, pos=[15, 0],
lineWidth=3, lineColor='yellow', lineColorSpace='rgb',
opacity=1,interpolate=True)
# Initialize components for Routine "Slow"
SlowClock = core.Clock()
SlowText = visual.TextStim(win=win, ori=0, name='SlowText', text=u'Too Slow', font=u'Arial', pos=[0, 0], height=3, units='cm', wrapWidth=None, color=u'white', colorSpace=u'rgb', opacity=1, depth=0.0)
# Instalize components for "Rest"
RestClock = core.Clock()
RestText = visual.TextStim(win=win, ori=0, name='RestText', text=u'Great! Now have a rest and press space when you are ready to begin the next block.', font=u'Arial', pos=[0, 0], units='cm', height=2, wrapWidth=30, color=u'white', colorSpace=u'rgb', opacity=1, depth=0.0)
# Instalize components for "Thank You"
ThankYouClock = core.Clock()
ThankYouText = visual.TextStim(win=win, ori=0, name='ThankYouText', text=u'You have now completed this experiment. Thank you for your participation. Please inform the experimenter that you have finished.', font=u'Arial', pos=[0, 0], height=2, units='cm', wrapWidth=30, color=u'white', colorSpace=u'rgb', opacity=1, depth=0.0)
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
################################################ Experiment Starts ##########################################
#------Prepare to start Routine "InstrStart"-------
t = 0
InstrStartClock.reset() # clock
frameN = -1
# update component parameters for each repeat
InstrResp = event.BuilderKeyResponse() # create an object of type KeyResponse
InstrResp.status = NOT_STARTED
# keep track of which components have finished
InstrStartComponents = []
InstrStartComponents.append(InstrStartText)
for thisComponent in InstrStartComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "InstrStart"-------
continueRoutine = True
while continueRoutine:
# get current time
t = InstrStartClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *InstrStartText* updates
if t >= 0.0 and InstrStartText.status == NOT_STARTED:
# keep track of start time/frame for later
InstrStartText.tStart = t # underestimates by a little under one frame
InstrStartText.frameNStart = frameN # exact frame index
InstrStartText.setAutoDraw(True)
# *InstrResp* updates
if t >= 0.0 and InstrResp.status == NOT_STARTED:
# keep track of start time/frame for later
InstrResp.tStart = t # underestimates by a little under one frame
InstrResp.frameNStart = frameN # exact frame index
InstrResp.status = STARTED
# keyboard checking is just starting
InstrResp.clock.reset() # now t=0
event.clearEvents(eventType='keyboard')
if InstrResp.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
InstrResp.keys = theseKeys[-1] # just the last key pressed
InstrResp.rt = InstrResp.clock.getTime()
# a response ends the routine
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in InstrStartComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
else: # this Routine was not non-slip safe so reset non-slip timer
routineTimer.reset()
#-------Ending Routine "InstrStart"-------
for thisComponent in InstrStartComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if InstrResp.keys in ['', [], None]: # No response was made
InstrResp.keys=None
# store data for thisExp (ExperimentHandler)
thisExp.addData('InstrResp.keys',InstrResp.keys)
if InstrResp.keys != None: # we had a response
thisExp.addData('InstrResp.rt', InstrResp.rt)
thisExp.nextEntry()
###################################### PRACTICE FRAMING LOOP STARTS ####################################################
# set up handler to look after randomisation of conditions etc
PracticeLoop = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=None,
trialList=data.importConditions(u'PracticeTrialHandlerOriginal.xlsx'),
seed=None, name='PracticeLoop')
thisExp.addLoop(PracticeLoop) # add the loop to the experiment
thisPracticeLoop = PracticeLoop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisFramingLoop.rgb)
if thisPracticeLoop != None:
for paramName in thisPracticeLoop.keys():
exec(paramName + '= thisPracticeLoop.' + paramName)
for thisPracticeLoop in PracticeLoop:
currentLoop = PracticeLoop
# abbreviate parameter names if possible (e.g. rgb = thisFramingLoop.rgb)
if thisPracticeLoop != None:
for paramName in thisPracticeLoop.keys():
exec(paramName + '= thisPracticeLoop.' + paramName)
#------Prepare to start Routine "OriginalValue"-------
# determine the text for the OriginalValueStimuli:
BaseValueText=u'You receive \n £%s' %FullAmount
t = 0
OriginalValueClock.reset() # clock
frameN = -1
# routineTimer.add(20.000000)
# update component parameters for each repeat
BaseValue.setText(BaseValueText)
# keep track of which components have finished
OriginalValueComponents = []
OriginalValueComponents.append(BaseValue)
OriginalValueComponents.append(FixationCross)
for thisComponent in OriginalValueComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "OriginalValue"-------
continueRoutine = True
while continueRoutine:
# get current time
t = OriginalValueClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *FixationCross* updates
if t >= 0.0 and FixationCross.status == NOT_STARTED:
# keep track of start time/frame for later
FixationCross.tStart = t # underestimates by a little under one frame
FixationCross.frameNStart = frameN # exact frame index
FixationCross.setAutoDraw(True)
elif FixationCross.status == STARTED and t >= (0.0 + (1.5-win.monitorFramePeriod*0.75)): #most of one frame period left
FixationCross.setAutoDraw(False)
# *BaseValue* updates
if t >= 1.5 and BaseValue.status == NOT_STARTED:
# keep track of start time/frame for later
BaseValue.tStart = t # underestimates by a little under one frame
BaseValue.frameNStart = frameN # exact frame index
BaseValue.setAutoDraw(True)
elif BaseValue.status == STARTED and t >= (1.5 + (3.0-win.monitorFramePeriod*0.75)): #most of one frame period left
BaseValue.setAutoDraw(False)
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in OriginalValueComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "OriginalValue"-------
for thisComponent in OriginalValueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# If the gamble should be shown on the right side of the screen, run the following:
if GambleLeft == 0:
# Creating a variable to simplify storing participants' answers at the end of the routine
RightChoice=Gamble
LeftChoice=Stable
#------Prepare to start Routine "trial"-------
t = 0
trialClock.reset() # clock
frameN = -1
# update component parameters for each repeat
ProbabilityRight.setImage(Gamble)
FixedLeft.setText(Stable)
# Update Keyboard parameters
event.clearEvents(eventType='keyboard')
KeyResp = event.BuilderKeyResponse()
KeyResp.status = NOT_STARTED
# keep track of which components have finished
trialComponents = []
trialComponents.append(ISI)
trialComponents.append(ProbabilityRight)
trialComponents.append(FixedLeft)
trialComponents.append(MiddleLine)
for thisComponent in trialComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "trial"-------
continueRoutine = True
while continueRoutine: # and routineTimer.getTime() > 0:
# get current time
t = trialClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *MiddleLine* updates
if t >= 0.3 and MiddleLine.status == NOT_STARTED:
# keep track of start time/frame for later
MiddleLine.tStart = t # underestimates by a little under one frame
MiddleLine.frameNStart = frameN # exact frame index
MiddleLine.setAutoDraw(True)
elif MiddleLine.status == STARTED and t >= (0.3 + (4.0-win.monitorFramePeriod*0.75)): #most of one frame period left
MiddleLine.setAutoDraw(False)
# *ProbabilityRight* updates
if t >= 0.3 and ProbabilityRight.status == NOT_STARTED:
# keep track of start time/frame for later
ProbabilityRight.tStart = t # underestimates by a little under one frame
ProbabilityRight.frameNStart = frameN # exact frame index
ProbabilityRight.setAutoDraw(True)
elif ProbabilityRight.status == STARTED and t >= (0.3 + (4.0-win.monitorFramePeriod*0.75)): #most of one frame period left
ProbabilityRight.setAutoDraw(False)
# *FixedLeft* updates
if t >= 0.3 and FixedLeft.status == NOT_STARTED:
# keep track of start time/frame for later
FixedLeft.tStart = t # underestimates by a little under one frame
FixedLeft.frameNStart = frameN # exact frame index
FixedLeft.setAutoDraw(True)
elif FixedLeft.status == STARTED and t >= (0.3 + (4.0-win.monitorFramePeriod*0.75)): #most of one frame period left
FixedLeft.setAutoDraw(False)
# *ISI* period
if t >= 0.0 and ISI.status == NOT_STARTED:
# keep track of start time/frame for later
ISI.tStart = t # underestimates by a little under one frame
ISI.frameNStart = frameN # exact frame index
ISI.start(0.3)
elif ISI.status == STARTED: #one frame should pass before updating params and completing
ISI.complete() #finish the static period
# *KeyResp* updates
if t >= 0.3 and KeyResp.status == NOT_STARTED:
KeyResp.tStart = t
KeyResp.frameNStart = frameN
KeyResp.status = STARTED
KeyResp.clock.reset()
if KeyResp.status == STARTED:
theseKeys = event.getKeys(keyList=['left', 'right'])
# check for quit:
if 'escape' in theseKeys:
endExpNow = True
if len(theseKeys) > 0:
KeyResp.keys = theseKeys[-1]
KeyResp.rt = KeyResp.clock.getTime()
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "trial"-------
for thisComponent in trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if KeyResp.keys in ['', [], None]:
KeyResp.keys = None
# Store data for experiment:
thisExp.addData('Response', KeyResp.keys)
if KeyResp.keys != None:
thisExp.addData('RT', KeyResp.rt)
if KeyResp.keys == 'left':
thisExp.addData('Choice', 'Stable')
if KeyResp.keys == 'right':
thisExp.addData('Choice', 'Gamble')
thisExp.nextEntry()
# Only do the outcome routine if there is a response of this trial
if KeyResp.keys != None:
#------Prepare to start Routine "Outcome"-------
t = 0
OutcomeClock.reset() # clock
frameN = -1
# update component parameters for each repeat
# keep track of which components have finished
OutcomeComponents = []
OutcomeComponents.append(SelectLeft)
OutcomeComponents.append(SelectRight)
OutcomeComponents.append(ProbabilityRight)
OutcomeComponents.append(FixedLeft)
OutcomeComponents.append(MiddleLine)
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "Outcome"-------
continueRoutine = True
while continueRoutine: # and routineTimer.getTime() > 0:
# get current time
t = OutcomeClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *MiddleLine* updates
if t >= 0 and MiddleLine.status == NOT_STARTED:
# keep track of start time/frame for later
MiddleLine.tStart = t # underestimates by a little under one frame
MiddleLine.frameNStart = frameN # exact frame index
MiddleLine.setAutoDraw(True)
elif MiddleLine.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
MiddleLine.setAutoDraw(False)
# *ProbabilityRight* updates
if t >= 0 and ProbabilityRight.status == NOT_STARTED:
# keep track of start time/frame for later
ProbabilityRight.tStart = t # underestimates by a little under one frame
ProbabilityRight.frameNStart = frameN # exact frame index
ProbabilityRight.setAutoDraw(True)
elif ProbabilityRight.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
ProbabilityRight.setAutoDraw(False)
# *FixedLeft* updates
if t >= 0 and FixedLeft.status == NOT_STARTED:
# keep track of start time/frame for later
FixedLeft.tStart = t # underestimates by a little under one frame
FixedLeft.frameNStart = frameN # exact frame index
FixedLeft.setAutoDraw(True)
elif FixedLeft.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
FixedLeft.setAutoDraw(False)
# *SelectLeft* updates
if t >= 0 and SelectLeft.status == NOT_STARTED and KeyResp.keys =='left':
# keep track of start time/frame for later
SelectLeft.tStart = t # underestimates by a little under one frame
SelectLeft.frameNStart = frameN # exact frame index
SelectLeft.setAutoDraw(True)
elif SelectLeft.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
SelectLeft.setAutoDraw(False)
continueRoutine = False
# *SelectRight* updates
if t >= 0 and SelectRight.status == NOT_STARTED and KeyResp.keys =='right':
# keep track of start time/frame for later
SelectRight.tStart = t # underestimates by a little under one frame
SelectRight.frameNStart = frameN # exact frame index
SelectRight.setAutoDraw(True)
elif SelectRight.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
SelectRight.setAutoDraw(False)
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "Outcome"-------
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# If people were too slow to respond start the Slow routine
if KeyResp.keys == None:
#------Prepare to start Routine "Slow"-------
t = 0
SlowClock.reset() # clock
frameN = -1
# update component parameters for each repeat
# keep track of which components have finished
SlowComponents = []
SlowComponents.append(SlowText)
for thisComponent in SlowComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "Slow"-------
continueRoutine = True
while continueRoutine:
# get current time
t = SlowClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *SlowText* updates
if t >= 0.0 and SlowText.status == NOT_STARTED:
# keep track of start time/frame for later
SlowText.tStart = t # underestimates by a little under one frame
SlowText.frameNStart = frameN # exact frame index
SlowText.setAutoDraw(True)
elif SlowText.status == STARTED and t >= (0.0 + (1.0-win.monitorFramePeriod*0.75)): #most of one frame period left
SlowText.setAutoDraw(False)
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in SlowComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "Slow"-------
for thisComponent in OriginalValueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# If the gamble should be shown on the left side of the screen, run the following:
if GambleLeft == 1:
# Creating a variable to simplify storing participants' answers at the end of the routine
RightChoice=Stable
LeftChoice=Gamble
#------Prepare to start Routine "trial"-------
t = 0
trialClock.reset() # clock
frameN = -1
# update component parameters for each repeat
ProbabilityLeft.setImage(Gamble)
FixedRight.setText(Stable)
# Update Keyboard parameters
event.clearEvents(eventType='keyboard')
KeyResp = event.BuilderKeyResponse()
KeyResp.status = NOT_STARTED
# keep track of which components have finished
trialComponents = []
trialComponents.append(ISI)
trialComponents.append(ProbabilityLeft)
trialComponents.append(FixedRight)
trialComponents.append(MiddleLine)
for thisComponent in trialComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "trial"-------
continueRoutine = True
while continueRoutine: # and routineTimer.getTime() > 0:
# get current time
t = trialClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *MiddleLine* updates
if t >= 0.5 and MiddleLine.status == NOT_STARTED:
# keep track of start time/frame for later
MiddleLine.tStart = t # underestimates by a little under one frame
MiddleLine.frameNStart = frameN # exact frame index
MiddleLine.setAutoDraw(True)
elif MiddleLine.status == STARTED and t >= (0.3 + (4-win.monitorFramePeriod*0.75)): #most of one frame period left
MiddleLine.setAutoDraw(False)
# *ProbabilityLeft* updates
if t >= 0.5 and ProbabilityLeft.status == NOT_STARTED:
# keep track of start time/frame for later
ProbabilityLeft.tStart = t # underestimates by a little under one frame
ProbabilityLeft.frameNStart = frameN # exact frame index
ProbabilityLeft.setAutoDraw(True)
elif ProbabilityLeft.status == STARTED and t >= (0.3 + (4-win.monitorFramePeriod*0.75)): #most of one frame period left
ProbabilityLeft.setAutoDraw(False)
# *FixedRight* updates
if t >= 0.5 and FixedRight.status == NOT_STARTED:
# keep track of start time/frame for later
FixedRight.tStart = t # underestimates by a little under one frame
FixedRight.frameNStart = frameN # exact frame index
FixedRight.setAutoDraw(True)
elif FixedRight.status == STARTED and t >= (0.3 + (4-win.monitorFramePeriod*0.75)): #most of one frame period left
FixedRight.setAutoDraw(False)
# *ISI* period
if t >= 0.0 and ISI.status == NOT_STARTED:
# keep track of start time/frame for later
ISI.tStart = t # underestimates by a little under one frame
ISI.frameNStart = frameN # exact frame index
ISI.start(0.3)
elif ISI.status == STARTED: #one frame should pass before updating params and completing
ISI.complete() #finish the static period
# *KeyResp* updates
if t >= 0.3 and KeyResp.status == NOT_STARTED:
KeyResp.tStart = t
KeyResp.frameNStart = frameN
KeyResp.status = STARTED
KeyResp.clock.reset()
if KeyResp.status == STARTED:
theseKeys = event.getKeys(keyList=['left', 'right'])
# check for quit:
if 'escape' in theseKeys:
endExpNow = True
if len(theseKeys) > 0:
KeyResp.keys = theseKeys[-1]
KeyResp.rt = KeyResp.clock.getTime()
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "trial"-------
for thisComponent in trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if KeyResp.keys in ['', [], None]:
KeyResp.keys = None
# Store data for experiment:
thisExp.addData('Response', KeyResp.keys)
if KeyResp.keys != None:
thisExp.addData('RT', KeyResp.rt)
if KeyResp.keys == 'left':
thisExp.addData('Choice', 'Gamble')
if KeyResp.keys == 'right':
thisExp.addData('Choice', 'Stable')
thisExp.nextEntry()
# Only do the outcome routine if there is a response of this trial
if KeyResp.keys != None:
#------Prepare to start Routine "Outcome"-------
t = 0
OutcomeClock.reset() # clock
frameN = -1
# update component parameters for each repeat
# keep track of which components have finished
OutcomeComponents = []
OutcomeComponents.append(SelectLeft)
OutcomeComponents.append(SelectRight)
OutcomeComponents.append(ProbabilityLeft)
OutcomeComponents.append(FixedRight)
OutcomeComponents.append(MiddleLine)
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "Outcome"-------
continueRoutine = True
while continueRoutine: # and routineTimer.getTime() > 0:
# get current time
t = OutcomeClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *MiddleLine* updates
if t >= 0 and MiddleLine.status == NOT_STARTED:
# keep track of start time/frame for later
MiddleLine.tStart = t # underestimates by a little under one frame
MiddleLine.frameNStart = frameN # exact frame index
MiddleLine.setAutoDraw(True)
elif MiddleLine.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
MiddleLine.setAutoDraw(False)
# *ProbabilityRight* updates
if t >= 0 and ProbabilityLeft.status == NOT_STARTED:
# keep track of start time/frame for later
ProbabilityLeft.tStart = t # underestimates by a little under one frame
ProbabilityLeft.frameNStart = frameN # exact frame index
ProbabilityLeft.setAutoDraw(True)
elif ProbabilityLeft.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
ProbabilityLeft.setAutoDraw(False)
# *FixedLeft* updates
if t >= 0 and FixedRight.status == NOT_STARTED:
# keep track of start time/frame for later
FixedRight.tStart = t # underestimates by a little under one frame
FixedRight.frameNStart = frameN # exact frame index
FixedRight.setAutoDraw(True)
elif FixedRight.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
FixedRight.setAutoDraw(False)
# *SelectLeft* updates
if t >= 0 and SelectLeft.status == NOT_STARTED and KeyResp.keys=='left':
# keep track of start time/frame for later
SelectLeft.tStart = t # underestimates by a little under one frame
SelectLeft.frameNStart = frameN # exact frame index
SelectLeft.setAutoDraw(True)
elif SelectLeft.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
SelectLeft.setAutoDraw(False)
continueRoutine = False
# *SelectRight* updates
if t >= 0 and SelectRight.status == NOT_STARTED and KeyResp.keys=='right':
# keep track of start time/frame for later
SelectRight.tStart = t # underestimates by a little under one frame
SelectRight.frameNStart = frameN # exact frame index
SelectRight.setAutoDraw(True)
elif SelectRight.status == STARTED and t >= (0 + (1-win.monitorFramePeriod*0.75)): #most of one frame period left
SelectRight.setAutoDraw(False)
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "Outcome"-------
for thisComponent in OutcomeComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# If people were too slow to respond start the Slow routine
elif KeyResp.keys == None:
#------Prepare to start Routine "Slow"-------
t = 0
SlowClock.reset() # clock
frameN = -1
# update component parameters for each repeat
# keep track of which components have finished
SlowComponents = []
SlowComponents.append(SlowText)
for thisComponent in SlowComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "Slow"-------
continueRoutine = True
while continueRoutine:
# get current time
t = SlowClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *SlowText* updates
if t >= 0.0 and SlowText.status == NOT_STARTED:
# keep track of start time/frame for later
SlowText.tStart = t # underestimates by a little under one frame
SlowText.frameNStart = frameN # exact frame index
SlowText.setAutoDraw(True)
elif SlowText.status == STARTED and t >= (0.0 + (1.0-win.monitorFramePeriod*0.75)): #most of one frame period left
SlowText.setAutoDraw(False)
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in SlowComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "Slow"-------
for thisComponent in OriginalValueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
###################################### PRACTICE FRAMING LOOP FINISHES ####################################################
#------Prepare to start Routine "InstrMain"-------
t = 0
InstrMainClock.reset() # clock
frameN = -1
# update component parameters for each repeat
InstrResp = event.BuilderKeyResponse() # create an object of type KeyResponse
InstrResp.status = NOT_STARTED
# keep track of which components have finished
InstrMainComponents = []
InstrMainComponents.append(InstrMainText)
for thisComponent in InstrMainComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "InstrMain"-------
continueRoutine = True
while continueRoutine:
# get current time
t = InstrMainClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *InstrMainText* updates
if t >= 0.0 and InstrMainText.status == NOT_STARTED:
# keep track of start time/frame for later
InstrMainText.tStart = t # underestimates by a little under one frame
InstrMainText.frameNStart = frameN # exact frame index
InstrMainText.setAutoDraw(True)
# *InstrResp* updates
if t >= 0.0 and InstrResp.status == NOT_STARTED:
# keep track of start time/frame for later
InstrResp.tStart = t # underestimates by a little under one frame
InstrResp.frameNStart = frameN # exact frame index
InstrResp.status = STARTED
# keyboard checking is just starting
InstrResp.clock.reset() # now t=0
event.clearEvents(eventType='keyboard')
if InstrResp.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
InstrResp.keys = theseKeys[-1] # just the last key pressed
InstrResp.rt = InstrResp.clock.getTime()
# a response ends the routine
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineTimer.reset() # if we abort early the non-slip timer needs reset
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in InstrMainComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
else: # this Routine was not non-slip safe so reset non-slip timer
routineTimer.reset()
#-------Ending Routine "InstrMain"-------
for thisComponent in InstrMainComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if InstrResp.keys in ['', [], None]: # No response was made
InstrResp.keys=None
# store data for thisExp (ExperimentHandler)
thisExp.addData('InstrResp.keys',InstrResp.keys)
if InstrResp.keys != None: # we had a response
thisExp.addData('InstrResp.rt', InstrResp.rt)
thisExp.nextEntry()
###################################### FRAMING LOOP STARTS ####################################################
# set up handler to look after randomisation of conditions etc
FramingLoop = data.TrialHandler(nReps=3, method='random',
extraInfo=expInfo, originPath=None,
trialList=data.importConditions(u'FramingTrialHandlerOriginal.xlsx'),
seed=None, name='FramingLoop')
thisExp.addLoop(FramingLoop) # add the loop to the experiment
thisFramingLoop = FramingLoop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisFramingLoop.rgb)
if thisFramingLoop != None:
for paramName in thisFramingLoop.keys():
exec(paramName + '= thisFramingLoop.' + paramName)
# Before the loop, we set up a counter to control the rest screen between the blocks!
RestCounter = 0
for thisFramingLoop in FramingLoop:
currentLoop = FramingLoop
# abbreviate parameter names if possible (e.g. rgb = thisFramingLoop.rgb)
if thisFramingLoop != None:
for paramName in thisFramingLoop.keys():
exec(paramName + '= thisFramingLoop.' + paramName)
# Increase the RestCounter by 1 per trial
RestCounter += 1
#------Prepare to start Routine "OriginalValue"-------
# determine the text for the OriginalValueStimuli: