-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtask-qct_bold.py
1805 lines (1613 loc) · 79.7 KB
/
task-qct_bold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2023.2.3),
on mar 24 oct 2023 18:18:17
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 plugins
plugins.activatePlugins()
prefs.hardware['audioLib'] = 'ptb'
prefs.hardware['audioLatencyMode'] = '0'
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, iohub, hardware
from psychopy.tools import environmenttools
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER, priority)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os # handy system and path functions
import sys # to get file system encoding
import psychopy.iohub as io
from psychopy.hardware import keyboard
# Run 'Before Experiment' code from channel_2
import socket
from hcphsignals import signals
from datetime import datetime
import pwd
def send_message(message, addr="localhost", port=2023):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((addr, port))
client_socket.sendall(message)
client_socket.close()
current_user = pwd.getpwuid(os.geteuid()).pw_name
folder_path = os.path.dirname('/home/'+current_user +'/workspace/HCPh-data/Psychopy/session-'+data.getDateStr(format="%Y-%m-%d")+'/')
if not os.path.exists(folder_path):
os.makedirs(folder_path)
ename = 'qct_'+data.getDateStr(format="%Y-%m-%d")
trial = 0
for file in os.listdir(folder_path):
filename_hour = datetime.strptime(file.split('_')[2],'%Hh%M.%S.%f')
current_time = datetime.now()
filename_hour_components = (filename_hour.hour, filename_hour.minute)
current_time_components = (current_time.hour, current_time.minute)
hour_difference = abs((current_time_components[0] - filename_hour_components[0]) +
(current_time_components[1] - filename_hour_components[1]) / 60.0)
if ename in file and '.log' in file and hour_difference <1.5:
trial += 1
# --- Setup global variables (available in all functions) ---
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
# Store info about the experiment session
psychopyVersion = '2023.2.3'
expName = 'qct' # from the Builder filename that created this script
expInfo = {
'trial': trial,
'session': '9999',
'date': data.getDateStr(), # add a simple timestamp
'expName': expName,
'psychopyVersion': psychopyVersion,
}
def showExpInfoDlg(expInfo):
"""
Show participant info dialog.
Parameters
==========
expInfo : dict
Information about this experiment, created by the `setupExpInfo` function.
Returns
==========
dict
Information about this experiment.
"""
# temporarily remove keys which the dialog doesn't need to show
poppedKeys = {
'date': expInfo.pop('date', data.getDateStr()),
'expName': expInfo.pop('expName', expName),
'psychopyVersion': expInfo.pop('psychopyVersion', psychopyVersion),
}
# show participant info dialog
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
# restore hidden keys
expInfo.update(poppedKeys)
# return expInfo
return expInfo
def setupData(expInfo, dataDir=None):
"""
Make an ExperimentHandler to handle trials and saving.
Parameters
==========
expInfo : dict
Information about this experiment, created by the `setupExpInfo` function.
dataDir : Path, str or None
Folder to save the data to, leave as None to create a folder in the current directory.
Returns
==========
psychopy.data.ExperimentHandler
Handler object for this experiment, contains the data to save and information about
where to save it to.
"""
# data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
if dataDir is None:
dataDir = _thisDir
filename = u'../HCPh-data/Psychopy/session-'+data.getDateStr(format="%Y-%m-%d")+'/%s_%s_%s_session_%s' %(expName, expInfo['date'],expInfo['trial'],expInfo['session'])
# make sure filename is relative to dataDir
if os.path.isabs(filename):
dataDir = os.path.commonprefix([dataDir, filename])
filename = os.path.relpath(filename, dataDir)
# an ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(
name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='task-qct_bold.py',
savePickle=True, saveWideText=False,
dataFileName=dataDir + os.sep + filename, sortColumns='time'
)
thisExp.setPriority('thisRow.t', priority.CRITICAL)
thisExp.setPriority('expName', priority.LOW)
# return experiment handler
return thisExp
def setupLogging(filename):
"""
Setup a log file and tell it what level to log at.
Parameters
==========
filename : str or pathlib.Path
Filename to save log file and data files as, doesn't need an extension.
Returns
==========
psychopy.logging.LogFile
Text stream to receive inputs from the logging system.
"""
# this outputs to the screen, not a file
logging.console.setLevel(logging.INFO)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.INFO)
return logFile
def setupWindow(expInfo=None, win=None):
"""
Setup the Window
Parameters
==========
expInfo : dict
Information about this experiment, created by the `setupExpInfo` function.
win : psychopy.visual.Window
Window to setup - leave as None to create a new window.
Returns
==========
psychopy.visual.Window
Window in which to run this experiment.
"""
if win is None:
# if not given a window to setup, make one
win = visual.Window(
size=[800, 600], fullscr=True, screen=1,
winType='pyglet', allowStencil=False,
monitor='testMonitor', color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb',
backgroundImage='', backgroundFit='none',
blendMode='avg', useFBO=True,
units='norm'
)
if expInfo is not None:
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
else:
# if we have a window, just set the attributes which are safe to set
win.color = [-1.0000, -1.0000, -1.0000]
win.colorSpace = 'rgb'
win.backgroundImage = ''
win.backgroundFit = 'none'
win.units = 'norm'
win.mouseVisible = False
win.hideMessage()
return win
def setupInputs(expInfo, thisExp, win):
"""
Setup whatever inputs are available (mouse, keyboard, eyetracker, etc.)
Parameters
==========
expInfo : dict
Information about this experiment, created by the `setupExpInfo` function.
thisExp : psychopy.data.ExperimentHandler
Handler object for this experiment, contains the data to save and information about
where to save it to.
win : psychopy.visual.Window
Window in which to run this experiment.
Returns
==========
dict
Dictionary of input devices by name.
"""
# --- Setup input devices ---
inputs = {}
ioConfig = {}
# Setup eyetracking
ioConfig['eyetracker.hw.sr_research.eyelink.EyeTracker'] = {
'name': 'tracker',
'model_name': 'EYELINK 1000 LONG RANGE',
'simulation_mode': False,
'network_settings': '100.1.1.1',
'default_native_data_file_name': 'EXPFILE',
'runtime_settings': {
'sampling_rate': 1000.0,
'track_eyes': 'RIGHT_EYE',
'sample_filtering': {
'sample_filtering': 'FILTER_LEVEL_2',
'elLiveFiltering': 'FILTER_LEVEL_OFF',
},
'vog_settings': {
'pupil_measure_types': 'PUPIL_AREA',
'tracking_mode': 'PUPIL_CR_TRACKING',
'pupil_center_algorithm': 'ELLIPSE_FIT',
}
}
}
# Setup iohub keyboard
ioConfig['Keyboard'] = dict(use_keymap='psychopy')
ioSession = '1'
if 'session' in expInfo:
ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, experiment_code='qct', session_code=ioSession, datastore_name=thisExp.dataFileName, **ioConfig)
eyetracker = ioServer.getDevice('tracker')
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend='iohub')
# return inputs dict
return {
'ioServer': ioServer,
'defaultKeyboard': defaultKeyboard,
'eyetracker': eyetracker,
}
def pauseExperiment(thisExp, inputs=None, win=None, timers=[], playbackComponents=[]):
"""
Pause this experiment, preventing the flow from advancing to the next routine until resumed.
Parameters
==========
thisExp : psychopy.data.ExperimentHandler
Handler object for this experiment, contains the data to save and information about
where to save it to.
inputs : dict
Dictionary of input devices by name.
win : psychopy.visual.Window
Window for this experiment.
timers : list, tuple
List of timers to reset once pausing is finished.
playbackComponents : list, tuple
List of any components with a `pause` method which need to be paused.
"""
# if we are not paused, do nothing
if thisExp.status != PAUSED:
return
# pause any playback components
for comp in playbackComponents:
comp.pause()
# prevent components from auto-drawing
win.stashAutoDraw()
# run a while loop while we wait to unpause
while thisExp.status == PAUSED:
# make sure we have a keyboard
if inputs is None:
inputs = {
'defaultKeyboard': keyboard.Keyboard(backend='ioHub')
}
# check for quit (typically the Esc key)
if inputs['defaultKeyboard'].getKeys(keyList=['escape']):
endExperiment(thisExp, win=win, inputs=inputs)
# flip the screen
win.flip()
# if stop was requested while paused, quit
if thisExp.status == FINISHED:
endExperiment(thisExp, inputs=inputs, win=win)
# resume any playback components
for comp in playbackComponents:
comp.play()
# restore auto-drawn components
win.retrieveAutoDraw()
# reset any timers
for timer in timers:
timer.reset()
def run(expInfo, thisExp, win, inputs, globalClock=None, thisSession=None):
"""
Run the experiment flow.
Parameters
==========
expInfo : dict
Information about this experiment, created by the `setupExpInfo` function.
thisExp : psychopy.data.ExperimentHandler
Handler object for this experiment, contains the data to save and information about
where to save it to.
psychopy.visual.Window
Window in which to run this experiment.
inputs : dict
Dictionary of input devices by name.
globalClock : psychopy.core.clock.Clock or None
Clock to get global time from - supply None to make a new one.
thisSession : psychopy.session.Session or None
Handle of the Session object this experiment is being run from, if any.
"""
# mark experiment as started
thisExp.status = STARTED
# make sure variables created by exec are available globally
exec = environmenttools.setExecEnvironment(globals())
# get device handles from dict of input devices
ioServer = inputs['ioServer']
defaultKeyboard = inputs['defaultKeyboard']
eyetracker = inputs['eyetracker']
# make sure we're running in the directory for this experiment
os.chdir(_thisDir)
# get filename from ExperimentHandler for convenience
filename = thisExp.dataFileName
frameTolerance = 0.001 # how close to onset before 'same' frame
endExpNow = False # flag for 'escape' or other condition => quit the exp
# get frame duration from frame rate in expInfo
if 'frameRate' in expInfo and expInfo['frameRate'] is not None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
# Start Code - component code to be run after the window creation
# --- Initialize components for Routine "intro" ---
wait_trigger = visual.TextStim(win=win, name='wait_trigger',
text='The program is ready for the scanner trigger. Press t to proceed manually.',
font='Arial',
pos=[0, -0.9], height=0.07, wrapWidth=1.5, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
key_resp_2 = keyboard.Keyboard()
fix_desc = visual.TextStim(win=win, name='fix_desc',
text='This task is composed of several blocks of stimuli. Whenever you see a green circle like the one below, please fix your gaze on it. If the circle moves, follow it with your eyes.',
font='Arial',
pos=(0.0, 0.6), height=0.12, wrapWidth=1.7, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-2.0);
fixation_example = visual.ShapeStim(
win=win, name='fixation_example',
size=(0.075, 0.1), vertices='circle',
ori=0.0, pos=(0, 0.1), anchor='center',
lineWidth=2.0, colorSpace='rgb', lineColor=[-1.0000, -1.0000, -1.0000], fillColor=[0.0000, 0.0000, 0.0000],
opacity=None, depth=-3.0, interpolate=True)
et_desc = visual.TextStim(win=win, name='et_desc',
text=' If you see "RIGHT" or "LEFT", sequentially tap your thumb with your other fingers of the corresponding hand.\nPlease leave the alarm button somewhere you can retrieve it when the task is concluded.',
font='Arial',
pos=(0, -0.4), height=0.12, wrapWidth=1.7, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-4.0);
fixation_example_inner = visual.ShapeStim(
win=win, name='fixation_example_inner',
size=(0.035, 0.047), vertices='circle',
ori=0.0, pos=(0, 0.1), anchor='center',
lineWidth=2.0, colorSpace='rgb', lineColor=[-1.0000, -1.0000, -1.0000], fillColor=[-1.0000, 1.0000, -1.0000],
opacity=None, depth=-5.0, interpolate=True)
# --- Initialize components for Routine "start_et" ---
et_start = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Start Only'
)
# Run 'Begin Experiment' code from channel_2
# --- Initialize components for Routine "trialSelection" ---
# Run 'Begin Experiment' code from code_4
nRepsvis=0
nRepsmot=0
nRepscog=0
nRepsblank=0
# --- Initialize components for Routine "vis" ---
grating = visual.GratingStim(
win=win, name='grating',
tex='sin', mask='gauss', anchor='center',
ori=0, pos=[0, 0], size=[1.3, 1.6], sf=12, phase=1.0,
color=[1,1,1], colorSpace='rgb',
opacity=1, contrast=1.0, blendmode='avg',
texRes=128, interpolate=True, depth=-1.0)
fixation_inner_circle = visual.ShapeStim(
win=win, name='fixation_inner_circle',
size=[0.035, 0.045], vertices='circle',
ori=0, pos=[0, 0], anchor='center',
lineWidth=1, colorSpace='rgb', lineColor=[-1,-1,-1], fillColor=[-1,1,-1],
opacity=1, depth=-2.0, interpolate=True)
# --- Initialize components for Routine "cog" ---
eye_movement_fixation = visual.ShapeStim(
win=win, name='eye_movement_fixation',
size=[0.075, 0.1], vertices='circle',
ori=0, pos=[0,0], anchor='center',
lineWidth=2, colorSpace='rgb', lineColor=[-1,-1,-1], fillColor=[0,0,0],
opacity=1, depth=0.0, interpolate=True)
eye_movement_fixation_inner = visual.ShapeStim(
win=win, name='eye_movement_fixation_inner',
size=[0.035, 0.045], vertices='circle',
ori=0, pos=[0,0], anchor='center',
lineWidth=2, colorSpace='rgb', lineColor=[-1,-1,-1], fillColor=[-1,1,-1],
opacity=1, depth=-1.0, interpolate=True)
# --- Initialize components for Routine "mot" ---
ft_hand = visual.TextStim(win=win, name='ft_hand',
text='',
font='Arial',
pos=[0,0], height=0.15, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
# --- Initialize components for Routine "blank" ---
fixation = visual.ShapeStim(
win=win, name='fixation',
size=[0.075, 0.1], vertices='circle',
ori=0, pos=[0, 0], anchor='center',
lineWidth=2, colorSpace='rgb', lineColor=[-1,-1,-1], fillColor=[0,0,0],
opacity=1, depth=0.0, interpolate=True)
fixation_inner = visual.ShapeStim(
win=win, name='fixation_inner',
size=[0.035, 0.047], vertices='circle',
ori=0, pos=[0, 0], anchor='center',
lineWidth=2, colorSpace='rgb', lineColor=[-1,-1,-1], fillColor=[-1,1,-1],
opacity=1, depth=-1.0, interpolate=True)
# --- Initialize components for Routine "end" ---
et_stop = hardware.eyetracker.EyetrackerControl(
tracker=eyetracker,
actionType='Stop Only'
)
# create some handy timers
if globalClock is None:
globalClock = core.Clock() # to track the time since experiment started
if ioServer is not None:
ioServer.syncClock(globalClock)
logging.setDefaultClock(globalClock)
routineTimer = core.Clock() # to track time remaining of each (possibly non-slip) routine
win.flip() # flip window to reset last flip timer
# store the exact time the global clock started
expInfo['expStart'] = data.getDateStr(format='%Y-%m-%d %Hh%M.%S.%f %z', fractionalSecondDigits=6)
# define target for calibration
calibrationTarget = visual.TargetStim(win,
name='calibrationTarget',
radius=0.075, fillColor=[-1.0000, -1.0000, -1.0000], borderColor='black', lineWidth=2.0,
innerRadius=0.035, innerFillColor='green', innerBorderColor='black', innerLineWidth=2.0,
colorSpace='rgb', units=None
)
# define parameters for calibration
calibration = hardware.eyetracker.EyetrackerCalibration(win,
eyetracker, calibrationTarget,
units=None, colorSpace='rgb',
progressMode='time', targetDur=1.5, expandScale=1.5,
targetLayout='NINE_POINTS', randomisePos=False, textColor='white',
movementAnimation=True, targetDelay=1.0
)
# run calibration
calibration.run()
# clear any keypresses from during calibration so they don't interfere with the experiment
defaultKeyboard.clearEvents()
# the Routine "calibration" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "intro" ---
continueRoutine = True
# update component parameters for each repeat
thisExp.addData('intro.started', globalClock.getTime())
key_resp_2.keys = []
key_resp_2.rt = []
_key_resp_2_allKeys = []
# keep track of which components have finished
introComponents = [wait_trigger, key_resp_2, fix_desc, fixation_example, et_desc, fixation_example_inner]
for thisComponent in introComponents:
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 "intro" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *wait_trigger* updates
# if wait_trigger is starting this frame...
if wait_trigger.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
wait_trigger.frameNStart = frameN # exact frame index
wait_trigger.tStart = t # local t and not account for scr refresh
wait_trigger.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(wait_trigger, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'wait_trigger.started')
# update status
wait_trigger.status = STARTED
wait_trigger.setAutoDraw(True)
# if wait_trigger is active this frame...
if wait_trigger.status == STARTED:
# update params
pass
# *key_resp_2* updates
waitOnFlip = False
# if key_resp_2 is starting this frame...
if key_resp_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
key_resp_2.frameNStart = frameN # exact frame index
key_resp_2.tStart = t # local t and not account for scr refresh
key_resp_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(key_resp_2, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'key_resp_2.started')
# update status
key_resp_2.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(key_resp_2.clock.reset) # t=0 on next screen flip
win.callOnFlip(key_resp_2.clearEvents, eventType='keyboard') # clear events on next screen flip
if key_resp_2.status == STARTED and not waitOnFlip:
theseKeys = key_resp_2.getKeys(keyList=['t', 's'], ignoreKeys=["escape"], waitRelease=False)
_key_resp_2_allKeys.extend(theseKeys)
if len(_key_resp_2_allKeys):
key_resp_2.keys = _key_resp_2_allKeys[-1].name # just the last key pressed
key_resp_2.rt = _key_resp_2_allKeys[-1].rt
key_resp_2.duration = _key_resp_2_allKeys[-1].duration
# a response ends the routine
continueRoutine = False
# *fix_desc* updates
# if fix_desc is starting this frame...
if fix_desc.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fix_desc.frameNStart = frameN # exact frame index
fix_desc.tStart = t # local t and not account for scr refresh
fix_desc.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fix_desc, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fix_desc.started')
# update status
fix_desc.status = STARTED
fix_desc.setAutoDraw(True)
# if fix_desc is active this frame...
if fix_desc.status == STARTED:
# update params
pass
# *fixation_example* updates
# if fixation_example is starting this frame...
if fixation_example.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_example.frameNStart = frameN # exact frame index
fixation_example.tStart = t # local t and not account for scr refresh
fixation_example.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_example, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_example.started')
# update status
fixation_example.status = STARTED
fixation_example.setAutoDraw(True)
# if fixation_example is active this frame...
if fixation_example.status == STARTED:
# update params
pass
# *et_desc* updates
# if et_desc is starting this frame...
if et_desc.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
et_desc.frameNStart = frameN # exact frame index
et_desc.tStart = t # local t and not account for scr refresh
et_desc.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(et_desc, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'et_desc.started')
# update status
et_desc.status = STARTED
et_desc.setAutoDraw(True)
# if et_desc is active this frame...
if et_desc.status == STARTED:
# update params
pass
# *fixation_example_inner* updates
# if fixation_example_inner is starting this frame...
if fixation_example_inner.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_example_inner.frameNStart = frameN # exact frame index
fixation_example_inner.tStart = t # local t and not account for scr refresh
fixation_example_inner.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_example_inner, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'fixation_example_inner.started')
# update status
fixation_example_inner.status = STARTED
fixation_example_inner.setAutoDraw(True)
# if fixation_example_inner is active this frame...
if fixation_example_inner.status == STARTED:
# update params
pass
# check for quit (typically the Esc key)
if defaultKeyboard.getKeys(keyList=["escape"]):
thisExp.status = FINISHED
if thisExp.status == FINISHED or endExpNow:
endExperiment(thisExp, inputs=inputs, win=win)
return
# 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 introComponents:
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 "intro" ---
for thisComponent in introComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('intro.stopped', globalClock.getTime())
# check responses
if key_resp_2.keys in ['', [], None]: # No response was made
key_resp_2.keys = None
thisExp.addData('key_resp_2.keys',key_resp_2.keys)
if key_resp_2.keys != None: # we had a response
thisExp.addData('key_resp_2.rt', key_resp_2.rt)
thisExp.addData('key_resp_2.duration', key_resp_2.duration)
thisExp.nextEntry()
# the Routine "intro" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# --- Prepare to start Routine "start_et" ---
continueRoutine = True
# update component parameters for each repeat
thisExp.addData('start_et.started', globalClock.getTime())
# Run 'Begin Routine' code from channel_2
send_message((signals.RUN | signals.ET_START_AND_STOP).to_bytes())
ioServer.getDevice('tracker').sendMessage("hello qct")
# keep track of which components have finished
start_etComponents = [et_start]
for thisComponent in start_etComponents:
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 "start_et" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *et_start* updates
# if et_start is starting this frame...
if et_start.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
et_start.frameNStart = frameN # exact frame index
et_start.tStart = t # local t and not account for scr refresh
et_start.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(et_start, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'et_start.started')
# update status
et_start.status = STARTED
# if et_start is stopping this frame...
if et_start.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > et_start.tStartRefresh + 0-frameTolerance:
# keep track of stop time/frame for later
et_start.tStop = t # not accounting for scr refresh
et_start.frameNStop = frameN # exact frame index
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'et_start.stopped')
# update status
et_start.status = FINISHED
# check for quit (typically the Esc key)
if defaultKeyboard.getKeys(keyList=["escape"]):
thisExp.status = FINISHED
if thisExp.status == FINISHED or endExpNow:
endExperiment(thisExp, inputs=inputs, win=win)
return
# 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 start_etComponents:
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 "start_et" ---
for thisComponent in start_etComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('start_et.stopped', globalClock.getTime())
# make sure the eyetracker recording stops
if et_start.status != FINISHED:
et_start.status = FINISHED
# the Routine "start_et" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
trialSelectLoop = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions('trial_select.csv'),
seed=None, name='trialSelectLoop')
thisExp.addLoop(trialSelectLoop) # add the loop to the experiment
thisTrialSelectLoop = trialSelectLoop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrialSelectLoop.rgb)
if thisTrialSelectLoop != None:
for paramName in thisTrialSelectLoop:
globals()[paramName] = thisTrialSelectLoop[paramName]
for thisTrialSelectLoop in trialSelectLoop:
currentLoop = trialSelectLoop
thisExp.timestampOnFlip(win, 'thisRow.t')
# pause experiment here if requested
if thisExp.status == PAUSED:
pauseExperiment(
thisExp=thisExp,
inputs=inputs,
win=win,
timers=[routineTimer],
playbackComponents=[]
)
# abbreviate parameter names if possible (e.g. rgb = thisTrialSelectLoop.rgb)
if thisTrialSelectLoop != None:
for paramName in thisTrialSelectLoop:
globals()[paramName] = thisTrialSelectLoop[paramName]
# --- Prepare to start Routine "trialSelection" ---
continueRoutine = True
# update component parameters for each repeat
thisExp.addData('trialSelection.started', globalClock.getTime())
# Run 'Begin Routine' code from code_4
if trialSelect ==1:
nRepsvis=1
nRepsmot=0
nRepscog=0
nRepsblank=0
if trialSelect ==2:
nRepsvis=0
nRepsmot=1
nRepscog=0
nRepsblank=0
if trialSelect ==3:
nRepsvis=0
nRepsmot=0
nRepscog=1
nRepsblank=0
if trialSelect ==4:
nRepsvis=0
nRepsmot=0
nRepscog=0
nRepsblank=1
print(trialSelect)
# keep track of which components have finished
trialSelectionComponents = []
for thisComponent in trialSelectionComponents:
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 "trialSelection" ---
routineForceEnded = not continueRoutine
while continueRoutine:
# get current time
t = routineTimer.getTime()
tThisFlip = win.getFutureFlipTime(clock=routineTimer)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# check for quit (typically the Esc key)
if defaultKeyboard.getKeys(keyList=["escape"]):
thisExp.status = FINISHED
if thisExp.status == FINISHED or endExpNow:
endExperiment(thisExp, inputs=inputs, win=win)
return
# 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 trialSelectionComponents:
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 "trialSelection" ---
for thisComponent in trialSelectionComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('trialSelection.stopped', globalClock.getTime())
# the Routine "trialSelection" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
visLoop = data.TrialHandler(nReps=nRepsvis, method='random',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='visLoop')
thisExp.addLoop(visLoop) # add the loop to the experiment
thisVisLoop = visLoop.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisVisLoop.rgb)
if thisVisLoop != None:
for paramName in thisVisLoop:
globals()[paramName] = thisVisLoop[paramName]
for thisVisLoop in visLoop:
currentLoop = visLoop
thisExp.timestampOnFlip(win, 'thisRow.t')
# pause experiment here if requested
if thisExp.status == PAUSED:
pauseExperiment(
thisExp=thisExp,
inputs=inputs,
win=win,
timers=[routineTimer],
playbackComponents=[]
)
# abbreviate parameter names if possible (e.g. rgb = thisVisLoop.rgb)
if thisVisLoop != None:
for paramName in thisVisLoop:
globals()[paramName] = thisVisLoop[paramName]
# --- Prepare to start Routine "vis" ---
continueRoutine = True
# update component parameters for each repeat
thisExp.addData('vis.started', globalClock.getTime())
# Run 'Begin Routine' code from code_2
gratingPhase=0
frameCounter=0
# Run 'Begin Routine' code from channel_4
send_message(signals.QCT_VIS.to_bytes())
ioServer.getDevice('tracker').sendMessage("start vis loop")
# keep track of which components have finished
visComponents = [grating, fixation_inner_circle]
for thisComponent in visComponents:
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 "vis" ---
routineForceEnded = not continueRoutine
while continueRoutine and routineTimer.getTime() < 3.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
# Run 'Each Frame' code from code_2
frameCounter=frameCounter+1
if frameCounter<30: # Change this number (30) to make the grating switch direction more/less often
gratingPhase=gratingPhase+0.1 # Change this number (0.1) to speed up or slow down the grating
if frameCounter>=30: # Change this number (30) to make the grating switch direction more/less of
gratingPhase=gratingPhase-0.1 # Change this number (0.1) to speed up or slow down the grating
if frameCounter==60:
frameCounter=0
# *grating* updates
# if grating is starting this frame...
if grating.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
grating.frameNStart = frameN # exact frame index
grating.tStart = t # local t and not account for scr refresh
grating.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(grating, 'tStartRefresh') # time at next scr refresh
# add timestamp to datafile
thisExp.timestampOnFlip(win, 'grating.started')
# update status
grating.status = STARTED
grating.setAutoDraw(True)
# if grating is active this frame...
if grating.status == STARTED:
# update params