-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmnemonicproj.py
1819 lines (1603 loc) · 82 KB
/
mnemonicproj.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.1.3),
on Tue Jul 5 15:42:46 2022
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
ATM 7/13/2022
TO DO:
1) Finish the retrieval dictionary of lists, using list comprehension similar to the ENC_RUN_TRIALS syntax #finally..completed..but...in a bit weird way..
2) Add a indoor/outdoor response during the encoding trials to ensure people are attending (NOT SELF TIMED) #completed
2a) write a separate datFile that has the image name, response given, and the latency of the response #completed
3) Make the confidence judgment self-paced rather than timed - follow the example of the retrieval image response syntax #completed
"""
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
# Store info about the experiment session
psychopyVersion = '2022.1.3'
expName = 'mstfoil' # from the Builder filename that created this script
expInfo = {'participant': ''}
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
# ATM 7/6/2022 added
import pandas as pd
# Ensure that relative paths start from the same directory as this script
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(SCRIPT_DIR)
# The following code all deals with setting up the encoding and recognition trial structure across runs ### modified by HLee
encodingtrials_lists = pd.read_excel(f"data/sub-{expInfo['participant']}/encoding.xlsx")
# CREATE A DICTIONARY BELOW CALLED ENC_RUN_TRIALS THAT LOOKS LIKE THE FOLLOWING:
# ENC_RUN_TRIALS = {1: [{"stim":'SetC/001a.jpg'}, {"stim":'SetC/002a.jpg'},{"stim":'SetC/003a.jpg'}, ..., {"stim":'SetC/045a.jpg'}],
# 2: [{"stim":'SetC/046a.jpg'}, {"stim":'SetC/047a.jpg'},{"stim":'SetC/048a.jpg'},..., {"stim":'SetC/090a.jpg'}],
# ...
# 4: [{"stim":'SetC/100a.jpg'}, {"stim":'SetC/101a.jpg'},{"stim":'SetC/102a.jpg'}, ..., {"stim":'SetC/145a.jpg'}]}
ENC_RUN_TRIALS = {
ENCRUN: [{"stim": curr_enc_img} for curr_enc_img in encodingtrials_lists[f"encoding{ENCRUN}"]]
for ENCRUN in range(1,5)
}
recognitionblocks_lists = {RECRUN: pd.read_excel(f"data/sub-{expInfo['participant']}/recognition{RECRUN}.xlsx") for RECRUN in range(1,5)}
#recognitionblocks_lists = pd.read_excel(f"data/sub-{expInfo['participant']}/recognition.xlsx")
# REC_RUN_BLOCKS = {
# RECRUN: [{"rec_list": curr_rec_list} for curr_rec_list in recognitionblocks_lists[f"recog_list{RECRUN}"]]
# for RECRUN in range(1,5)
# }
# REC_RUN_CRESPS = {
# RECRUN: [{"rec_cresp": curr_recog_cresp} for curr_recog_cresp in recognitionblocks_lists[f"cresp{RECRUN}"]]
# for RECRUN in range(1,5)
# }
#recognitionblocks_lists = {RECRUN: pd.read_excel(f"data/sub-{expInfo['participant']}/recognition{RECRUN}.xlsx") for RECRUN in range(1,5)}
# REC_RUN_TRIALS = {
# RECRUN: [{"rec_stim": curr_rec_img} for curr_rec_img in recognitiontrials_lists[f"rec_stim{RECRUN}"]]
# for RECRUN in range(1, 5)
# }
#RET_RUN = {RECRUN: pd.read_excel(f"data/sub-{expInfo['participant']}/retrieval{RECRUN}.xlsx") for RECRUN in range(1,5)}
# CREATE A DICTIONARY BELOW CALLED RET_RUN_TRIALS THAT LOOKS LIKE THE FOLLOWING:
# RET_RUN_TRIALS = {1: [{'stim': 'SetC/001a.jpg', 'type': 'targ'}, {'stim': 'SetC/002a.jpg', 'type': 'targ'}, ..., {'stim': 'SetC/048b.jpg', 'type': 'lure'}],
# 2: [{'stim': 'SetC/049a.jpg', 'type': 'targ'}, {'stim': 'SetC/050a.jpg', 'type': 'targ'}, ..., {'stim': 'SetC/108a.jpg', 'type': 'foil'}],
# ...
# 4: [{'stim': 'SetC/181a.jpg', 'type': 'targ'}, {'stim': 'SetC/182a.jpg', 'type': 'targ'}, ..., {'stim': 'SetD/084a.jpg', 'type': 'foil'}]}
# REC_RUN_TRIALS = {
# [{"stim_in_rec_trials": curr_rec_list} for curr_rec_list in recognitiontrial_lists["recog_stim"]]
# }
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = SCRIPT_DIR + os.sep + u'{0}_data/sub-{1}/ses-S1/{2}/sub-{1}_task-mstfoil_events'.format(expName, expInfo['participant'], expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
# ATM 7/6/2022 edited for readability
thisExp = data.ExperimentHandler(
name=expName,
version='',
extraInfo=expInfo,
runtimeInfo=None,
originPath=None,
savePickle=True,
saveWideText=True,
dataFileName=filename,
)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
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=[1440, 900],
fullscr=True,
screen=0,
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()
welcome_message = """Hello, thanks for your participation.
This experiment consists of a total of FOUR blocks.
In each block, you'll see pictures, after which
you'll play a Sudoku game and do memory tests.
Press “M” to move on to the next screen."""
# Initialize components for Routine "welcome"
welcomeClock = core.Clock()
welcome_text = visual.TextStim(
win=win,
name='welcome_text',
text=welcome_message,
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
welcome_resp = keyboard.Keyboard()
# Initialize components for Routine "ready_block" ###edited by HLee
# encoding_instruct_message = """You are in block {0}
#
# Now, you will see the pictures, each for 2 seconds.
#
# After that, please answer whether the object you saw is for indoor or outdoor use.
#
#
# H = Indoor,
#
# J = Outdoor,
#
# K = Ambiguous,
#
# L = I forgot what I just saw.
#
#
# When you are ready to begin, press the "R" key."""
encoding_intructClock = core.Clock()
encoding_instruct_text = visual.TextStim(
win=win,
name='encoding_instruct_text',
text=None,
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
encoding_instruct_resp = keyboard.Keyboard()
# Initialize components for Routine "fixationcross"
fixationcrossClock = core.Clock()
fixation = visual.TextStim(
win=win,
name='fixation',
text='+',
font='Open Sans',
pos=(0, 0),
height=0.1,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
# Initialize components for Routine "ecd_trial"
encoding_imgClock = core.Clock()
encoding_img = visual.ImageStim(
win=win,
name='encoding_img',
image=None,
mask=None,
ori=0.0,
pos=(0, 0),
size=None, #(0.5, 0.5),
color=[1,1,1],
colorSpace='rgb',
opacity=None,
flipHoriz=False,
flipVert=False,
texRes=128.0,
interpolate=False,
depth=0.0)
# Initialize components for Routine "inandout_decision" ### added by HLee
inandout_decClock = core.Clock()
inandout_dec_instruct = visual.TextStim(
win=win,
name='inandout_dec_instruct',
text='Please answer whether the object you saw is for indoor or outdoor use.',
font='Open Sans',
pos=(0, 0.3),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
inandout_dec_options = visual.TextStim(
win=win,
name='inandout_resp_options',
text="""
H = indoor,
J = outdoor,
K = ambiguous,
L = I forgot what I just saw""",
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=3.0);
inandout_dec_resp = keyboard.Keyboard()
# Initialize components for Routine "sudoku_intro"
sudoku_message = """Now, you will play Sudoku for 5 minutes.
Please use the paper and pen given to you.
If you don't know how to play Sudoku, refer to the instrctions.
Do your best! Your results will be analyzed.
When you are ready press the "R" key to start the timer.
"""
sudoku_instructClock = core.Clock()
sudoku_instructions = visual.TextStim(
win=win,
name='sudoku_instructions',
text=sudoku_message,
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
sudoku_instruct_resp = keyboard.Keyboard()
# Initialize components for Routine "sudoku_timer"
sudoku_timerClock = core.Clock()
sudoku_timer_text = visual.TextStim(
win=win,
name='sudoku_timer_text',
text='',
font='Open Sans',
pos=(0, 0),
height=0.05,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=-1.0);
recog_instruct_message = """Now you are going to do a memory test.
If the object that appears is what you just saw (old), press H.
If the object that appears is similar to what you saw (similar), press J.
If the object that appears is not what you saw (new), press K.
Then, rate how confident you are about your answer.
H = very certain,
J = somewhat certain,
K = somewhat uncertain,
L = very uncertain.
When you are ready to begin, press the "A" key.
"""
# Initialize components for Routine "recog_intro"
recognition_instructClock = core.Clock()
recognition_instruct = visual.TextStim(
win=win,
name='recognition_instruct',
text=recog_instruct_message,
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
recognition_instruct_resp = keyboard.Keyboard()
# Initialize components for Routine "rcg_trial"
recognition_imgClock = core.Clock()
recognition_img = visual.ImageStim(
win=win,
name='recognition_img',
image=None,
mask=None,
ori=0.0,
pos=(0, 0),
size=None, #(0.5, 0.5),
color=[1,1,1],
colorSpace='rgb',
opacity=None,
flipHoriz=False,
flipVert=False,
texRes=128.0,
interpolate=False,
depth=0.0)
recognition_img_resp = keyboard.Keyboard()
recognition_resp_prompt_main = visual.TextStim(
win=win,
name='recognition_resp_prompt_main',
text='Please select from the responses below.',
font='Open Sans',
pos=(0, 0.35),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=-2.0);
recognition_resp_prompt_options = visual.TextStim(
win=win,
name='recognition_resp_prompt_options',
text='H = old, J = similar, K = new',
font='Open Sans',
pos=(0, -0.35),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=-3.0);
# Initialize components for Routine "confidence" ### modified by HLee
confidence_respClock = core.Clock()
confidence_resp_prompt_main = visual.TextStim(
win=win,
name='confidence_resp_prompt_main',
text='Please rate your confidence in your answer.',
font='Open Sans',
pos=(0, 0.35),
height=0.03,
wrapWidth=None,
ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
confidence_ratebar = visual.ImageStim(
win=win,
name='confidence_ratebar',
image='ratebar.png',
mask=None,
ori=0.0,
pos=(0, -0.05),
size=(1.2, 0.7),
color=[1,1,1],
colorSpace='rgb',
opacity=None,
flipHoriz=False,
flipVert=False,
texRes=128.0,
interpolate=False,
depth=-1.0)
confidence_resp = keyboard.Keyboard()
# Initialize components for Routine "ExpEnd"
ExpEndClock = core.Clock()
byebye = visual.TextStim(
win=win,
name='byebye',
text='Thank you for your participation.\nPlease enter any key to exit this screen.',
font='Open Sans',
pos=(0, 0),
height=0.03,
wrapWidth=None, ori=0.0,
color='black',
colorSpace='rgb',
opacity=None,
languageStyle='LTR',
depth=0.0);
bye_resp = keyboard.Keyboard()
# 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
#############################################################################################
################################ Components of the main loop ################################
# 1) "welcome" routine
# 2) "ready" routine; explains the whole procedure
############################# 3) - 6) will repeat four times. ###############################
# 3) Encoding loop (repeats 48 times within each block)
# 3a) "encoding_instructions"; It tells you which block you are in.
# 3b) "fixationcross"; lasts 0.5s
# 3c) "encoding_img"; It shows objects that you have to remember for the recognition tests, 2s
# 3d) "inandout_decision";
# A task to determine whether the object you saw is for indoor or outdoor use.
# This is for the purpose of verifying the encoding.
# Stimuli for which the "I forgot what I just saw" option were selected can be excluded from recognition data analysis.
# 4) Sudoku Loop
# 4a) "sudoku_intro"; It lets participants know that they will play a sudoku game
# 4b) "sudoku_instructions" ;
# how to play will explain via paper
# because it's repeated routine
# so I don't want people to see the same long explanation multiple times
# 4c) "sudoku_timer"; 300s count down timer
# 5) "recog_intro"; It lets participants know that they will do a recognition test with confidence checking
# 6) Recognition Loop (repeats 48, 60, 72, or 96 within each block)
# 48 - 24 targets & 24 lures / 60 - 24 targets, 24 lures, & 12 foils
# 72 - 24 targets, 24 lures, & 24 foils / 96 - 24 targets, 24 lures, & 48 foils
# 6a) "fixationcross"; lasts 0.5s
# 6b) "rcg_trial"; self-paced task asking whether you saw objects before or not
# 6c) "confidence"; self-paced question asking their deicision
#############################################################################################
# 7) "ExpEnd" routine; It lets participants know that they're done with the experiment
#############################################################################################
#############################################################################################
################################## Start of the main loop ###################################
#############################################################################################
# ------Prepare to start Routine "welcome"-------
continueRoutine = True
# update component parameters for each repeat
welcome_resp.keys = []
welcome_resp.rt = []
_welcome_resp_allKeys = []
# keep track of which components have finished
welcomeComponents = [welcome_text, welcome_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")
welcomeClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "welcome"-------
while continueRoutine:
# get current time
t = welcomeClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=welcomeClock)
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
welcome_text.setAutoDraw(True)
# *welcome_resp* updates
waitOnFlip = False
if welcome_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
welcome_resp.frameNStart = frameN # exact frame index
welcome_resp.tStart = t # local t and not account for scr refresh
welcome_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(welcome_resp, 'tStartRefresh') # time at next scr refresh
welcome_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(welcome_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(welcome_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if welcome_resp.status == STARTED and not waitOnFlip:
theseKeys = welcome_resp.getKeys(keyList=['m'], waitRelease=False)
_welcome_resp_allKeys.extend(theseKeys)
if len(_welcome_resp_allKeys):
welcome_resp.keys = _welcome_resp_allKeys[-1].name # just the last key pressed
welcome_resp.rt = _welcome_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
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)
thisExp.addData('welcome_text.started', welcome_text.tStartRefresh)
thisExp.addData('welcome_text.stopped', welcome_text.tStopRefresh)
# check responses
if welcome_resp.keys in ['', [], None]: # No response was made
welcome_resp.keys = None
thisExp.addData('welcome_resp.keys',welcome_resp.keys)
if welcome_resp.keys != None: # we had a response
thisExp.addData('welcome_resp.rt', welcome_resp.rt)
thisExp.addData('welcome_resp.started', welcome_resp.tStartRefresh)
thisExp.addData('welcome_resp.stopped', welcome_resp.tStopRefresh)
thisExp.nextEntry()
# the Routine "welcome" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ATM 7/7/2022 added....iterating over 4 runs hard coded.
for _run in range(1, 5):
#encoding_instruct_message = encoding_instruct_message.format(_run)
encoding_instruct_message = """You are in block %d.
Now, you will see the pictures, each for 2 seconds.
After that, please answer whether the object you saw is for indoor or outdoor use.
H = Indoor,
J = Outdoor,
K = Ambiguous,
L = I forgot what I just saw.
When you are ready to begin, press the "R" key.""" % _run
datFile_base = SCRIPT_DIR + "/mstfoil_data/sub-{0}/ses-S1/{1}/sub-{0}_task-mstfoil_events".format(expInfo["participant"], expInfo["date"])
# If restart occurs within the same minute, prevents writing to same file
if os.path.exists(datFile_base + ".tsv"):
datFile_base += "_latest"
datFile = open(datFile_base + ".tsv", "a",)
datFile.write("trial_type\trecog_resp\trecog_resp_time\tconfi_resp\tconfi_resp_time\tstim_file\tperformance\n")
# ------Prepare to start Routine "ready_intructions_block"-------
continueRoutine = True
# update component parameters for each repeat
encoding_instruct_resp.keys = []
encoding_instruct_resp.rt = []
_encoding_instruct_resp_allKeys = []
encoding_instruct_text.text = encoding_instruct_message
# keep track of which components have finished
encoding_instructComponents = [encoding_instruct_text, encoding_instruct_resp]
for thisComponent in encoding_instructComponents:
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")
encoding_intructClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "encoding_instructions"-------
while continueRoutine:
# get current time
t = encoding_intructClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=encoding_intructClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text* updates
if encoding_instruct_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
encoding_instruct_text.frameNStart = frameN # exact frame index
encoding_instruct_text.tStart = t # local t and not account for scr refresh
encoding_instruct_text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(encoding_instruct_text, 'tStartRefresh') # time at next scr refresh
encoding_instruct_text.setAutoDraw(True)
# *key_resp* updates
waitOnFlip = False
if encoding_instruct_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
encoding_instruct_resp.frameNStart = frameN # exact frame index
encoding_instruct_resp.tStart = t # local t and not account for scr refresh
encoding_instruct_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(encoding_instruct_resp, 'tStartRefresh') # time at next scr refresh
encoding_instruct_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(encoding_instruct_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(encoding_instruct_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if encoding_instruct_resp.status == STARTED and not waitOnFlip:
theseKeys = encoding_instruct_resp.getKeys(keyList=['r'], waitRelease=False)
_encoding_instruct_resp_allKeys.extend(theseKeys)
if len(_encoding_instruct_resp_allKeys):
encoding_instruct_resp.keys = _encoding_instruct_resp_allKeys[-1].name # just the last key pressed
encoding_instruct_resp.rt = _encoding_instruct_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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in encoding_instructComponents:
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 "encoding_instructions"-------
for thisComponent in encoding_instructComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "ready_block" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
curr_enc_run = ENC_RUN_TRIALS[_run] #ATM 7/7/2022 added
encoding_trials_block = data.TrialHandler(
nReps=1.0,
method='sequential',
extraInfo=expInfo,
originPath=-1,
trialList=curr_enc_run, #ATM 7/7/2022 added this
seed=None,
name='encoding_trials_block')
thisExp.addLoop(encoding_trials_block) # add the loop to the experiment
thisEncoding_trials_block = encoding_trials_block.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisEcd_block.rgb)
if thisEncoding_trials_block != None:
for paramName in thisEncoding_trials_block:
exec('{} = thisEncoding_trials_block[paramName]'.format(paramName))
for thisEncoding_trials_block in encoding_trials_block:
currentLoop = encoding_trials_block
# abbreviate parameter names if possible (e.g. rgb = thisEcd_block.rgb)
if thisEncoding_trials_block != None:
for paramName in thisEncoding_trials_block:
exec('{} = thisEncoding_trials_block[paramName]'.format(paramName))
# ------Prepare to start Routine "fixationcross"-------
continueRoutine = True
routineTimer.add(0.500000)
# update component parameters for each repeat
# keep track of which components have finished
fixationComponents = [fixation]
for thisComponent in fixationComponents:
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")
fixationcrossClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "fixationcross"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = fixationcrossClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=fixationcrossClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *polygon* updates
if fixation.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation.frameNStart = frameN # exact frame index
fixation.tStart = t # local t and not account for scr refresh
fixation.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation, 'tStartRefresh') # time at next scr refresh
fixation.setAutoDraw(True)
if fixation.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation.tStartRefresh + 0.5-frameTolerance:
# keep track of stop time/frame for later
fixation.tStop = t # not accounting for scr refresh
fixation.frameNStop = frameN # exact frame index
win.timeOnFlip(fixation, 'tStopRefresh') # time at next scr refresh
fixation.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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in fixationComponents:
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 "fixationcross"-------
for thisComponent in fixationComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
encoding_trials_block.addData('fixation.started', fixation.tStartRefresh)
encoding_trials_block.addData('fixation.stopped', fixation.tStopRefresh)
# ------Prepare to start Routine "encoding_trials"-------
continueRoutine = True
routineTimer.add(2.00000)
#routineTimer.add(0.01000)
# update component parameters for each repeat
encoding_img.image = thisEncoding_trials_block.stim #ATM 7/7/2022 added
# keep track of which components have finished
encoding_imgComponents = [encoding_img]
for thisComponent in encoding_imgComponents:
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")
encoding_imgClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "encoding_trial"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = encoding_imgClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=encoding_imgClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *ecd_img* updates
if encoding_img.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
encoding_img.frameNStart = frameN # exact frame index
encoding_img.tStart = t # local t and not account for scr refresh
encoding_img.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(encoding_img, 'tStartRefresh') # time at next scr refresh
encoding_img.setAutoDraw(True)
if encoding_img.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > encoding_img.tStartRefresh + 2.0-frameTolerance:
# keep track of stop time/frame for later
encoding_img.tStop = t # not accounting for scr refresh
encoding_img.frameNStop = frameN # exact frame index
win.timeOnFlip(encoding_img, 'tStopRefresh') # time at next scr refresh
encoding_img.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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in encoding_imgComponents:
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 "encoding_trial"-------
for thisComponent in encoding_imgComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
encoding_trials_block.addData('encoding_img.started', encoding_img.tStartRefresh)
encoding_trials_block.addData('encoding_img.stopped', encoding_img.tStopRefresh)
# ------Prepare to start Routine "inandout_dec"-------
continueRoutine = True
# update component parameters for each repeat
inandout_dec_resp.keys = []
inandout_dec_resp.rt = []
_inandout_dec_resp_allKeys = []
# keep track of which components have finished
inandout_decComponents = [inandout_dec_instruct, inandout_dec_options, inandout_dec_resp]
for thisComponent in inandout_decComponents:
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")
inandout_decClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "inandout_dec"-------
while continueRoutine:
#get current time
t = inandout_decClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=inandout_decClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *inandout_dec_instruct* updates
if inandout_dec_instruct.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
inandout_dec_instruct.frameNStart = frameN # exact frame index
inandout_dec_instruct.tStart = t # local t and not account for scr refresh
inandout_dec_instruct.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(inandout_dec_instruct, 'tStartRefresh') # time at next scr refresh
inandout_dec_instruct.setAutoDraw(True)
# *inandout_dec_options* updates
if inandout_dec_options.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
inandout_dec_options.frameNStart = frameN # exact frame index
inandout_dec_options.tStart = t # local t and not account for scr refresh
inandout_dec_options.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(inandout_dec_options, 'tStartRefresh') # time at next scr refresh
inandout_dec_options.setAutoDraw(True)
# "inandout_dec_resp" updates
waitOnFlip = False
if inandout_dec_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
inandout_dec_resp.frameNStart = frameN # exact frame index
inandout_dec_resp.tStart = t # local t and not account for scr refresh
inandout_dec_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(inandout_dec_resp, 'tStartRefresh') # time at next scr refresh
inandout_dec_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(inandout_dec_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(inandout_dec_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if inandout_dec_resp.status == STARTED and not waitOnFlip:
theseKeys = inandout_dec_resp.getKeys(keyList=['h', 'j', 'k', 'l'], waitRelease=False)
_inandout_dec_resp_allKeys.extend(theseKeys)
if len(_inandout_dec_resp_allKeys):
inandout_dec_resp.keys = _inandout_dec_resp_allKeys[-1].name # just the last key pressed
inandout_dec_resp.rt = _inandout_dec_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
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in inandout_decComponents:
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 "inandout_decision"-------
for thisComponent in inandout_decComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
encoding_trials_block.addData('inandout_dec_instruct.started', inandout_dec_instruct.tStartRefresh)
encoding_trials_block.addData('inandout_dec_instruct.stopped', inandout_dec_instruct.tStartRefresh)
# check responses
if inandout_dec_resp.keys in ['', [], None]: # No response was made
inandout_dec_resp.keys = None
# store data for encoding_trials_block (TrialHandler)
encoding_trials_block.addData('inandout_dec_resp.keys',inandout_dec_resp.keys)
encoding_trials_block.addData('inandout_dec_resp.corr', inandout_dec_resp.corr)