-
Notifications
You must be signed in to change notification settings - Fork 0
/
Eyetracking_MW_reading6_08_noP_WORKING_lastrun.py
5407 lines (4903 loc) · 233 KB
/
Eyetracking_MW_reading6_08_noP_WORKING_lastrun.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 (v2022.2.5),
on January 19, 2023, at 15:16
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('2022.2.5')
# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, iohub, hardware
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
# 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 = '2022.2.5'
expName = 'Eyetracking_MW_reading6_08_noP_WORKING' # from the Builder filename that created this script
expInfo = {
'participant': '',
'session': '001',
}
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['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='C:\\Users\\BAR Lab\\Desktop\\Leilani MW Eyetracking\\Eyetracking_MW_reading6_08_noP_WORKING_lastrun.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=[1920, 1080], fullscr=False, screen=0,
winType='pyglet', allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
win.mouseVisible = True
# 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 eyetracking
ioConfig['eyetracker.hw.pupil_labs.pupil_core.EyeTracker'] = {
'name': 'tracker',
'runtime_settings': {
'pupillometry_only': False,
'surface_name': 'Monitor',
'gaze_confidence_threshold': 0.6,
'pupil_remote': {
'ip_address': '127.0.0.1',
'port': 50020.0,
'timeout_ms': 1000.0,
},
'pupil_capture_recording': {
'enabled': True,
'location': 'C:/Users/BAR Lab/Desktop/Leilani MW Eyetracking/EyeData',
}
}
}
# 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 = ioServer.getDevice('tracker')
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend='iohub')
# --- Initialize components for Routine "Launch" ---
# Run 'Begin Experiment' code from code
#import what we need to generate a random number
import random, xlrd
import time
#Use the machine time as a seed to generate a random number from (allows for closer to "truly random" numbers)
random.seed(time.process_time())
#set variable myRand to a random number (either 1 or 2); myRandP (EITHER 3 OR 4)
rand = random.randint(1,2) #random number for choosing experimental condition order
randP = random.randint(3,4) #random number for choosing reading pages order
#set new variable 'currCondition' depending on what random number we generated
if rand == 1:
#50% chance of being in the PC condition
currCondition = "PC"
elif rand == 2:
#50% chance of being in the SC condition
currCondition = "SC"
#CREATE A VARIABLE CALLED currConditionP and set it depending on randP
if randP == 3:
#50% chance of being Tropo pages
currConditionP = "Tropo"
elif randP == 4:
#50% chance of being Life pages
currConditionP = "Life"
#For testing purposes we can set our condition and pages here.
#Just comment out the two lines below to run the experiment randomly.
currCondition = "SC"
#currConditionP = "Tropo"
# --- Initialize components for Routine "Welcome" ---
Welcome_text = visual.TextStim(win=win, name='Welcome_text',
text='Welcome to the experiment!\n\nBefore we begin, please complete the following multiple choice questions by using the number keys to enter your answers.\n\n\n(Press the spacebar to continue)',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
Welcome_text_resp = keyboard.Keyboard()
# --- Initialize components for Routine "DemographicQs" ---
DemoQs = visual.ImageStim(
win=win,
name='DemoQs',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.7),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
DemographicQs_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "AgeQuestion" ---
AgeQuestion_textbox = visual.TextBox2(
win, text=None, font='Open Sans',
pos=(0, -0.15), letterHeight=0.05,
size=(None, None), borderWidth=2.0,
color='white', colorSpace='rgb',
opacity=None,
bold=False, italic=False,
lineSpacing=1.0,
padding=0.0, alignment='center',
anchor='center',
fillColor=None, borderColor=None,
flipHoriz=False, flipVert=False, languageStyle='LTR',
editable=True,
name='AgeQuestion_textbox',
autoLog=True,
)
text_4 = visual.TextStim(win=win, name='text_4',
text="Using the number keys please enter your age. Then press 'space' to continue.",
font='Open Sans',
pos=(0, 0.2), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
Age_resp = keyboard.Keyboard()
# --- Initialize components for Routine "AQintro" ---
text_3 = visual.TextStim(win=win, name='text_3',
text='Please answer the following questions.\n\n\n\n(Press the spacebar to continue.)',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
AQintro_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "AQ_10_Qs" ---
AQ_10 = visual.ImageStim(
win=win,
name='AQ_10',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.7),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
AQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank500" ---
text_2 = visual.TextStim(win=win, name='text_2',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "adhdQ1_2" ---
adhdQ = visual.TextStim(win=win, name='adhdQ',
text='',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
Qanswer = visual.TextStim(win=win, name='Qanswer',
text='',
font='Open Sans',
pos=(0, -0.3), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
key_QA = keyboard.Keyboard()
# --- Initialize components for Routine "blank500" ---
text_2 = visual.TextStim(win=win, name='text_2',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "AlwaysQ" ---
AlwaysQText = visual.TextStim(win=win, name='AlwaysQText',
text='',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
AlwaysAnswer = visual.TextStim(win=win, name='AlwaysAnswer',
text='1. Yes\n2. No',
font='Open Sans',
pos=(0, -0.3), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-2.0);
key_AlwaysResp = keyboard.Keyboard()
# --- Initialize components for Routine "blank500" ---
text_2 = visual.TextStim(win=win, name='text_2',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "adhdDx" ---
adhdDxQ = visual.TextStim(win=win, name='adhdDxQ',
text='Have you ever been given an official diagnosis of attention-deficit / hyperactivity disorder (ADHD) (e.g., by a registered psychologist, psychiatrist, counsellor, etc.)?',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
Dx_answer = visual.TextStim(win=win, name='Dx_answer',
text='1. Yes\n2. No\n3. No, but I strongly suspect I might have ADHD',
font='Open Sans',
pos=(0, -.3), height=0.04, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-1.0);
key_Dx = keyboard.Keyboard()
# --- Initialize components for Routine "setFiles" ---
# Run 'Begin Experiment' code from code_8
#SETTING ALL OUR FILE VARIABLES FOR THE EXPERIMENT BASED ON currCondition AND currConditionPs
if currCondition == "PC":
#if we're in the PC condition then show the PC instructions first run and the SC instructions second run
InstrFile = "InstrFile/Instr_PC.csv"
InstrFile2 = "InstrFile/Instr_SC_v2.csv"
#if we're in the PC condition then show the PC probe message first run and the SC probe message second run
probeMessage = "Remember, when the probe appears on screen: \n Press 'i' if your MW was intentional (on purpose), or 'u' if it was unintentional (just happened on its own). \n Press '0' if you were not experiencing MW when the probe appeared."
probeMessage2 = "Remember: Press '1' any time you catch yourself mind wandering (MW). \n When prompted, press 'i' if your MW was intentional (on purpose), or 'u' if it was unintentional (just happened on its own)."
elif currCondition == "SC":
#if we're in the SC condition then show the SC instructions first run and the PC instructions second run
InstrFile = "InstrFile/Instr_SC.csv"
InstrFile2 = "InstrFile/Instr_PC_v2.csv"
#if we're in the SC condition then show the SC probe message first run and the PC probe message second run
probeMessage = "Remember: Press '1' any time you catch yourself mind wandering (MW). \n When prompted, press 'i' if your MW was intentional (on purpose), or 'u' if it was unintentional (just happened on its own)."
probeMessage2 = "Remember, when the probe appears on screen: \n Press 'i' if your MW was intentional (on purpose), or 'u' if it was unintentional (just happened on its own). \n Press '0' if you were not experiencing MW when the probe appeared."
if currConditionP == "Life":
#if we're in the Life condition then show LifePages first run and TropoPages second run
stimFile = "LifePages.csv"
stimFile2 = "TropoPages.csv"
#if we're in the Life condition then show Life quiz questions first run and Tropo quiz questions second run
quizFile = "lifeQs.csv"
quizFile2 = "tropoQs.csv"
elif currConditionP == "Tropo":
#if we're in the Tropo condition then show TropoPages first run and LifePages second run
stimFile = "TropoPages.csv"
stimFile2 = "LifePages.csv"
#if we're in the Tropo condition then show Tropo quiz questions first run and Life quiz questions second run
quizFile = "tropoQs.csv"
quizFile2 = "lifeQs.csv"
#All the above variables will be used in later components as such:
#InstrFile used in MWdefinitions loop as the csv file to pull instruction images from
#InstrFile2 used in MWdefinitions2 loop as the csv file to pull instruction images from
#probeMessage used in IntroExp as display text
#probeMessage2 used in IntroExp2 as display text
#stimFile used in ReadingLoop as the csv file to pull reading page images from
#stimFile2 used in ReadingLoop2 as the csv file to pull reading page images from
#quizFile used in QuizLoop as the csv file to pull quiz question images from
#quizFile2 used in QuizLoop2 as the csv file to pull quiz question images from
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "MW_def" ---
MWdefInstr = visual.ImageStim(
win=win,
name='MWdefInstr',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
MWdefInstr_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "IntroExp" ---
text = visual.TextStim(win=win, name='text',
text=probeMessage,
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=1.0,
languageStyle='LTR',
depth=0.0);
IntroExp_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "PageSkipping" ---
NoSkipping = visual.TextStim(win=win, name='NoSkipping',
text='Please read at your normal pace and do not skip pages.\n\n\n(press spacebar to continue)',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
key_Skip = keyboard.Keyboard()
# --- Initialize components for Routine "EYE_RECORD_START" ---
etRecord_START = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Start Only'
)
# --- Initialize components for Routine "Reading" ---
# Run 'Begin Experiment' code from code_3
##ONE TIME INITIALIZATION START
#setting a bunch of defaults here (we will reset these in every practice or reading loop)
opacityImage1 = 0 #PC image opacity (by default our probe and intentionality images are hidden)
opacityImage2 = 0 #SC image opacity
time1=0 #variables for recording response time data
time2=0
resp1=0 #variables for recording key press data
resp2=0
printNow = 0 #used to trigger data writing to output file
keys = "" #stores keypress values
#these three variables are used to start our timers at the right spot and avoid some edge cases
firstLoop2 = True
firstRoutine2 = True
timerStarted2 = False
#start two clocks
mainTimer2 = core.Clock() # this one just runs for the whole PracticeTrial loop
probeTimer2 = core.Clock() # this one stops and restarts every time one of our probe/intentionality images pops up
myCount = 1 #this counts up and tells which value from the probe list we should use
# import some stuff just in case
import random, copy
from random import randint
from decimal import *
import csv
from numpy import *
from psychopy import core, event
event.getKeys() #clear the keyboard buffer just in case they recently pressed a relevant key
##ONE TIME INITIALIZATION END
#Counter for iterating through our probe2 list
myCount2 = 1
event.clearEvents() #clear events just in case they recently pressed a relevant key
# here's a list of the time in seconds between probes
# change this to adjust the probes for the Reading loop
probe2 = [0,91,112,74,98,113,62,92,79,76,62]
# first item in probe, 0, never happens because myCount starts at 1
Reading_key_resp = keyboard.Keyboard()
imagePages = visual.ImageStim(
win=win,
name='imagePages',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.85, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1.0,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
PCProbe = visual.ImageStim(
win=win,
name='PCProbe',
image='images/PC_v2.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1.0,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
SCProbe = visual.ImageStim(
win=win,
name='SCProbe',
image='images/SC_v2.png', mask=None, anchor='center',
ori=0, pos=(0, 0), size=(1, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1.0,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-4.0)
# --- Initialize components for Routine "EYE_RECORD_STOP" ---
EYE_Record_STOP = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Stop Only'
)
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "Quiz" ---
QuizQuestion = visual.ImageStim(
win=win,
name='QuizQuestion',
image='sin', mask=None, anchor='center',
ori=0, pos=(0, 0), size=(0.8, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=0.0)
Quiz_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "InterestingQ" ---
interestingImage = visual.ImageStim(
win=win,
name='interestingImage',
image='QuizQs/Likert_interest.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
InterestingQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "DifficultyQ" ---
difficultyImage = visual.ImageStim(
win=win,
name='difficultyImage',
image='QuizQs/Likert_difficulty.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
DifficultyQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "Likert_Mot" ---
MW_mot = visual.ImageStim(
win=win,
name='MW_mot',
image='QuizQs/Likert_motivation.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
MW_motQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "unIntMWcapture" ---
MWunint = visual.ImageStim(
win=win,
name='MWunint',
image='QuizQs/Likert_unintMW.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
unintMWkey_resp_2 = keyboard.Keyboard()
# --- Initialize components for Routine "intMWcaptureQ" ---
MWcaptureImage = visual.ImageStim(
win=win,
name='MWcaptureImage',
image='QuizQs/Likert_intMW.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
intMWcaptureQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "Halfway" ---
HalfwayText = visual.TextStim(win=win, name='HalfwayText',
text='Thank you for completing the first half of the experiment.\n\nBefore beginning the second half, please let the research assistant know if you have any questions or if you need a short break.\n\n(Press the spacebar to continue)',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
HalfwayResp = keyboard.Keyboard()
# --- Initialize components for Routine "MW_def2" ---
MWdef_image = visual.ImageStim(
win=win,
name='MWdef_image',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
MW_def2_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "IntroExp2" ---
probe_message = visual.TextStim(win=win, name='probe_message',
text=probeMessage2,
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
IntroExp2_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "EYE_RECORD_START" ---
etRecord_START = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Start Only'
)
# --- Initialize components for Routine "Reading2" ---
Reading2_key_resp = keyboard.Keyboard()
imagePages2 = visual.ImageStim(
win=win,
name='imagePages2',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.85, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
PCProbe2 = visual.ImageStim(
win=win,
name='PCProbe2',
image='images/PC_v2.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1.0,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
SCProbe2 = visual.ImageStim(
win=win,
name='SCProbe2',
image='images/SC_v2.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1.0,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
# Run 'Begin Experiment' code from code_2
#use new true/false variables so that the values from our Practice loop don't affect the functionality of the Reading loop
firstLoop4 = True
firstRoutine4 = True
timerStarted4 = False
#start two new clocks so the values of the previous clocks don't affect this loop
mainTimer4 = core.Clock()
probeTimer4 = core.Clock()
#create a new counter so the value of our old counter doesn't carry over to this loop
myCount4 = 1
event.clearEvents()
# here's a list of the time in seconds between probes
# change this to adjust the probes for the Quiz2 loop
probe4 = [0,91,112,74,98,113,62,92,79,76,62]
# first item in probe, 0, never happens because myCount starts at 1
# --- Initialize components for Routine "EYE_RECORD_STOP" ---
EYE_Record_STOP = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Stop Only'
)
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "Quiz2" ---
QuizQuestion2 = visual.ImageStim(
win=win,
name='QuizQuestion2',
image='sin', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.8, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
Quiz2_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "InterestingQ" ---
interestingImage = visual.ImageStim(
win=win,
name='interestingImage',
image='QuizQs/Likert_interest.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
InterestingQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "DifficultyQ" ---
difficultyImage = visual.ImageStim(
win=win,
name='difficultyImage',
image='QuizQs/Likert_difficulty.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
DifficultyQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "Likert_Mot" ---
MW_mot = visual.ImageStim(
win=win,
name='MW_mot',
image='QuizQs/Likert_motivation.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
MW_motQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "unIntMWcapture" ---
MWunint = visual.ImageStim(
win=win,
name='MWunint',
image='QuizQs/Likert_unintMW.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1.0, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
unintMWkey_resp_2 = keyboard.Keyboard()
# --- Initialize components for Routine "intMWcaptureQ" ---
MWcaptureImage = visual.ImageStim(
win=win,
name='MWcaptureImage',
image='QuizQs/Likert_intMW.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(1, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
intMWcaptureQ_key_resp = keyboard.Keyboard()
# --- Initialize components for Routine "blank" ---
textInterval = visual.TextStim(win=win, name='textInterval',
text=None,
font='Open Sans',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "EndText" ---
EndExpText = visual.TextStim(win=win, name='EndExpText',
text="Thank you for participating in this experiment!\n\nPlease let the research assistant know if you would like to be debriefed.\n\nThank you!\n\n(Press 'space' to continue)",
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
key_resp = 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
# define target for calibration
calibrationTarget = visual.TargetStim(win,
name='calibrationTarget',
radius=0.01, fillColor='', borderColor='black', lineWidth=2.0,
innerRadius=0.0035, innerFillColor='green', innerBorderColor='black', innerLineWidth=2.0,
colorSpace='hsv', units=None
)
# define parameters for calibration
calibration = hardware.eyetracker.EyetrackerCalibration(win,
eyetracker, calibrationTarget,
units=None, colorSpace='hsv',
progressMode='time', targetDur=1.5, expandScale=1.5,
targetLayout='FIVE_POINTS', randomisePos=True, textColor='white',
movementAnimation=False, targetDelay=1.0
)
# run calibration
calibration.run()
# clear any keypresses from during calibration so they don't interfere with the experiment
defaultKeyboard.clearEvents()
# the Routine "calibration" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# define target for validation
validationTarget = visual.TargetStim(win,
name='validationTarget',
radius=0.05, fillColor=[1.0000, 1.0000, 1.0000], borderColor='black', lineWidth=5.0,
innerRadius=0.01, innerFillColor='green', innerBorderColor='black', innerLineWidth=5.0,
colorSpace='rgb', units=None
)
# define parameters for validation
validation = iohub.ValidationProcedure(win,
target=validationTarget,
gaze_cursor='green',
positions='FIVE_POINTS', randomize_positions=True,
expand_scale=1.5, target_duration=1.5,
enable_position_animation=True, target_delay=1.0,
progress_on_key=None, text_color='auto',
show_results_screen=True, save_results_screen=True,
color_space='rgb', unit_type=None
)
# run validation
validation.run()
# clear any keypresses from during validation so they don't interfere with the experiment
defaultKeyboard.clearEvents()
# the Routine "validation" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "Launch" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
# keep track of which components have finished
LaunchComponents = []
for thisComponent in LaunchComponents:
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 "Launch" ---
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 LaunchComponents:
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 "Launch" ---
for thisComponent in LaunchComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "Launch" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "Welcome" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
Welcome_text_resp.keys = []
Welcome_text_resp.rt = []
_Welcome_text_resp_allKeys = []
# keep track of which components have finished
WelcomeComponents = [Welcome_text, Welcome_text_resp]
for thisComponent in WelcomeComponents:
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 "Welcome" ---
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
# *Welcome_text* updates
if Welcome_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
Welcome_text.frameNStart = frameN # exact frame index
Welcome_text.tStart = t # local t and not account for scr refresh
Welcome_text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(Welcome_text, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'Welcome_text.started')
Welcome_text.setAutoDraw(True)
# *Welcome_text_resp* updates
waitOnFlip = False
if Welcome_text_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
Welcome_text_resp.frameNStart = frameN # exact frame index
Welcome_text_resp.tStart = t # local t and not account for scr refresh
Welcome_text_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(Welcome_text_resp, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'Welcome_text_resp.started')
Welcome_text_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(Welcome_text_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(Welcome_text_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if Welcome_text_resp.status == STARTED and not waitOnFlip:
theseKeys = Welcome_text_resp.getKeys(keyList=['space'], waitRelease=False)
_Welcome_text_resp_allKeys.extend(theseKeys)
if len(_Welcome_text_resp_allKeys):
Welcome_text_resp.keys = _Welcome_text_resp_allKeys[-1].name # just the last key pressed
Welcome_text_resp.rt = _Welcome_text_resp_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 WelcomeComponents:
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 "Welcome" ---
for thisComponent in WelcomeComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if Welcome_text_resp.keys in ['', [], None]: # No response was made
Welcome_text_resp.keys = None
thisExp.addData('Welcome_text_resp.keys',Welcome_text_resp.keys)
if Welcome_text_resp.keys != None: # we had a response
thisExp.addData('Welcome_text_resp.rt', Welcome_text_resp.rt)
thisExp.nextEntry()
# the Routine "Welcome" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
Demographic_Loop = data.TrialHandler(nReps=1.0, method='sequential',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions('chooseDemoQs.csv'),
seed=None, name='Demographic_Loop')
thisExp.addLoop(Demographic_Loop) # add the loop to the experiment
thisDemographic_Loop = Demographic_Loop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisDemographic_Loop.rgb)
if thisDemographic_Loop != None:
for paramName in thisDemographic_Loop:
exec('{} = thisDemographic_Loop[paramName]'.format(paramName))
for thisDemographic_Loop in Demographic_Loop:
currentLoop = Demographic_Loop
# abbreviate parameter names if possible (e.g. rgb = thisDemographic_Loop.rgb)
if thisDemographic_Loop != None:
for paramName in thisDemographic_Loop:
exec('{} = thisDemographic_Loop[paramName]'.format(paramName))
# --- Prepare to start Routine "DemographicQs" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
DemoQs.setImage(chDemoQs)
DemographicQs_resp.keys = []
DemographicQs_resp.rt = []
_DemographicQs_resp_allKeys = []
# keep track of which components have finished
DemographicQsComponents = [DemoQs, DemographicQs_resp]
for thisComponent in DemographicQsComponents:
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 "DemographicQs" ---
while continueRoutine:
# get current time
t = routineTimer.getTime()