forked from emmetaobrien/semt-encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSEMT.py
More file actions
2364 lines (2127 loc) · 109 KB
/
SEMT.py
File metadata and controls
2364 lines (2127 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 (v2021.1.4),
on March 15, 2023, at 12:32
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
"""
from __future__ import absolute_import, division
import psychopy
psychopy.useVersion('2021.1.4')
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors
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
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 = '2021.1.4'
expName = 'SEMT' # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
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_%s' % (expInfo['participant'], expName, expInfo['date'], expInfo['session'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='C:\\Users\\BIG Birtha\\Documents\\Lepage\\SEMT CogMP\\final_both conditions\\SEMT _ 4 conditions\\SEMT.py',
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.DEBUG)
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
from psychopy.hardware import joystick as joysticklib # joystick/gamepad accsss
from psychopy.experiment.components.joystick import virtualJoystick as virtualjoysticklib
from psychopy.hardware import joystick as joysticklib # joystick/gamepad accsss
from psychopy.experiment.components.joystick import virtualJoystick as virtualjoysticklib
from psychopy.hardware import joystick as joysticklib # joystick/gamepad accsss
from psychopy.experiment.components.joystick import virtualJoystick as virtualjoysticklib
from psychopy.hardware import joystick as joysticklib # joystick/gamepad accsss
from psychopy.experiment.components.joystick import virtualJoystick as virtualjoysticklib
# Setup the Window
win = visual.Window(
size=[1600, 900], fullscr=True, screen=1,
winType='pyglet', allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[1,1,1], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
# 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
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard()
# Initialize components for Routine "lang"
langClock = core.Clock()
import re, time
from datetime import datetime
# Save starting session time
startingTime = datetime.now().strftime("%H:%M:%S.%f")
startingTime = "\'"+startingTime
print("Starting time: ", startingTime)
#startingTime = datetime.utcnow().strftime("%H:%M:%S.%f")[:-3]
thisExp.addData("SessionTime", startingTime)
thisExp.addData("SessionTime.RTTime", core.Clock().getTime())
# Remove illegal characters in participants' name to avoid errors in filenames
expInfo['participant']= re.sub('[^A-Za-z0-9]+', '', expInfo['participant'])
# No buttons is currently pressed
button_down = False
text_lang = visual.TextStim(win=win, name='text_lang',
text='Veuillez sélectionner votre langue.\nAppuyez sur 1 pour Français.\n\nPlease select your language.\nPress 2 for English.',
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
x, y = [None, None]
joystick_lang = type('', (), {})() # Create an object to use as a name space
joystick_lang.device = None
joystick_lang.device_number = 0
joystick_lang.joystickClock = core.Clock()
joystick_lang.xFactor = 1
joystick_lang.yFactor = 1
try:
numJoysticks = joysticklib.getNumJoysticks()
if numJoysticks > 0:
try:
joystickCache
except NameError:
joystickCache={}
if not 0 in joystickCache:
joystickCache[0] = joysticklib.Joystick(0)
joystick_lang.device = joystickCache[0]
if win.units == 'height':
joystick_lang.xFactor = 0.5 * win.size[0]/win.size[1]
joystick_lang.yFactor = 0.5
else:
joystick_lang.device = virtualjoysticklib.VirtualJoystick(0)
logging.warning("joystick_{}: Using keyboard+mouse emulation 'ctrl' + 'Alt' + digit.".format(joystick_lang.device_number))
except Exception:
pass
if not joystick_lang.device:
logging.error('No joystick/gamepad device found.')
core.quit()
joystick_lang.status = None
joystick_lang.clock = core.Clock()
joystick_lang.numButtons = joystick_lang.device.getNumButtons()
joystick_lang.getNumButtons = joystick_lang.device.getNumButtons
joystick_lang.getAllButtons = joystick_lang.device.getAllButtons
joystick_lang.getX = lambda: joystick_lang.xFactor * joystick_lang.device.getX()
joystick_lang.getY = lambda: joystick_lang.yFactor * joystick_lang.device.getY()
key_lang = keyboard.Keyboard()
# Initialize components for Routine "instr"
instrClock = core.Clock()
instr_text_1 = visual.TextStim(win=win, name='instr_text_1',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
instr_text_2 = visual.TextStim(win=win, name='instr_text_2',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-2.0);
instr_text_3 = visual.TextStim(win=win, name='instr_text_3',
text='Any text\n\nincluding line breaks',
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-3.0);
instr_text_4 = visual.TextStim(win=win, name='instr_text_4',
text='Any text\n\nincluding line breaks',
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-4.0);
instr_text_5 = visual.TextStim(win=win, name='instr_text_5',
text='Any text\n\nincluding line breaks',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=1.1, ori=0.0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1.0,
languageStyle='LTR',
depth=-5.0);
x, y = [None, None]
joystick_instr = type('', (), {})() # Create an object to use as a name space
joystick_instr.device = None
joystick_instr.device_number = 0
joystick_instr.joystickClock = core.Clock()
joystick_instr.xFactor = 1
joystick_instr.yFactor = 1
try:
numJoysticks = joysticklib.getNumJoysticks()
if numJoysticks > 0:
try:
joystickCache
except NameError:
joystickCache={}
if not 0 in joystickCache:
joystickCache[0] = joysticklib.Joystick(0)
joystick_instr.device = joystickCache[0]
if win.units == 'height':
joystick_instr.xFactor = 0.5 * win.size[0]/win.size[1]
joystick_instr.yFactor = 0.5
else:
joystick_instr.device = virtualjoysticklib.VirtualJoystick(0)
logging.warning("joystick_{}: Using keyboard+mouse emulation 'ctrl' + 'Alt' + digit.".format(joystick_instr.device_number))
except Exception:
pass
if not joystick_instr.device:
logging.error('No joystick/gamepad device found.')
core.quit()
joystick_instr.status = None
joystick_instr.clock = core.Clock()
joystick_instr.numButtons = joystick_instr.device.getNumButtons()
joystick_instr.getNumButtons = joystick_instr.device.getNumButtons
joystick_instr.getAllButtons = joystick_instr.device.getAllButtons
joystick_instr.getX = lambda: joystick_instr.xFactor * joystick_instr.device.getX()
joystick_instr.getY = lambda: joystick_instr.yFactor * joystick_instr.device.getY()
# Initialize components for Routine "prac"
pracClock = core.Clock()
# Store frame rate of the monitor so we can time our stimuli more precisely
#expInfo['frameRate'] = win.getActualFrameRate()
#frameRate = round(expInfo['frameRate'])
item1_img_pr = visual.ImageStim(
win=win,
name='item1_img_pr',
image='sin', mask=None,
ori=0, pos=(0, 0), size=None,
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-1.0)
brL_img_pr = visual.ImageStim(
win=win,
name='brL_img_pr',
image='left_cr.jpg', mask=None,
ori=0, pos=(-0.6, 0), size=(0.1, 0.6),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-2.0)
que_text_pr = visual.TextStim(win=win, name='que_text_pr',
text=None,
font='Arial',
pos=(0, 0), height=0.06, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-3.0);
item2_img_pr = visual.ImageStim(
win=win,
name='item2_img_pr',
image='sin', mask=None,
ori=0, pos=(0, 0), size=None,
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-4.0)
brR_img_pr = visual.ImageStim(
win=win,
name='brR_img_pr',
image='right_cr.jpg', mask=None,
ori=0, pos=(0.6, 0), size=(0.1, 0.6),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-5.0)
response_pr = visual.TextStim(win=win, name='response_pr',
text=None,
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=0,
languageStyle='LTR',
depth=-6.0);
timer_pr = visual.TextStim(win=win, name='timer_pr',
text=None,
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=0,
languageStyle='LTR',
depth=-7.0);
fix_text_pr = visual.TextStim(win=win, name='fix_text_pr',
text='+',
font='Arial',
pos=(0, 0), height=0.11, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-8.0);
key_prac = keyboard.Keyboard()
x, y = [None, None]
joystick_prac = type('', (), {})() # Create an object to use as a name space
joystick_prac.device = None
joystick_prac.device_number = 0
joystick_prac.joystickClock = core.Clock()
joystick_prac.xFactor = 1
joystick_prac.yFactor = 1
try:
numJoysticks = joysticklib.getNumJoysticks()
if numJoysticks > 0:
try:
joystickCache
except NameError:
joystickCache={}
if not 0 in joystickCache:
joystickCache[0] = joysticklib.Joystick(0)
joystick_prac.device = joystickCache[0]
if win.units == 'height':
joystick_prac.xFactor = 0.5 * win.size[0]/win.size[1]
joystick_prac.yFactor = 0.5
else:
joystick_prac.device = virtualjoysticklib.VirtualJoystick(0)
logging.warning("joystick_{}: Using keyboard+mouse emulation 'ctrl' + 'Alt' + digit.".format(joystick_prac.device_number))
except Exception:
pass
if not joystick_prac.device:
logging.error('No joystick/gamepad device found.')
core.quit()
joystick_prac.status = None
joystick_prac.clock = core.Clock()
joystick_prac.numButtons = joystick_prac.device.getNumButtons()
joystick_prac.getNumButtons = joystick_prac.device.getNumButtons
joystick_prac.getAllButtons = joystick_prac.device.getAllButtons
joystick_prac.getX = lambda: joystick_prac.xFactor * joystick_prac.device.getX()
joystick_prac.getY = lambda: joystick_prac.yFactor * joystick_prac.device.getY()
# Initialize components for Routine "transition"
transitionClock = core.Clock()
txt_transi = visual.TextStim(win=win, name='txt_transi',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
key_transi = keyboard.Keyboard()
# Initialize components for Routine "ready"
readyClock = core.Clock()
txt_rdy = visual.TextStim(win=win, name='txt_rdy',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=1.1, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
key_rdy = keyboard.Keyboard()
# Initialize components for Routine "cntdown"
cntdownClock = core.Clock()
timer_ctdown = visual.TextStim(win=win, name='timer_ctdown',
text='',
font='Arial',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
# Initialize components for Routine "trial"
trialClock = core.Clock()
item1_img = visual.ImageStim(
win=win,
name='item1_img',
image='sin', mask=None,
ori=0, pos=(0, 0), size=None,
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-1.0)
brL_img = visual.ImageStim(
win=win,
name='brL_img',
image='left_cr.jpg', mask=None,
ori=0, pos=(-0.6, 0), size=(0.1, 0.6),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-2.0)
que_text = visual.TextStim(win=win, name='que_text',
text=None,
font='Arial',
pos=(0, 0), height=0.06, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-3.0);
item2_img = visual.ImageStim(
win=win,
name='item2_img',
image='sin', mask=None,
ori=0, pos=(0, 0), size=None,
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-4.0)
brR_img = visual.ImageStim(
win=win,
name='brR_img',
image='right_cr.jpg', mask=None,
ori=0, pos=(0.6, 0), size=(0.1, 0.6),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=False, depth=-5.0)
response = visual.TextStim(win=win, name='response',
text=None,
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=0,
languageStyle='LTR',
depth=-6.0);
timer = visual.TextStim(win=win, name='timer',
text=None,
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=0,
languageStyle='LTR',
depth=-7.0);
fix_text = visual.TextStim(win=win, name='fix_text',
text='+',
font='Arial',
pos=(0, 0), height=0.11, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-8.0);
key = keyboard.Keyboard()
x, y = [None, None]
joystick = type('', (), {})() # Create an object to use as a name space
joystick.device = None
joystick.device_number = 0
joystick.joystickClock = core.Clock()
joystick.xFactor = 1
joystick.yFactor = 1
try:
numJoysticks = joysticklib.getNumJoysticks()
if numJoysticks > 0:
try:
joystickCache
except NameError:
joystickCache={}
if not 0 in joystickCache:
joystickCache[0] = joysticklib.Joystick(0)
joystick.device = joystickCache[0]
if win.units == 'height':
joystick.xFactor = 0.5 * win.size[0]/win.size[1]
joystick.yFactor = 0.5
else:
joystick.device = virtualjoysticklib.VirtualJoystick(0)
logging.warning("joystick_{}: Using keyboard+mouse emulation 'ctrl' + 'Alt' + digit.".format(joystick.device_number))
except Exception:
pass
if not joystick.device:
logging.error('No joystick/gamepad device found.')
core.quit()
joystick.status = None
joystick.clock = core.Clock()
joystick.numButtons = joystick.device.getNumButtons()
joystick.getNumButtons = joystick.device.getNumButtons
joystick.getAllButtons = joystick.device.getAllButtons
joystick.getX = lambda: joystick.xFactor * joystick.device.getX()
joystick.getY = lambda: joystick.yFactor * joystick.device.getY()
# Initialize components for Routine "rest"
restClock = core.Clock()
txt_rest = visual.TextStim(win=win, name='txt_rest',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
key_rest = keyboard.Keyboard()
# Initialize components for Routine "ready_2"
ready_2Clock = core.Clock()
txt_rdy2 = visual.TextStim(win=win, name='txt_rdy2',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
key_rdy2 = keyboard.Keyboard()
# Initialize components for Routine "cntdown_2"
cntdown_2Clock = core.Clock()
timer_ctdown2 = visual.TextStim(win=win, name='timer_ctdown2',
text='',
font='Arial',
pos=(0, 0), height=0.08, wrapWidth=None, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
# Initialize components for Routine "thanks"
thanksClock = core.Clock()
txt_thx = visual.TextStim(win=win, name='txt_thx',
text=None,
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=1.1, ori=0,
color=[-1,-1,-1], colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.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
# ------Prepare to start Routine "lang"-------
continueRoutine = True
# update component parameters for each repeat
# Joystick's button is not pressed by default
button_down = False
joystick_lang.oldButtonState = joystick_lang.device.getAllButtons()[:]
joystick_lang.activeButtons=[0, 1]
# setup some python lists for storing info about the joystick_lang
gotValidClick = False # until a click is received
key_lang.keys = []
key_lang.rt = []
_key_lang_allKeys = []
# keep track of which components have finished
langComponents = [text_lang, joystick_lang, key_lang]
for thisComponent in langComponents:
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")
langClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "lang"-------
while continueRoutine:
# get current time
t = langClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=langClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
#Perform actions depending to the pressed button/key
#Set french or english variable to true when the language is selected
if joystick_lang.getAllButtons()[1] or "1" in key_lang.keys:
french = True
english = False
pracConditions = "SEMT_conditions_prac.csv"
trialConditions = "SEMT_conditions_trials_bloc1.csv"
text_lang.finished = True
continueRoutine = False
elif joystick_lang.getAllButtons()[2] or "2" in key_lang.keys:
french = False
english = True
pracConditions = "SEMT_conditions_prac.csv"
trialConditions = "SEMT_conditions_trials_bloc1.csv"
text_lang.finished = True
continueRoutine = False
# *text_lang* updates
if text_lang.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text_lang.frameNStart = frameN # exact frame index
text_lang.tStart = t # local t and not account for scr refresh
text_lang.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text_lang, 'tStartRefresh') # time at next scr refresh
text_lang.setAutoDraw(True)
# *key_lang* updates
waitOnFlip = False
if key_lang.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
key_lang.frameNStart = frameN # exact frame index
key_lang.tStart = t # local t and not account for scr refresh
key_lang.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(key_lang, 'tStartRefresh') # time at next scr refresh
key_lang.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(key_lang.clock.reset) # t=0 on next screen flip
win.callOnFlip(key_lang.clearEvents, eventType='keyboard') # clear events on next screen flip
if key_lang.status == STARTED and not waitOnFlip:
theseKeys = key_lang.getKeys(keyList=['1', '2', 'esc'], waitRelease=False)
_key_lang_allKeys.extend(theseKeys)
if len(_key_lang_allKeys):
key_lang.keys = _key_lang_allKeys[-1].name # just the last key pressed
key_lang.rt = _key_lang_allKeys[-1].rt
# 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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in langComponents:
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 "lang"-------
for thisComponent in langComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
lang = 'en' if english==True else 'fr'
thisExp.addData('language', lang)
button_down = True
thisExp.addData('text_lang.started', text_lang.tStartRefresh)
thisExp.addData('text_lang.stopped', text_lang.tStopRefresh)
# store data for thisExp (ExperimentHandler)
# store data for thisExp (ExperimentHandler)
x, y = joystick_lang.getX(), joystick_lang.getY()
joystick_lang.newButtonState = joystick_lang.getAllButtons()[:]
joystick_lang.pressedState = [joystick_lang.newButtonState[i] for i in range(joystick_lang.numButtons)]
joystick_lang.time = joystick_lang.joystickClock.getTime()
thisExp.addData('joystick_lang.x', x)
thisExp.addData('joystick_lang.y', y)
[thisExp.addData('joystick_lang.button_{0}'.format(i), int(joystick_lang.pressedState[i])) for i in joystick_lang.activeButtons]
thisExp.addData('joystick_lang.time', joystick_lang.time)
thisExp.addData('joystick_lang.started', joystick_lang.tStart)
thisExp.addData('joystick_lang.stopped', joystick_lang.tStop)
thisExp.nextEntry()
# check responses
if key_lang.keys in ['', [], None]: # No response was made
key_lang.keys = None
thisExp.addData('key_lang.keys',key_lang.keys)
if key_lang.keys != None: # we had a response
thisExp.addData('key_lang.rt', key_lang.rt)
thisExp.nextEntry()
# the Routine "lang" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "instr"-------
continueRoutine = True
# update component parameters for each repeat
# Find a font that is available on the system.
#fm = visual.textbox2.getFontManager()
#available_font_names=fm.getFontFamilyStyles()
#print(available_font_names)
#Change displayed text based on the language previously chosen
if english == True:
instr_text_1.text = "Hi to the experiment!\n\nYour task will be to memorize different pairs of pictures representing objects you encounter in your daily life.\n\nThe first object of each pair will be presented with an open bracket on the left, while the second object will be presented with an open bracket on the right.\n\nIMPORTANT: YOU HAVE TO MEMORIZE BOTH OBJECTS TOGETHER!\n\nPress 1 or 2 to continue."
instr_text_2.text = "Between the presentation of the paired objects, a question will appear.\n\nIf question is 'Bigger?' :\n\nPress '1' if the first object in the pair is bigger than the second object in the pair in real life.\n\nPress '2' if the second object in the pair is the bigger one.\n\nPress 1 or 2 to continue."
instr_text_3.text = "Please answer when the second object appears.\n\nBetween each pair of objects, there will be a fixation cross (+). You should look at this cross while there are no images on the screen.\n\nPress 1 or 2 to continue."
instr_text_4.text = "If the question is 'Same category?' :\n\nPress '1' if both objects are from the same semantic category (ex: both objects are clothes, or both objects are food...)\n\nPress '2' if they are from different categories (ex: one clothing and one food item).\n\nPress 1 or 2 to continue."
instr_text_5.text = "hi"
else:
instr_text_1.text = "Bienvenue à l'expérience !\n\nVous devrez mémoriser des paires d'images représentant des objets de la vie quotidienne.\n\nLe premier objet de chaque paire sera présenté avec un crochet à sa gauche et le second objet sera présenté avec un crochet à sa droite.\n\nIMPORTANT: VOUS DEVEZ MÉMORISER LES DEUX OBJETS DE LA PAIRE ENSEMBLE!!\n\nAppuyez sur 1 ou 2 pour continuer."
instr_text_2.text = "Entre les deux présentations d'objets, l'une des deux questions apparaîtra à l'écran.\n\nLa question est soit \'Plus gros ?\, soit \'Catégorie?\'\n\nAppuyez sur le \"bouton1\" si dans la vie de tous les jours le premier objet de la paire est plus gros/dans la même catégorie que le deuxième objet.\n\nAppuyez sur le \"bouton2\" si le deuxième objet de la paire est le plus gros/pas dans la même catégorie/.\n\nAppuyez sur 1 ou 2 pour continuer."
instr_text_3.text = "Vous devez répondre quand le DEUXIÈME OBJET apparaît.\n\nEntre chaque paire d'objets, il y aura une croix de fixation (+). Vous devez regarder cette croix lorsqu'il n'y a pas d'image à l'écran.\n\nAppuyez sur le bouton 1 ou 2 pour continuer."
instr_text_4.text = "Commençons la pratique avec quelques essais.\n\nÊtes-vous prêt ?\n\nAppuyez sur 1 ou 2 pour commencer la pratique."
instr_text_5.text = "hi"
#Display 4 instructions
curIns = 1
# The button was previously pressed
button_down = True
joystick_instr.oldButtonState = joystick_instr.device.getAllButtons()[:]
joystick_instr.activeButtons=[1, 2]
# setup some python lists for storing info about the joystick_instr
gotValidClick = False # until a click is received
# keep track of which components have finished
instrComponents = [instr_text_1, instr_text_2, instr_text_3, instr_text_4, instr_text_5, joystick_instr]
for thisComponent in instrComponents:
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")
instrClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "instr"-------
while continueRoutine:
# get current time
t = instrClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=instrClock)
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 if we pressed keyboard keys
keys = event.getKeys()
#print(keys)
# Reset buttons if they are not pressed
if button_down and not joystick_instr.getAllButtons()[1] and not joystick_instr.getAllButtons()[2] and not '1' in keys and not '2' in keys:
button_down = False
# Go to next instruction if '1' or '2' is pressed
if not button_down and curIns >= 1 and curIns <= 4 and (joystick_instr.getAllButtons()[1] or joystick_instr.getAllButtons()[2] or '1' in keys or '2' in keys):
button_down = True
curIns = curIns + 1
# Go to next routine
elif not button_down and curIns == 5 and (joystick_instr.getAllButtons()[1] or joystick_instr.getAllButtons()[2] or '1' in keys or '2' in keys):
button_down = True
continueRoutine = False
print("current instruction: ", curIns)
# *instr_text_1* updates
if instr_text_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
instr_text_1.frameNStart = frameN # exact frame index
instr_text_1.tStart = t # local t and not account for scr refresh
instr_text_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instr_text_1, 'tStartRefresh') # time at next scr refresh
instr_text_1.setAutoDraw(True)
if instr_text_1.status == STARTED:
if bool(curIns == 2):
# keep track of stop time/frame for later
instr_text_1.tStop = t # not accounting for scr refresh
instr_text_1.frameNStop = frameN # exact frame index
win.timeOnFlip(instr_text_1, 'tStopRefresh') # time at next scr refresh
instr_text_1.setAutoDraw(False)
# *instr_text_2* updates
if instr_text_2.status == NOT_STARTED and curIns == 2:
# keep track of start time/frame for later
instr_text_2.frameNStart = frameN # exact frame index
instr_text_2.tStart = t # local t and not account for scr refresh
instr_text_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instr_text_2, 'tStartRefresh') # time at next scr refresh
instr_text_2.setAutoDraw(True)
if instr_text_2.status == STARTED:
if bool(curIns == 3):
# keep track of stop time/frame for later
instr_text_2.tStop = t # not accounting for scr refresh
instr_text_2.frameNStop = frameN # exact frame index
win.timeOnFlip(instr_text_2, 'tStopRefresh') # time at next scr refresh
instr_text_2.setAutoDraw(False)
# *instr_text_3* updates
if instr_text_3.status == NOT_STARTED and curIns == 3:
# keep track of start time/frame for later
instr_text_3.frameNStart = frameN # exact frame index
instr_text_3.tStart = t # local t and not account for scr refresh
instr_text_3.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instr_text_3, 'tStartRefresh') # time at next scr refresh
instr_text_3.setAutoDraw(True)
if instr_text_3.status == STARTED:
if bool(curIns == 4):
# keep track of stop time/frame for later
instr_text_3.tStop = t # not accounting for scr refresh
instr_text_3.frameNStop = frameN # exact frame index
win.timeOnFlip(instr_text_3, 'tStopRefresh') # time at next scr refresh
instr_text_3.setAutoDraw(False)
# *instr_text_4* updates
if instr_text_4.status == NOT_STARTED and curIns == 4:
# keep track of start time/frame for later
instr_text_4.frameNStart = frameN # exact frame index
instr_text_4.tStart = t # local t and not account for scr refresh
instr_text_4.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instr_text_4, 'tStartRefresh') # time at next scr refresh
instr_text_4.setAutoDraw(True)
if instr_text_4.status == STARTED:
if bool(curIns == 5):
# keep track of stop time/frame for later
instr_text_4.tStop = t # not accounting for scr refresh
instr_text_4.frameNStop = frameN # exact frame index
win.timeOnFlip(instr_text_4, 'tStopRefresh') # time at next scr refresh
instr_text_4.setAutoDraw(False)
# *instr_text_5* updates
if instr_text_5.status == NOT_STARTED and curIns == 5:
# keep track of start time/frame for later
instr_text_5.frameNStart = frameN # exact frame index
instr_text_5.tStart = t # local t and not account for scr refresh
instr_text_5.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instr_text_5, 'tStartRefresh') # time at next scr refresh
instr_text_5.setAutoDraw(True)
# 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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in instrComponents:
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 "instr"-------
for thisComponent in instrComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
instr_text_1.setOpacity(0)
instr_text_2.setOpacity(0)
instr_text_3.setOpacity(0)
instr_text_4.setOpacity(0)
instr_text_5.setOpacity(0)
thisExp.addData('instr_text_1.started', instr_text_1.tStartRefresh)
thisExp.addData('instr_text_1.stopped', instr_text_1.tStopRefresh)
thisExp.addData('instr_text_2.started', instr_text_2.tStartRefresh)
thisExp.addData('instr_text_2.stopped', instr_text_2.tStopRefresh)
thisExp.addData('instr_text_3.started', instr_text_3.tStartRefresh)
thisExp.addData('instr_text_3.stopped', instr_text_3.tStopRefresh)
thisExp.addData('instr_text_4.started', instr_text_4.tStartRefresh)
thisExp.addData('instr_text_4.stopped', instr_text_4.tStopRefresh)
thisExp.addData('instr_text_5.started', instr_text_5.tStartRefresh)
thisExp.addData('instr_text_5.stopped', instr_text_5.tStopRefresh)
# store data for thisExp (ExperimentHandler)
thisExp.addData('joystick_instr.started', joystick_instr.tStart)
thisExp.addData('joystick_instr.stopped', joystick_instr.tStop)
thisExp.nextEntry()
# the Routine "instr" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
prac_repeat = data.TrialHandler(nReps=100, method='sequential',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='prac_repeat')
thisExp.addLoop(prac_repeat) # add the loop to the experiment
thisPrac_repeat = prac_repeat.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisPrac_repeat.rgb)
if thisPrac_repeat != None:
for paramName in thisPrac_repeat:
exec('{} = thisPrac_repeat[paramName]'.format(paramName))
for thisPrac_repeat in prac_repeat:
currentLoop = prac_repeat
# abbreviate parameter names if possible (e.g. rgb = thisPrac_repeat.rgb)
if thisPrac_repeat != None:
for paramName in thisPrac_repeat:
exec('{} = thisPrac_repeat[paramName]'.format(paramName))
# set up handler to look after randomisation of conditions etc
practice = data.TrialHandler(nReps=1, method='sequential',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions(pracConditions),
seed=None, name='practice')
thisExp.addLoop(practice) # add the loop to the experiment
thisPractice = practice.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisPractice.rgb)
if thisPractice != None:
for paramName in thisPractice:
exec('{} = thisPractice[paramName]'.format(paramName))
for thisPractice in practice:
currentLoop = practice
# abbreviate parameter names if possible (e.g. rgb = thisPractice.rgb)
if thisPractice != None:
for paramName in thisPractice:
exec('{} = thisPractice[paramName]'.format(paramName))
# ------Prepare to start Routine "prac"-------
continueRoutine = True
# update component parameters for each repeat
# Change displayed text based on the language previously chosen
if english == True:
que_text_pr.text = question_english
else:
que_text_pr.text = question_french
# Save the answer of the participant
# The response period started when image 2 started. No need to save it.
response_time_pr = -1. # Save when the participant answered (in secs)
# set the images by parameters of condition file
img1 = pic1
img2 = pic2
# Set the duration of the fixation cross and the question
timeQue = duration_ques/1000 #duration of the question
timeFix = duration_fixation/1000 #duration of the fixation cross
# Duration of the items, question and fixation cross with frames
# The number of frames we want to display is equal to
# the product of frame-rate and the number of seconds to display
# the stimulus.
# n_frames = frame_rate * n_seconds
# n_frames_img1 = frameRate * 2.
# n_frames_img2 = frameRate * 2.
# debug.text = "duration of img 1 in frames: "+str(n_frames_img1)
n_secs_img1 = 2.
n_secs_img2 = 2.
#By default the elements did not start so they are not finished
item1_finished = False
que_finished = False
item2_finished = False
# Record if the participant answered
participant_answered = False
# When true, we reached the end of img2 without any answer
no_answers = False
# Reset the response of the participant
response_pr.text = ""
item1_img_pr.setImage(img1)
item2_img_pr.setImage(img2)
key_prac.keys = []
key_prac.rt = []
_key_prac_allKeys = []
joystick_prac.oldButtonState = joystick_prac.device.getAllButtons()[:]
joystick_prac.activeButtons=[1, 2]
# setup some python lists for storing info about the joystick_prac
gotValidClick = False # until a click is received
# keep track of which components have finished
pracComponents = [item1_img_pr, brL_img_pr, que_text_pr, item2_img_pr, brR_img_pr, response_pr, timer_pr, fix_text_pr, key_prac, joystick_prac]
for thisComponent in pracComponents:
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")
pracClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "prac"-------
while continueRoutine:
# get current time
t = pracClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=pracClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
#Set the boolean to true when item1 is done
if item1_img_pr.status == FINISHED:
item1_finished = True
# Set the boolean to true when the question is done
if que_text_pr.status == FINISHED and not que_finished:
que_finished = True
# Register participant's answers
# Button 1 is pressed
if not participant_answered and que_finished and (joystick_prac.getAllButtons()[1] or "1" in key_prac.keys):
response_pr.text = 1
participant_answered = True
#win.color = 'grey'
print("participant chose: ", response_pr.text)
# Register participant's answers
# Button 2 is pressed
elif not participant_answered and que_finished and (joystick_prac.getAllButtons()[2] or "2" in key_prac.keys):
response_pr.text = 2
participant_answered = True
print("participant chose: ", response_pr.text)
# Register participant's answers
#4s countdown are done
elif not no_answers and not participant_answered and timer_pr.status == FINISHED:
response_pr.finished = True
no_answers = True
print("participant did not answer: ", response_pr.text)
#Set the boolean to true when the item2 is done
if item2_img_pr.status == FINISHED:
item2_finished = True
#Go to next routine when fixation cross is done
if fix_text_pr.status == FINISHED:
continueRoutine = False