-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpainpred_lastrun.py
1649 lines (1521 loc) · 75.8 KB
/
painpred_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.4),
on November 18, 2022, at 00:28
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 packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os # handy system and path functions
import sys # to get file system encoding
import psychopy.iohub as io
from psychopy.hardware import keyboard
# 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.4'
expName = 'painpred' # from the Builder filename that created this script
expInfo = {
'participant': f"{randint(0, 999999):06.0f}",
'session': '001',
}
# --- Show participant info dialog --
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['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\\Sharon Ho\\Documents\\Camb\\Engineering\\Part_IIB\\project\\part_iib_project\\newest\\painpred_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=[1536, 864], fullscr=True, screen=0,
winType='pyglet', allowStencil=False,
monitor='testMonitor', color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
win.mouseVisible = False
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
# --- Setup input devices ---
ioConfig = {}
# Setup iohub keyboard
ioConfig['Keyboard'] = dict(use_keymap='psychopy')
ioSession = '1'
if 'session' in expInfo:
ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, **ioConfig)
eyetracker = None
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend='iohub')
# --- Initialize components for Routine "instruction_1" ---
next_button_1 = visual.ImageStim(
win=win,
name='next_button_1',
image='instruction_images/next_button.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.07),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
mouse_1 = event.Mouse(win=win)
x, y = [None, None]
mouse_1.mouseClock = core.Clock()
slider_1 = visual.ImageStim(
win=win,
name='slider_1',
image='instruction_images/first_slider_image.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.12), size=(0.3, 0.55),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
instruction_1_text_new = visual.TextStim(win=win, name='instruction_1_text_new',
text='Thank you for agreeing to participate in our study. \n\nYou will be asked to rate how much pain you feel \nin real time, using a slider like this. \n\nPlease rate pain continuously and ensure to always \nhave your finger on the screen \neven if the pain level is not changing.',
font='Arial',
pos=(0, 0.3), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-3.0);
# --- Initialize components for Routine "instruction_2" ---
next_button_2 = visual.ImageStim(
win=win,
name='next_button_2',
image='instruction_images/next_button.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.07),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
mouse_2 = event.Mouse(win=win)
x, y = [None, None]
mouse_2.mouseClock = core.Clock()
slider_2 = visual.ImageStim(
win=win,
name='slider_2',
image='instruction_images/second_slider_image.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.12), size=(0.3, 0.55),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
text_2 = visual.TextStim(win=win, name='text_2',
text='Sometimes, you will be asked to predict how much pain \nyou will experience in one minute from now, \non a slider like this. Don’toverthink it, \nwe will collect your first response.',
font='Arial',
pos=(0, 0.30), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-3.0);
# --- Initialize components for Routine "instruction_3" ---
mouse_3 = event.Mouse(win=win)
x, y = [None, None]
mouse_3.mouseClock = core.Clock()
start_button = visual.ImageStim(
win=win,
name='start_button',
image='instruction_images/start_button.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.07),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
slider_3 = visual.ImageStim(
win=win,
name='slider_3',
image='instruction_images/confidence_slider.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.375, 0.15),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
instruction_3_text_ = visual.TextStim(win=win, name='instruction_3_text_',
text='Next, you will be asked to rate how confident you are \nin your prediction, on a scale ranging from unsure to sure.',
font='Arial',
pos=(0, 0.3), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-3.0);
# --- Initialize components for Routine "blank500ms" ---
text = visual.TextStim(win=win, name='text',
text=None,
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);
# --- Initialize components for Routine "continuous_pain_rating" ---
vertical_1 = visual.ImageStim(
win=win,
name='vertical_1',
image='instruction_images/vertical_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.05), size=(0.025, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
horiozntal_top_1 = visual.ImageStim(
win=win,
name='horiozntal_top_1',
image='instruction_images/hori_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0.35), size=(0.1, 0.02),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
horizontal_bottom_1 = visual.ImageStim(
win=win,
name='horizontal_bottom_1',
image='instruction_images/hori_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.02),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
pain_continuous_image = visual.ImageStim(
win=win,
name='pain_continuous_image',
image='instruction_images/pain_pred.PNG', mask=None, anchor='center',
ori=0.0, pos=(0.0, 0.45), size=(0.627, 0.09405),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
most_pain_1 = visual.TextStim(win=win, name='most_pain_1',
text='Most Pain',
font='Arial',
pos=(-0.15, 0.352), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-4.0);
least_pain_1 = visual.TextStim(win=win, name='least_pain_1',
text='Least Pain',
font='Arial',
pos=(-0.15, -0.445), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-5.0);
continuous_pain_slider = visual.Slider(win=win, name='continuous_pain_slider',
startValue=None, size=(0.1, 0.8), pos=(0, -0.05), units=None,
labels=None, ticks=(1, 2), granularity=0.0,
style='rating', styleTweaks=(), opacity=None,
labelColor='white', markerColor=[1.0000, 0.6000, -1.0000], lineColor='White', colorSpace='rgb',
font='Arial', labelHeight=0.03,
flip=False, ori=0.0, depth=-6, readOnly=False)
# --- Initialize components for Routine "blank500ms" ---
text = visual.TextStim(win=win, name='text',
text=None,
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);
# --- Initialize components for Routine "pain_prediction" ---
vertical_2 = visual.ImageStim(
win=win,
name='vertical_2',
image='instruction_images/vertical_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.05), size=(0.025, 0.8),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
horizontal_bottom_2 = visual.ImageStim(
win=win,
name='horizontal_bottom_2',
image='instruction_images/hori_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.02),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
horizontal_top_2 = visual.ImageStim(
win=win,
name='horizontal_top_2',
image='instruction_images/hori_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0.35), size=(0.1, 0.02),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
pain_predict_image = visual.ImageStim(
win=win,
name='pain_predict_image',
image='instruction_images/pain_expect.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0.45), size=(0.5544, 0.1188),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
most_pain_2 = visual.TextStim(win=win, name='most_pain_2',
text='Most Pain',
font='Arial',
pos=(-0.15, 0.352), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-4.0);
least_pain_2 = visual.TextStim(win=win, name='least_pain_2',
text='Least Pain',
font='Arial',
pos=(-0.15, -0.445), height=0.03, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=-5.0);
pain_predict_slider = visual.Slider(win=win, name='pain_predict_slider',
startValue=None, size=(0.1, 0.8), pos=(0, -0.05), units=None,
labels=None, ticks=(1, 2), granularity=0.0,
style='rating', styleTweaks=(), opacity=None,
labelColor='white', markerColor=[0.3333, 0.3333, 1.0000], lineColor='White', colorSpace='rgb',
font='Arial', labelHeight=0.03,
flip=False, ori=0.0, depth=-6, readOnly=False)
# --- Initialize components for Routine "blank500ms" ---
text = visual.TextStim(win=win, name='text',
text=None,
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);
# --- Initialize components for Routine "pain_confidence" ---
horizontal_central = visual.ImageStim(
win=win,
name='horizontal_central',
image='instruction_images/hori_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.6, 0.025),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=0.0)
vertical_right = visual.ImageStim(
win=win,
name='vertical_right',
image='instruction_images/vertical_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(0.3, 0), size=(0.02, 0.1),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
vertical_left = visual.ImageStim(
win=win,
name='vertical_left',
image='instruction_images/vertical_white_rectangle.png', mask=None, anchor='center',
ori=0.0, pos=(-0.3, 0), size=(0.02, 0.1),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-2.0)
confidence_image = visual.ImageStim(
win=win,
name='confidence_image',
image='instruction_images/confidence.PNG', mask=None, anchor='center',
ori=0.0, pos=(0, 0.35), size=(0.5544, 0.1188),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-3.0)
confidence_slider_2 = visual.Slider(win=win, name='confidence_slider_2',
startValue=None, size=(0.6, 0.1), pos=(0, 0), units=None,
labels=['Unsure', 'Sure'], ticks=(1, 2), granularity=0.0,
style='rating', styleTweaks=(), opacity=None,
labelColor='White', markerColor=[-1.0000, 1.0000, 1.0000], lineColor='White', colorSpace='rgb',
font='Arial', labelHeight=0.03,
flip=False, ori=0.0, depth=-4, readOnly=False)
# --- Initialize components for Routine "end_screen" ---
ending = visual.TextStim(win=win, name='ending',
text='The session is over! \nThank you for completing the task. \n\nPlease click on the button below to \nfinish the game.',
font='Arial',
pos=(0, 0.2), height=0.025, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
finish_button = visual.ImageStim(
win=win,
name='finish_button',
image='instruction_images/finish_button.png', mask=None, anchor='center',
ori=0.0, pos=(0, -0.45), size=(0.1, 0.07),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)
mouse = event.Mouse(win=win)
x, y = [None, None]
mouse.mouseClock = core.Clock()
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.Clock() # to track time remaining of each (possibly non-slip) routine
# --- Prepare to start Routine "instruction_1" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
# setup some python lists for storing info about the mouse_1
mouse_1.x = []
mouse_1.y = []
mouse_1.leftButton = []
mouse_1.midButton = []
mouse_1.rightButton = []
mouse_1.time = []
mouse_1.clicked_name = []
gotValidClick = False # until a click is received
# keep track of which components have finished
instruction_1Components = [next_button_1, mouse_1, slider_1, instruction_1_text_new]
for thisComponent in instruction_1Components:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "instruction_1" ---
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
# *next_button_1* updates
if next_button_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
next_button_1.frameNStart = frameN # exact frame index
next_button_1.tStart = t # local t and not account for scr refresh
next_button_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(next_button_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'next_button_1.started')
next_button_1.setAutoDraw(True)
# *mouse_1* updates
if mouse_1.status == NOT_STARTED and t >= 0.0-frameTolerance:
# keep track of start time/frame for later
mouse_1.frameNStart = frameN # exact frame index
mouse_1.tStart = t # local t and not account for scr refresh
mouse_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mouse_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.addData('mouse_1.started', t)
mouse_1.status = STARTED
mouse_1.mouseClock.reset()
prevButtonState = mouse_1.getPressed() # if button is down already this ISN'T a new click
if mouse_1.status == STARTED: # only update if started and not finished!
buttons = mouse_1.getPressed()
if buttons != prevButtonState: # button state changed?
prevButtonState = buttons
if sum(buttons) > 0: # state changed to a new click
# check if the mouse was inside our 'clickable' objects
gotValidClick = False
try:
iter(next_button_1)
clickableList = next_button_1
except:
clickableList = [next_button_1]
for obj in clickableList:
if obj.contains(mouse_1):
gotValidClick = True
mouse_1.clicked_name.append(obj.name)
x, y = mouse_1.getPos()
mouse_1.x.append(x)
mouse_1.y.append(y)
buttons = mouse_1.getPressed()
mouse_1.leftButton.append(buttons[0])
mouse_1.midButton.append(buttons[1])
mouse_1.rightButton.append(buttons[2])
mouse_1.time.append(mouse_1.mouseClock.getTime())
if gotValidClick:
continueRoutine = False # abort routine on response
# *slider_1* updates
if slider_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
slider_1.frameNStart = frameN # exact frame index
slider_1.tStart = t # local t and not account for scr refresh
slider_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(slider_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'slider_1.started')
slider_1.setAutoDraw(True)
# *instruction_1_text_new* updates
if instruction_1_text_new.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
instruction_1_text_new.frameNStart = frameN # exact frame index
instruction_1_text_new.tStart = t # local t and not account for scr refresh
instruction_1_text_new.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instruction_1_text_new, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'instruction_1_text_new.started')
instruction_1_text_new.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
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in instruction_1Components:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "instruction_1" ---
for thisComponent in instruction_1Components:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# store data for thisExp (ExperimentHandler)
thisExp.addData('mouse_1.x', mouse_1.x)
thisExp.addData('mouse_1.y', mouse_1.y)
thisExp.addData('mouse_1.leftButton', mouse_1.leftButton)
thisExp.addData('mouse_1.midButton', mouse_1.midButton)
thisExp.addData('mouse_1.rightButton', mouse_1.rightButton)
thisExp.addData('mouse_1.time', mouse_1.time)
thisExp.addData('mouse_1.clicked_name', mouse_1.clicked_name)
thisExp.nextEntry()
# the Routine "instruction_1" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "instruction_2" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
# setup some python lists for storing info about the mouse_2
mouse_2.x = []
mouse_2.y = []
mouse_2.leftButton = []
mouse_2.midButton = []
mouse_2.rightButton = []
mouse_2.time = []
mouse_2.clicked_name = []
gotValidClick = False # until a click is received
# keep track of which components have finished
instruction_2Components = [next_button_2, mouse_2, slider_2, text_2]
for thisComponent in instruction_2Components:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "instruction_2" ---
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
# *next_button_2* updates
if next_button_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
next_button_2.frameNStart = frameN # exact frame index
next_button_2.tStart = t # local t and not account for scr refresh
next_button_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(next_button_2, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'next_button_2.started')
next_button_2.setAutoDraw(True)
# *mouse_2* updates
if mouse_2.status == NOT_STARTED and t >= 0.0-frameTolerance:
# keep track of start time/frame for later
mouse_2.frameNStart = frameN # exact frame index
mouse_2.tStart = t # local t and not account for scr refresh
mouse_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mouse_2, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.addData('mouse_2.started', t)
mouse_2.status = STARTED
mouse_2.mouseClock.reset()
prevButtonState = mouse_2.getPressed() # if button is down already this ISN'T a new click
if mouse_2.status == STARTED: # only update if started and not finished!
buttons = mouse_2.getPressed()
if buttons != prevButtonState: # button state changed?
prevButtonState = buttons
if sum(buttons) > 0: # state changed to a new click
# check if the mouse was inside our 'clickable' objects
gotValidClick = False
try:
iter(next_button_2)
clickableList = next_button_2
except:
clickableList = [next_button_2]
for obj in clickableList:
if obj.contains(mouse_2):
gotValidClick = True
mouse_2.clicked_name.append(obj.name)
x, y = mouse_2.getPos()
mouse_2.x.append(x)
mouse_2.y.append(y)
buttons = mouse_2.getPressed()
mouse_2.leftButton.append(buttons[0])
mouse_2.midButton.append(buttons[1])
mouse_2.rightButton.append(buttons[2])
mouse_2.time.append(mouse_2.mouseClock.getTime())
if gotValidClick:
continueRoutine = False # abort routine on response
# *slider_2* updates
if slider_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
slider_2.frameNStart = frameN # exact frame index
slider_2.tStart = t # local t and not account for scr refresh
slider_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(slider_2, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'slider_2.started')
slider_2.setAutoDraw(True)
# *text_2* updates
if text_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text_2.frameNStart = frameN # exact frame index
text_2.tStart = t # local t and not account for scr refresh
text_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text_2, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'text_2.started')
text_2.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
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in instruction_2Components:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "instruction_2" ---
for thisComponent in instruction_2Components:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# store data for thisExp (ExperimentHandler)
thisExp.addData('mouse_2.x', mouse_2.x)
thisExp.addData('mouse_2.y', mouse_2.y)
thisExp.addData('mouse_2.leftButton', mouse_2.leftButton)
thisExp.addData('mouse_2.midButton', mouse_2.midButton)
thisExp.addData('mouse_2.rightButton', mouse_2.rightButton)
thisExp.addData('mouse_2.time', mouse_2.time)
thisExp.addData('mouse_2.clicked_name', mouse_2.clicked_name)
thisExp.nextEntry()
# the Routine "instruction_2" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "instruction_3" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
# setup some python lists for storing info about the mouse_3
mouse_3.x = []
mouse_3.y = []
mouse_3.leftButton = []
mouse_3.midButton = []
mouse_3.rightButton = []
mouse_3.time = []
mouse_3.clicked_name = []
gotValidClick = False # until a click is received
# keep track of which components have finished
instruction_3Components = [mouse_3, start_button, slider_3, instruction_3_text_]
for thisComponent in instruction_3Components:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
frameN = -1
# --- Run Routine "instruction_3" ---
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
# *mouse_3* updates
if mouse_3.status == NOT_STARTED and t >= 0.0-frameTolerance:
# keep track of start time/frame for later
mouse_3.frameNStart = frameN # exact frame index
mouse_3.tStart = t # local t and not account for scr refresh
mouse_3.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mouse_3, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.addData('mouse_3.started', t)
mouse_3.status = STARTED
mouse_3.mouseClock.reset()
prevButtonState = mouse_3.getPressed() # if button is down already this ISN'T a new click
if mouse_3.status == STARTED: # only update if started and not finished!
buttons = mouse_3.getPressed()
if buttons != prevButtonState: # button state changed?
prevButtonState = buttons
if sum(buttons) > 0: # state changed to a new click
# check if the mouse was inside our 'clickable' objects
gotValidClick = False
try:
iter(start_button)
clickableList = start_button
except:
clickableList = [start_button]
for obj in clickableList:
if obj.contains(mouse_3):
gotValidClick = True
mouse_3.clicked_name.append(obj.name)
x, y = mouse_3.getPos()
mouse_3.x.append(x)
mouse_3.y.append(y)
buttons = mouse_3.getPressed()
mouse_3.leftButton.append(buttons[0])
mouse_3.midButton.append(buttons[1])
mouse_3.rightButton.append(buttons[2])
mouse_3.time.append(mouse_3.mouseClock.getTime())
if gotValidClick:
continueRoutine = False # abort routine on response
# *start_button* updates
if start_button.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
start_button.frameNStart = frameN # exact frame index
start_button.tStart = t # local t and not account for scr refresh
start_button.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(start_button, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'start_button.started')
start_button.setAutoDraw(True)
# *slider_3* updates
if slider_3.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
slider_3.frameNStart = frameN # exact frame index
slider_3.tStart = t # local t and not account for scr refresh
slider_3.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(slider_3, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'slider_3.started')
slider_3.setAutoDraw(True)
# *instruction_3_text_* updates
if instruction_3_text_.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
instruction_3_text_.frameNStart = frameN # exact frame index
instruction_3_text_.tStart = t # local t and not account for scr refresh
instruction_3_text_.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(instruction_3_text_, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'instruction_3_text_.started')
instruction_3_text_.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
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in instruction_3Components:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# --- Ending Routine "instruction_3" ---
for thisComponent in instruction_3Components:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# store data for thisExp (ExperimentHandler)
thisExp.addData('mouse_3.x', mouse_3.x)
thisExp.addData('mouse_3.y', mouse_3.y)
thisExp.addData('mouse_3.leftButton', mouse_3.leftButton)
thisExp.addData('mouse_3.midButton', mouse_3.midButton)
thisExp.addData('mouse_3.rightButton', mouse_3.rightButton)
thisExp.addData('mouse_3.time', mouse_3.time)
thisExp.addData('mouse_3.clicked_name', mouse_3.clicked_name)
thisExp.nextEntry()
# the Routine "instruction_3" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=5.0, method='sequential',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='trials')
thisExp.addLoop(trials) # add the loop to the experiment
thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial:
exec('{} = thisTrial[paramName]'.format(paramName))
for thisTrial in trials:
currentLoop = trials
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial:
exec('{} = thisTrial[paramName]'.format(paramName))
# --- Prepare to start Routine "blank500ms" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
# keep track of which components have finished
blank500msComponents = [text]
for thisComponent in blank500msComponents:
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 "blank500ms" ---
while continueRoutine and routineTimer.getTime() < 0.5:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text* updates
if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text.frameNStart = frameN # exact frame index
text.tStart = t # local t and not account for scr refresh
text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'text.started')
text.setAutoDraw(True)
if text.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > text.tStartRefresh + 0.5-frameTolerance:
# keep track of stop time/frame for later
text.tStop = t # not accounting for scr refresh
text.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'text.stopped')
text.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
routineForceEnded = True
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in blank500msComponents:
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 "blank500ms" ---
for thisComponent in blank500msComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# using non-slip timing so subtract the expected duration of this Routine (unless ended on request)
if routineForceEnded:
routineTimer.reset()
else:
routineTimer.addTime(-0.500000)
# --- Prepare to start Routine "continuous_pain_rating" ---
continueRoutine = True
routineForceEnded = False
# update component parameters for each repeat
continuous_pain_slider.reset()
# keep track of which components have finished
continuous_pain_ratingComponents = [vertical_1, horiozntal_top_1, horizontal_bottom_1, pain_continuous_image, most_pain_1, least_pain_1, continuous_pain_slider]
for thisComponent in continuous_pain_ratingComponents:
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 "continuous_pain_rating" ---
while continueRoutine and routineTimer.getTime() < 10.0:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *vertical_1* updates
if vertical_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
vertical_1.frameNStart = frameN # exact frame index
vertical_1.tStart = t # local t and not account for scr refresh
vertical_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(vertical_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'vertical_1.started')
vertical_1.setAutoDraw(True)
if vertical_1.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > vertical_1.tStartRefresh + 10-frameTolerance:
# keep track of stop time/frame for later
vertical_1.tStop = t # not accounting for scr refresh
vertical_1.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'vertical_1.stopped')
vertical_1.setAutoDraw(False)
# *horiozntal_top_1* updates
if horiozntal_top_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
horiozntal_top_1.frameNStart = frameN # exact frame index
horiozntal_top_1.tStart = t # local t and not account for scr refresh
horiozntal_top_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(horiozntal_top_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'horiozntal_top_1.started')
horiozntal_top_1.setAutoDraw(True)
if horiozntal_top_1.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > horiozntal_top_1.tStartRefresh + 10-frameTolerance:
# keep track of stop time/frame for later
horiozntal_top_1.tStop = t # not accounting for scr refresh
horiozntal_top_1.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'horiozntal_top_1.stopped')
horiozntal_top_1.setAutoDraw(False)
# *horizontal_bottom_1* updates
if horizontal_bottom_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
horizontal_bottom_1.frameNStart = frameN # exact frame index
horizontal_bottom_1.tStart = t # local t and not account for scr refresh
horizontal_bottom_1.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(horizontal_bottom_1, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'horizontal_bottom_1.started')
horizontal_bottom_1.setAutoDraw(True)
if horizontal_bottom_1.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > horizontal_bottom_1.tStartRefresh + 10-frameTolerance:
# keep track of stop time/frame for later
horizontal_bottom_1.tStop = t # not accounting for scr refresh
horizontal_bottom_1.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'horizontal_bottom_1.stopped')
horizontal_bottom_1.setAutoDraw(False)
# *pain_continuous_image* updates
if pain_continuous_image.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
pain_continuous_image.frameNStart = frameN # exact frame index
pain_continuous_image.tStart = t # local t and not account for scr refresh
pain_continuous_image.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(pain_continuous_image, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'pain_continuous_image.started')
pain_continuous_image.setAutoDraw(True)
if pain_continuous_image.status == STARTED:
# is it time to stop? (based on global clock, using actual start)