-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdk-discrimination.py
1971 lines (1751 loc) · 87.9 KB
/
rdk-discrimination.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 python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2023.1.0),
on Mon Mar 6 21:56:53 2023
If you publish work using this script the most relevant publication is:
Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
PsychoPy2: Experiments in behavior made easy Behav Res 51: 195.
https://doi.org/10.3758/s13428-018-01193-y
"""
import psychopy
psychopy.useVersion('2023.1.0')
# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import plugins
plugins.activatePlugins()
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout
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, choice as randchoice
import os # handy system and path functions
import sys # to get file system encoding
import psychopy.iohub as io
from psychopy.hardware import keyboard
# Run 'Before Experiment' code from code
import time, string, random
# sample 3 uppercase letters
letters = np.random.choice(list(string.ascii_uppercase), 3)
# convert characters into string
letters = ''.join(letters)
# take timestamp in seconds and convert to milliseconds
timestamp = round(time.time() * 1000)
# remove first 6 digits
timestamp = int(str(timestamp)[6:])
# concatenate letters and timestamp to create unique ID
participant_id = letters + str(timestamp)
# 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
psychopyVersion = '2023.1.0'
expName = 'rdk-discrimination' # from the Builder filename that created this script
expInfo = {
'Pseudonym': partipant_id,
}
# --- Show participant info dialog --
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['Pseudonym'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='/Users/andrew/Library/CloudStorage/OneDrive-UniversitaetBern/teaching/neuroscicomplabFS23/psychopy-rdk-discrimination-task/rdk-discrimination.py',
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
frameTolerance = 0.001 # how close to onset before 'same' frame
# Start Code - component code to be run after the window creation
# --- Setup the Window ---
win = visual.Window(
size=[2056, 1329], fullscr=True, screen=-1,
winType='pyglet', allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
backgroundImage='', backgroundFit='none',
blendMode='avg', useFBO=True,
units='height')
win.mouseVisible = False
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
# --- Setup input devices ---
ioConfig = {}
# Setup iohub keyboard
ioConfig['Keyboard'] = dict(use_keymap='psychopy')
ioSession = '1'
if 'session' in expInfo:
ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, **ioConfig)
eyetracker = None
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend='iohub')
# --- Initialize components for Routine "participant_id" ---
# --- Initialize components for Routine "Instruction" ---
instruction_text = visual.TextStim(win=win, name='instruction_text',
text="Welcome to the experiment.\n\nIn the following you will solve a series of tasks. You will be presented with a circle full of dots. Some of these dots will be moving to either the left or to the right. Your task is to decide in which direction they are moving.\n\nPress the [ F key ] if you think the dots are moving to the left, or the [ J key] if you think they are moving the right.\n\nBefore the dots appear, you will see an arrow on the screen indicating the more probable direction of motion. If the arrow points to the right, the dots are more likely to move to the right than to the left, and vice versa.\n\nPlease always focus on the small cross on the screen, if nothing else is presented, and try to respond as fast as possible.\n\nPress [ space ] to start with some practice runs when you're ready.",
font='Open Sans',
pos=(0, 0), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
instruction_keyboard_response = keyboard.Keyboard()
# --- Initialize components for Routine "ISI" ---
static_isi = clock.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='static_isi')
# --- Initialize components for Routine "Fixation_pre_cue" ---
fixation_pre = visual.TextStim(win=win, name='fixation_pre',
text='+',
font='Open Sans',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Cue" ---
image = visual.ImageStim(
win=win,
name='image',
image='default.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.2, 0.1),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
# --- Initialize components for Routine "Fixation_post_cue" ---
fixation_post = visual.TextStim(win=win, name='fixation_post',
text='+',
font='Open Sans',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Dots" ---
dots_background = visual.ShapeStim(
win=win, name='dots_background',
size=(0.75, 0.75), vertices='circle',
ori=0.0, pos=(0, 0), anchor='center',
lineWidth=1.0, colorSpace='rgb', lineColor='black', fillColor='black',
opacity=None, depth=-1.0, interpolate=True)
dots_stimulus = visual.DotStim(
win=win, name='dots_stimulus',
nDots=250, dotSize=3.0,
speed=0.0125, dir=1.0, coherence=0.08,
fieldPos=(0.0, 0.0), fieldSize=0.75, fieldAnchor='center', fieldShape='circle',
signalDots='same', noiseDots='walk',dotLife=3.0,
color=[1.0,1.0,1.0], colorSpace='rgb', opacity=1.0,
depth=-2.0)
dots_keyboard_response = keyboard.Keyboard()
# --- Initialize components for Routine "Feedback" ---
feedback_text = visual.TextStim(win=win, name='feedback_text',
text='',
font='Open Sans',
pos=(0, 0.01), height=0.07, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Instruction_Main" ---
instruction_main_text = visual.TextStim(win=win, name='instruction_main_text',
text='We are now finished with the practice runs and will proceed to the main experiment.\n\nPlease try to respond as fast as possible.\n\nPress [ space ] to start the main experiment.',
font='Open Sans',
pos=(0, 0), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
instruction_main_keyboard_response = keyboard.Keyboard()
# --- Initialize components for Routine "ISI" ---
static_isi = clock.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='static_isi')
# --- Initialize components for Routine "Fixation_pre_cue" ---
fixation_pre = visual.TextStim(win=win, name='fixation_pre',
text='+',
font='Open Sans',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Cue" ---
image = visual.ImageStim(
win=win,
name='image',
image='default.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.2, 0.1),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
# --- Initialize components for Routine "Fixation_post_cue" ---
fixation_post = visual.TextStim(win=win, name='fixation_post',
text='+',
font='Open Sans',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Dots" ---
dots_background = visual.ShapeStim(
win=win, name='dots_background',
size=(0.75, 0.75), vertices='circle',
ori=0.0, pos=(0, 0), anchor='center',
lineWidth=1.0, colorSpace='rgb', lineColor='black', fillColor='black',
opacity=None, depth=-1.0, interpolate=True)
dots_stimulus = visual.DotStim(
win=win, name='dots_stimulus',
nDots=250, dotSize=3.0,
speed=0.0125, dir=1.0, coherence=0.08,
fieldPos=(0.0, 0.0), fieldSize=0.75, fieldAnchor='center', fieldShape='circle',
signalDots='same', noiseDots='walk',dotLife=3.0,
color=[1.0,1.0,1.0], colorSpace='rgb', opacity=1.0,
depth=-2.0)
dots_keyboard_response = keyboard.Keyboard()
# --- Initialize components for Routine "Feedback" ---
feedback_text = visual.TextStim(win=win, name='feedback_text',
text='',
font='Open Sans',
pos=(0, 0.01), height=0.07, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
# --- Initialize components for Routine "Debriefing" ---
debriefing_text = visual.TextStim(win=win, name='debriefing_text',
text='Thank you for your participation!\n\nPress [ space ] to end the experiment.',
font='Open Sans',
pos=(0, 0), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
debriefing_keyboard_response = keyboard.Keyboard()
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.Clock() # to track time remaining of each (possibly non-slip) routine
# --- Prepare to start Routine "participant_id" ---
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
participant_idComponents = []
for thisComponent in participant_idComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "participant_id" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in participant_idComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "participant_id" ---
for thisComponent in participant_idComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "participant_id" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "Instruction" ---
continueRoutine = True
# update component parameters for each repeat
instruction_keyboard_response.keys = []
instruction_keyboard_response.rt = []
_instruction_keyboard_response_allKeys = []
# keep track of which components have finished
InstructionComponents = [instruction_text, instruction_keyboard_response]
for thisComponent in InstructionComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "Instruction" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *instruction_text* updates
# if instruction_text is starting this frame...
if instruction_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
instruction_text.frameNStart = frameN # exact frame index
instruction_text.tStart = t # local t and not account for scr refresh
instruction_text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instruction_text, 'tStartRefresh') # time at next scr refresh
# update status
instruction_text.status = STARTED
instruction_text.setAutoDraw(True)
# if instruction_text is active this frame...
if instruction_text.status == STARTED:
# update params
pass
# *instruction_keyboard_response* updates
waitOnFlip = False
# if instruction_keyboard_response is starting this frame...
if instruction_keyboard_response.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
instruction_keyboard_response.frameNStart = frameN # exact frame index
instruction_keyboard_response.tStart = t # local t and not account for scr refresh
instruction_keyboard_response.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instruction_keyboard_response, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'instruction_keyboard_response.started')
# update status
instruction_keyboard_response.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(instruction_keyboard_response.clock.reset) # t=0 on next screen flip
win.callOnFlip(instruction_keyboard_response.clearEvents, eventType='keyboard') # clear events on next screen flip
if instruction_keyboard_response.status == STARTED and not waitOnFlip:
theseKeys = instruction_keyboard_response.getKeys(keyList=['space'], waitRelease=False)
_instruction_keyboard_response_allKeys.extend(theseKeys)
if len(_instruction_keyboard_response_allKeys):
instruction_keyboard_response.keys = _instruction_keyboard_response_allKeys[-1].name # just the last key pressed
instruction_keyboard_response.rt = _instruction_keyboard_response_allKeys[-1].rt
# a response ends the routine
continueRoutine = False
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in InstructionComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "Instruction" ---
for thisComponent in InstructionComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "Instruction" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
practice_block_loop = data.TrialHandler(nReps=1.0, method='random',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions('conditions_practice.csv'),
seed=None, name='practice_block_loop')
thisExp.addLoop(practice_block_loop) # add the loop to the experiment
thisPractice_block_loop = practice_block_loop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisPractice_block_loop.rgb)
if thisPractice_block_loop != None:
for paramName in thisPractice_block_loop:
exec('{} = thisPractice_block_loop[paramName]'.format(paramName))
for thisPractice_block_loop in practice_block_loop:
currentLoop = practice_block_loop
# abbreviate parameter names if possible (e.g. rgb = thisPractice_block_loop.rgb)
if thisPractice_block_loop != None:
for paramName in thisPractice_block_loop:
exec('{} = thisPractice_block_loop[paramName]'.format(paramName))
# --- Prepare to start Routine "ISI" ---
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
ISIComponents = [static_isi]
for thisComponent in ISIComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "ISI" ---
routineForceEnded = not continueRoutine
while continueRoutine and routineTimer.getTime() < 1.0:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *static_isi* period
# if static_isi is starting this frame...
if static_isi.status == NOT_STARTED and frameN >= 0:
# keep track of start time/frame for later
static_isi.frameNStart = frameN # exact frame index
static_isi.tStart = t # local t and not account for scr refresh
static_isi.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(static_isi, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.addData('static_isi.started', t)
# update status
static_isi.status = STARTED
static_isi.start(60*frameDur)
elif static_isi.status == STARTED: # one frame should pass before updating params and completing
static_isi.complete() # finish the static period
static_isi.tStop = static_isi.tStart + 60*frameDur # record stop time
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in ISIComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "ISI" ---
for thisComponent in ISIComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
if routineForceEnded:
routineTimer.reset()
else:
routineTimer.addTime(-1.000000)
# --- Prepare to start Routine "Fixation_pre_cue" ---
continueRoutine = True
# update component parameters for each repeat
# Run 'Begin Routine' code from fixation_pre_set_duration
# Before the fixation cross (the one before the cue) is displayed, randomly
# choose a duration for it. Since we are using seconds as time unit, these
# numbers correspond to 100ms, 350ms, 800ms and 1200ms.
fixation_duration_pre_cue = randchoice([0.1, 0.35, 0.8, 1.2])
# keep track of which components have finished
Fixation_pre_cueComponents = [fixation_pre]
for thisComponent in Fixation_pre_cueComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "Fixation_pre_cue" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *fixation_pre* updates
# if fixation_pre is starting this frame...
if fixation_pre.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_pre.frameNStart = frameN # exact frame index
fixation_pre.tStart = t # local t and not account for scr refresh
fixation_pre.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_pre, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_pre.started')
# update status
fixation_pre.status = STARTED
fixation_pre.setAutoDraw(True)
# if fixation_pre is active this frame...
if fixation_pre.status == STARTED:
# update params
pass
# if fixation_pre is stopping this frame...
if fixation_pre.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation_pre.tStartRefresh + fixation_duration_pre_cue-frameTolerance:
# keep track of stop time/frame for later
fixation_pre.tStop = t # not accounting for scr refresh
fixation_pre.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_pre.stopped')
# update status
fixation_pre.status = FINISHED
fixation_pre.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Fixation_pre_cueComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "Fixation_pre_cue" ---
for thisComponent in Fixation_pre_cueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "Fixation_pre_cue" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "Cue" ---
continueRoutine = True
# update component parameters for each repeat
# Run 'Begin Routine' code from cue_set_text
# Here we set which cue is displayed (a cue is just a text symbol). We check the
# content of the loop variable 'cue', and decide if the cue text should be an
# arrow pointing the left, an arrow pointing to the right or just a circle.
if cue == "left":
cue_path = "img/arrow_left.png"
elif cue == "right":
cue_path = "img/arrow_right.png"
elif cue == "none":
cue_path = "img/neutral.png"
image.setImage(cue_path)
# keep track of which components have finished
CueComponents = [image]
for thisComponent in CueComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "Cue" ---
routineForceEnded = not continueRoutine
while continueRoutine and routineTimer.getTime() < 1.0:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *image* updates
# if image is starting this frame...
if image.status == NOT_STARTED and frameN >= 0:
# keep track of start time/frame for later
image.frameNStart = frameN # exact frame index
image.tStart = t # local t and not account for scr refresh
image.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(image, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'image.started')
# update status
image.status = STARTED
image.setAutoDraw(True)
# if image is active this frame...
if image.status == STARTED:
# update params
pass
# if image is stopping this frame...
if image.status == STARTED:
if frameN >= (image.frameNStart + 60):
# keep track of stop time/frame for later
image.tStop = t # not accounting for scr refresh
image.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'image.stopped')
# update status
image.status = FINISHED
image.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in CueComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "Cue" ---
for thisComponent in CueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
if routineForceEnded:
routineTimer.reset()
else:
routineTimer.addTime(-1.000000)
# --- Prepare to start Routine "Fixation_post_cue" ---
continueRoutine = True
# update component parameters for each repeat
# Run 'Begin Routine' code from fixation_post_set_duration
# Before the fixation cross (the one after the cue) is displayed, randomly
# choose a duration for it. Since we are using seconds as time unit, these
# numbers correspond to 3400ms, 4000ms, 4500ms and 5000ms.
fixation_duration_post_cue = randchoice([3.4, 4, 4.5, 5])
# keep track of which components have finished
Fixation_post_cueComponents = [fixation_post]
for thisComponent in Fixation_post_cueComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "Fixation_post_cue" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *fixation_post* updates
# if fixation_post is starting this frame...
if fixation_post.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_post.frameNStart = frameN # exact frame index
fixation_post.tStart = t # local t and not account for scr refresh
fixation_post.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_post, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_post.started')
# update status
fixation_post.status = STARTED
fixation_post.setAutoDraw(True)
# if fixation_post is active this frame...
if fixation_post.status == STARTED:
# update params
pass
# if fixation_post is stopping this frame...
if fixation_post.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation_post.tStartRefresh + fixation_duration_post_cue-frameTolerance:
# keep track of stop time/frame for later
fixation_post.tStop = t # not accounting for scr refresh
fixation_post.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_post.stopped')
# update status
fixation_post.status = FINISHED
fixation_post.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Fixation_post_cueComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "Fixation_post_cue" ---
for thisComponent in Fixation_post_cueComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "Fixation_post_cue" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "Dots" ---
continueRoutine = True
# update component parameters for each repeat
# Run 'Begin Routine' code from dots_set_direction
if direction == "right":
dots_direction = 0
elif direction == "left":
dots_direction = 180
dots_stimulus.setDir(dots_direction)
dots_stimulus.refreshDots()
dots_keyboard_response.keys = []
dots_keyboard_response.rt = []
_dots_keyboard_response_allKeys = []
# keep track of which components have finished
DotsComponents = [dots_background, dots_stimulus, dots_keyboard_response]
for thisComponent in DotsComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "Dots" ---
routineForceEnded = not continueRoutine
while continueRoutine and routineTimer.getTime() < 1.5:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *dots_background* updates
# if dots_background is starting this frame...
if dots_background.status == NOT_STARTED and frameN >= 0:
# keep track of start time/frame for later
dots_background.frameNStart = frameN # exact frame index
dots_background.tStart = t # local t and not account for scr refresh
dots_background.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(dots_background, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_background.started')
# update status
dots_background.status = STARTED
dots_background.setAutoDraw(True)
# if dots_background is active this frame...
if dots_background.status == STARTED:
# update params
pass
# if dots_background is stopping this frame...
if dots_background.status == STARTED:
if frameN >= (dots_background.frameNStart + 90):
# keep track of stop time/frame for later
dots_background.tStop = t # not accounting for scr refresh
dots_background.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_background.stopped')
# update status
dots_background.status = FINISHED
dots_background.setAutoDraw(False)
# *dots_stimulus* updates
# if dots_stimulus is starting this frame...
if dots_stimulus.status == NOT_STARTED and frameN >= 0:
# keep track of start time/frame for later
dots_stimulus.frameNStart = frameN # exact frame index
dots_stimulus.tStart = t # local t and not account for scr refresh
dots_stimulus.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(dots_stimulus, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_stimulus.started')
# update status
dots_stimulus.status = STARTED
dots_stimulus.setAutoDraw(True)
# if dots_stimulus is active this frame...
if dots_stimulus.status == STARTED:
# update params
pass
# if dots_stimulus is stopping this frame...
if dots_stimulus.status == STARTED:
if frameN >= (dots_stimulus.frameNStart + 90):
# keep track of stop time/frame for later
dots_stimulus.tStop = t # not accounting for scr refresh
dots_stimulus.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_stimulus.stopped')
# update status
dots_stimulus.status = FINISHED
dots_stimulus.setAutoDraw(False)
# *dots_keyboard_response* updates
waitOnFlip = False
# if dots_keyboard_response is starting this frame...
if dots_keyboard_response.status == NOT_STARTED and frameN >= 0:
# keep track of start time/frame for later
dots_keyboard_response.frameNStart = frameN # exact frame index
dots_keyboard_response.tStart = t # local t and not account for scr refresh
dots_keyboard_response.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(dots_keyboard_response, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_keyboard_response.started')
# update status
dots_keyboard_response.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(dots_keyboard_response.clock.reset) # t=0 on next screen flip
win.callOnFlip(dots_keyboard_response.clearEvents, eventType='keyboard') # clear events on next screen flip
# if dots_keyboard_response is stopping this frame...
if dots_keyboard_response.status == STARTED:
if frameN >= (dots_keyboard_response.frameNStart + 90):
# keep track of stop time/frame for later
dots_keyboard_response.tStop = t # not accounting for scr refresh
dots_keyboard_response.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'dots_keyboard_response.stopped')
# update status
dots_keyboard_response.status = FINISHED
dots_keyboard_response.status = FINISHED
if dots_keyboard_response.status == STARTED and not waitOnFlip:
theseKeys = dots_keyboard_response.getKeys(keyList=['f','j'], waitRelease=False)
_dots_keyboard_response_allKeys.extend(theseKeys)
if len(_dots_keyboard_response_allKeys):
dots_keyboard_response.keys = _dots_keyboard_response_allKeys[-1].name # just the last key pressed
dots_keyboard_response.rt = _dots_keyboard_response_allKeys[-1].rt
# a response ends the routine
continueRoutine = False
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in DotsComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "Dots" ---
for thisComponent in DotsComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if dots_keyboard_response.keys in ['', [], None]: # No response was made
dots_keyboard_response.keys = None
practice_block_loop.addData('dots_keyboard_response.keys',dots_keyboard_response.keys)
if dots_keyboard_response.keys != None: # we had a response
practice_block_loop.addData('dots_keyboard_response.rt', dots_keyboard_response.rt)
# using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
if routineForceEnded:
routineTimer.reset()
else:
routineTimer.addTime(-1.500000)
# --- Prepare to start Routine "Feedback" ---
continueRoutine = True
# update component parameters for each repeat
# Run 'Begin Routine' code from feedback_set_text
# If the participant did not respond at all, set the response text to 'miss'.
# You can figure that out by checking whether the given response 'None'.
# 'None' in Python means a values is not defined, so when
# dots_main_keyboard_resp.keys is 'None' we know the participant did not respond.
if dots_keyboard_response.keys is None:
response_text = "miss"
# If the response time (rt) was shorter than 100ms, set the response text to
# 'too fast' (like Mulder et al., 2012 did).
# You can get the response time from the Keyboard component that was used to
# capture the response (name_of_the_keyboard_component.rt).
elif dots_keyboard_response.rt <= 0.1:
response_text = "too fast"
# If the response time was between 100ms and 1500ms (i.e. it was valid), give
# feedback. If the repsonse was also correct, set the response text to '+5 points',
# if it was wrong, set the response text to '+0 points'.
# The variable 'direction' is a loop variable storing the stimulus direction for
# the current trial.
else:
if (direction == "left" and dots_keyboard_response.keys == "f" or
direction == "right" and dots_keyboard_response.keys == "j"
):
response_text = "+5 points"
else:
response_text = "+0 points"
feedback_text.setText(response_text)
# keep track of which components have finished
FeedbackComponents = [feedback_text]
for thisComponent in FeedbackComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None