peavler_lastrun.py 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This experiment was created using PsychoPy3 Experiment Builder (v2020.1.3),
  5. on Октябрь 04, 2020, at 20:26
  6. If you publish work using this script the most relevant publication is:
  7. Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
  8. PsychoPy2: Experiments in behavior made easy Behav Res 51: 195.
  9. https://doi.org/10.3758/s13428-018-01193-y
  10. """
  11. from __future__ import absolute_import, division
  12. import psychopy
  13. psychopy.useVersion('2020.1.3')
  14. from psychopy import locale_setup
  15. from psychopy import prefs
  16. prefs.hardware['audioLib'] = 'pyo'
  17. prefs.hardware['audioLatencyMode'] = '3'
  18. from psychopy import sound, gui, visual, core, data, event, logging, clock, parallel, microphone
  19. from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
  20. STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
  21. import numpy as np # whole numpy lib is available, prepend 'np.'
  22. from numpy import (sin, cos, tan, log, log10, pi, average,
  23. sqrt, std, deg2rad, rad2deg, linspace, asarray)
  24. from numpy.random import random, randint, normal, shuffle
  25. import os # handy system and path functions
  26. import sys # to get file system encoding
  27. from psychopy.hardware import keyboard
  28. # Ensure that relative paths start from the same directory as this script
  29. _thisDir = os.path.dirname(os.path.abspath(__file__))
  30. os.chdir(_thisDir)
  31. # Store info about the experiment session
  32. psychopyVersion = '2020.1.3'
  33. expName = 'peavler' # from the Builder filename that created this script
  34. expInfo = {'participant': '', 'session': 'experiment'}
  35. dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
  36. if dlg.OK == False:
  37. core.quit() # user pressed cancel
  38. expInfo['date'] = data.getDateStr() # add a simple timestamp
  39. expInfo['expName'] = expName
  40. expInfo['psychopyVersion'] = psychopyVersion
  41. # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
  42. filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
  43. # An ExperimentHandler isn't essential but helps with data saving
  44. thisExp = data.ExperimentHandler(name=expName, version='',
  45. extraInfo=expInfo, runtimeInfo=None,
  46. originPath='D:\\GoogleDisk\\Neurotech_lab\\cogLoad_project\\scripts\\peavlerRepl\\v15\\peavler_lastrun.py',
  47. savePickle=True, saveWideText=True,
  48. dataFileName=filename)
  49. # save a log file for detail verbose info
  50. logFile = logging.LogFile(filename+'.log', level=logging.EXP)
  51. logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
  52. endExpNow = False # flag for 'escape' or other condition => quit the exp
  53. frameTolerance = 0.001 # how close to onset before 'same' frame
  54. # Start Code - component code to be run before the window creation
  55. wavDirName = filename + '_wav'
  56. if not os.path.isdir(wavDirName):
  57. os.makedirs(wavDirName) # to hold .wav files
  58. # Setup the Window
  59. win = visual.Window(
  60. size=[200, 200], fullscr=False, screen=0,
  61. winType='pyglet', allowGUI=True, allowStencil=False,
  62. monitor='testMonitor', color=[0, 0, 0], colorSpace='rgb',
  63. blendMode='avg', useFBO=True,
  64. units='height')
  65. # Enable sound input/output:
  66. microphone.switchOn()
  67. # store frame rate of monitor if we can measure it
  68. expInfo['frameRate'] = win.getActualFrameRate()
  69. if expInfo['frameRate'] != None:
  70. frameDur = 1.0 / round(expInfo['frameRate'])
  71. else:
  72. frameDur = 1.0 / 60.0 # could not measure, so guess
  73. # create a default keyboard (e.g. to check for escape)
  74. defaultKeyboard = keyboard.Keyboard()
  75. # Initialize components for Routine "Randomizer"
  76. RandomizerClock = core.Clock()
  77. from numpy.random import choice
  78. import random
  79. from numpy import arange, concatenate
  80. def randomDigits(numOfReps):
  81. if numOfReps<=10:
  82. return choice(10, size=numOfReps, replace=False)
  83. else:
  84. arr1 = list(choice(10, size=10, replace=False))
  85. arr2 = list(choice(10, size=numOfReps-10, replace=False))
  86. while arr2[0] == arr1[-1]:
  87. random.shuffle(arr2)
  88. return arr1+arr2
  89. from zmq_socket import ZMQsocket
  90. from time import sleep, time
  91. #remote_ip = '192.168.0.2'
  92. remote_ip = '127.0.0.1'
  93. print('Make sure the ports match with Pupil Capture Remote Plugin and the one in zmq_pocket.py')
  94. port = '50020'
  95. socket = ZMQsocket(remote_ip,port)
  96. socket.connect()
  97. # socket.start_calibration()
  98. # Grab the time module for timesync
  99. time_fn = time
  100. # Sync time
  101. print(socket.set_time(time_fn))
  102. # # Start the notifications plugin
  103. socket.notify({'subject': 'start_plugin', 'name': 'Annotation_Capture', 'args': {}})
  104. #
  105. socket.start_recording() # commenting this out to test something, needs to be uncommented later.
  106. core.wait(0.005)
  107. ## send name of the participant as a trigger
  108. socket.annotation(str('Participant number '+expInfo['participant']), 0)
  109. print(str('Participant number '+expInfo['participant']))
  110. core.wait(10.005)
  111. # Initialize components for Routine "instruction"
  112. instructionClock = core.Clock()
  113. blockN=1
  114. trigger_instr_EEG = parallel.ParallelPort(address='0x0378')
  115. instruction_text = visual.TextStim(win=win, name='instruction_text',
  116. text='default text',
  117. font='Arial',
  118. pos=(0, 0), height=0.056, wrapWidth=None, ori=0,
  119. color='white', colorSpace='rgb', opacity=1,
  120. languageStyle='LTR',
  121. depth=-2.0);
  122. start_sound = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  123. name='start_sound')
  124. start_sound.setVolume(1)
  125. exclamationMark = visual.TextStim(win=win, name='exclamationMark',
  126. text='!',
  127. font='Arial',
  128. pos=(0, 0), height=0.076, wrapWidth=None, ori=0,
  129. color=[1,1,1], colorSpace='rgb', opacity=1,
  130. languageStyle='LTR',
  131. depth=-4.0);
  132. # Initialize components for Routine "baseline_3s"
  133. baseline_3sClock = core.Clock()
  134. trigger_baseline_EEG = parallel.ParallelPort(address='0x0378')
  135. fixCross = visual.ImageStim(
  136. win=win,
  137. name='fixCross',
  138. image='num/FixCross.png', mask=None,
  139. ori=0, pos=(0, 0), size=None,
  140. color=[1,1,1], colorSpace='rgb', opacity=1,
  141. flipHoriz=False, flipVert=False,
  142. texRes=128, interpolate=True, depth=-2.0)
  143. # Initialize components for Routine "digits"
  144. digitsClock = core.Clock()
  145. trigger_digits_EEG = parallel.ParallelPort(address='0x0378')
  146. sound_digit = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  147. name='sound_digit')
  148. sound_digit.setVolume(1)
  149. FixCross_answ = visual.ImageStim(
  150. win=win,
  151. name='FixCross_answ',
  152. image='num/FixCross.png', mask=None,
  153. ori=0, pos=(0, 0), size=None,
  154. color=[1,1,1], colorSpace='rgb', opacity=1,
  155. flipHoriz=False, flipVert=False,
  156. texRes=128, interpolate=True, depth=-3.0)
  157. # Initialize components for Routine "retention_1s"
  158. retention_1sClock = core.Clock()
  159. trigger_retention_EEG = parallel.ParallelPort(address='0x0378')
  160. fixCross_1s = visual.ImageStim(
  161. win=win,
  162. name='fixCross_1s',
  163. image='num/FixCross.png', mask=None,
  164. ori=0, pos=(0, 0), size=None,
  165. color=[1,1,1], colorSpace='rgb', opacity=1,
  166. flipHoriz=False, flipVert=False,
  167. texRes=128, interpolate=True, depth=-2.0)
  168. # Initialize components for Routine "repeat"
  169. repeatClock = core.Clock()
  170. trigger_mic_EEG = parallel.ParallelPort(address='0x0378')
  171. mic_image = visual.ImageStim(
  172. win=win,
  173. name='mic_image',
  174. image='num/mic_white.png', mask=None,
  175. ori=0, pos=(0, 0), size=(0.67, 0.36),
  176. color=[1,1,1], colorSpace='rgb', opacity=1,
  177. flipHoriz=False, flipVert=False,
  178. texRes=128, interpolate=True, depth=-4.0)
  179. # Initialize components for Routine "end_block"
  180. end_blockClock = core.Clock()
  181. trigger_endBlock_EEG = parallel.ParallelPort(address='0x0378')
  182. end = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  183. name='end')
  184. end.setVolume(1)
  185. FixCross_end = visual.ImageStim(
  186. win=win,
  187. name='FixCross_end',
  188. image='num/FixCross.png', mask=None,
  189. ori=0, pos=(0, 0), size=None,
  190. color=[1,1,1], colorSpace='rgb', opacity=0,
  191. flipHoriz=False, flipVert=False,
  192. texRes=128, interpolate=True, depth=-3.0)
  193. # Initialize components for Routine "rest"
  194. restClock = core.Clock()
  195. trigger_rest_EEG = parallel.ParallelPort(address='0x0378')
  196. rest_instruction = visual.TextStim(win=win, name='rest_instruction',
  197. text='default text',
  198. font='Arial',
  199. pos=(0, 0), height=0.056, wrapWidth=None, ori=0,
  200. color='white', colorSpace='rgb', opacity=1,
  201. languageStyle='LTR',
  202. depth=-2.0);
  203. key_resp_2 = keyboard.Keyboard()
  204. # Create some handy timers
  205. globalClock = core.Clock() # to track the time since experiment started
  206. routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
  207. # set up handler to look after randomisation of conditions etc
  208. trialSet_9 = data.TrialHandler(nReps=1, method='sequential',
  209. extraInfo=expInfo, originPath=-1,
  210. trialList=data.importConditions('rest_inst.xlsx'),
  211. seed=None, name='trialSet_9')
  212. thisExp.addLoop(trialSet_9) # add the loop to the experiment
  213. thisTrialSet_9 = trialSet_9.trialList[0] # so we can initialise stimuli with some values
  214. # abbreviate parameter names if possible (e.g. rgb = thisTrialSet_9.rgb)
  215. if thisTrialSet_9 != None:
  216. for paramName in thisTrialSet_9:
  217. exec('{} = thisTrialSet_9[paramName]'.format(paramName))
  218. for thisTrialSet_9 in trialSet_9:
  219. currentLoop = trialSet_9
  220. # abbreviate parameter names if possible (e.g. rgb = thisTrialSet_9.rgb)
  221. if thisTrialSet_9 != None:
  222. for paramName in thisTrialSet_9:
  223. exec('{} = thisTrialSet_9[paramName]'.format(paramName))
  224. # ------Prepare to start Routine "Randomizer"-------
  225. continueRoutine = True
  226. # update component parameters for each repeat
  227. # 3 listen + 12 remember + 3 listen trials per block
  228. l1 = choice([0,1,2],3,replace=False)
  229. r = choice(arange(3,15),12,replace=False)
  230. l2 = choice([15,16,17],3,replace=False)
  231. trialsOrder = concatenate([l1,r,l2])
  232. # keep track of which components have finished
  233. RandomizerComponents = []
  234. for thisComponent in RandomizerComponents:
  235. thisComponent.tStart = None
  236. thisComponent.tStop = None
  237. thisComponent.tStartRefresh = None
  238. thisComponent.tStopRefresh = None
  239. if hasattr(thisComponent, 'status'):
  240. thisComponent.status = NOT_STARTED
  241. # reset timers
  242. t = 0
  243. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  244. RandomizerClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  245. frameN = -1
  246. # -------Run Routine "Randomizer"-------
  247. while continueRoutine:
  248. # get current time
  249. t = RandomizerClock.getTime()
  250. tThisFlip = win.getFutureFlipTime(clock=RandomizerClock)
  251. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  252. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  253. # update/draw components on each frame
  254. # check for quit (typically the Esc key)
  255. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  256. core.quit()
  257. # check if all components have finished
  258. if not continueRoutine: # a component has requested a forced-end of Routine
  259. break
  260. continueRoutine = False # will revert to True if at least one component still running
  261. for thisComponent in RandomizerComponents:
  262. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  263. continueRoutine = True
  264. break # at least one component has not yet finished
  265. # refresh the screen
  266. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  267. win.flip()
  268. # -------Ending Routine "Randomizer"-------
  269. for thisComponent in RandomizerComponents:
  270. if hasattr(thisComponent, "setAutoDraw"):
  271. thisComponent.setAutoDraw(False)
  272. # the Routine "Randomizer" was not non-slip safe, so reset the non-slip timer
  273. routineTimer.reset()
  274. # set up handler to look after randomisation of conditions etc
  275. trials = data.TrialHandler(nReps=1, method='sequential',
  276. extraInfo=expInfo, originPath=-1,
  277. trialList=data.importConditions('repNums_'+str(int(expInfo['participant'])%2)+'.xlsx', selection=trialsOrder),
  278. seed=None, name='trials')
  279. thisExp.addLoop(trials) # add the loop to the experiment
  280. thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
  281. # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
  282. if thisTrial != None:
  283. for paramName in thisTrial:
  284. exec('{} = thisTrial[paramName]'.format(paramName))
  285. for thisTrial in trials:
  286. currentLoop = trials
  287. # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
  288. if thisTrial != None:
  289. for paramName in thisTrial:
  290. exec('{} = thisTrial[paramName]'.format(paramName))
  291. # ------Prepare to start Routine "instruction"-------
  292. continueRoutine = True
  293. # update component parameters for each repeat
  294. ## ET trigger ##
  295. # listen or remember trials
  296. socket.annotation(str(trialType_trCode), 0)
  297. ## info about current trial
  298. print('\nSet number: {}/9\nBlock number: {}/162\nLength of the string: {}\nTrial type: {}'.format(setN, blockN, numOfReps, trialType))
  299. blockN=blockN+1
  300. instruction_text.setColor(instrCol, colorSpace='rgb')
  301. instruction_text.setText(inst)
  302. start_sound.setSound('num/start.wav', hamming=True)
  303. start_sound.setVolume(1, log=False)
  304. # keep track of which components have finished
  305. instructionComponents = [trigger_instr_EEG, instruction_text, start_sound, exclamationMark]
  306. for thisComponent in instructionComponents:
  307. thisComponent.tStart = None
  308. thisComponent.tStop = None
  309. thisComponent.tStartRefresh = None
  310. thisComponent.tStopRefresh = None
  311. if hasattr(thisComponent, 'status'):
  312. thisComponent.status = NOT_STARTED
  313. # reset timers
  314. t = 0
  315. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  316. instructionClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  317. frameN = -1
  318. # -------Run Routine "instruction"-------
  319. while continueRoutine:
  320. # get current time
  321. t = instructionClock.getTime()
  322. tThisFlip = win.getFutureFlipTime(clock=instructionClock)
  323. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  324. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  325. # update/draw components on each frame
  326. # *trigger_instr_EEG* updates
  327. if trigger_instr_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  328. # keep track of start time/frame for later
  329. trigger_instr_EEG.frameNStart = frameN # exact frame index
  330. trigger_instr_EEG.tStart = t # local t and not account for scr refresh
  331. trigger_instr_EEG.tStartRefresh = tThisFlipGlobal # on global time
  332. win.timeOnFlip(trigger_instr_EEG, 'tStartRefresh') # time at next scr refresh
  333. trigger_instr_EEG.status = STARTED
  334. trigger_instr_EEG.setData(int(trialType_trCode))
  335. if trigger_instr_EEG.status == STARTED:
  336. # is it time to stop? (based on global clock, using actual start)
  337. if tThisFlipGlobal > trigger_instr_EEG.tStartRefresh + 0.02-frameTolerance:
  338. # keep track of stop time/frame for later
  339. trigger_instr_EEG.tStop = t # not accounting for scr refresh
  340. trigger_instr_EEG.frameNStop = frameN # exact frame index
  341. win.timeOnFlip(trigger_instr_EEG, 'tStopRefresh') # time at next scr refresh
  342. trigger_instr_EEG.status = FINISHED
  343. trigger_instr_EEG.setData(int(0))
  344. # *instruction_text* updates
  345. if instruction_text.status == NOT_STARTED and tThisFlip >= 0.5-frameTolerance:
  346. # keep track of start time/frame for later
  347. instruction_text.frameNStart = frameN # exact frame index
  348. instruction_text.tStart = t # local t and not account for scr refresh
  349. instruction_text.tStartRefresh = tThisFlipGlobal # on global time
  350. win.timeOnFlip(instruction_text, 'tStartRefresh') # time at next scr refresh
  351. instruction_text.setAutoDraw(True)
  352. if instruction_text.status == STARTED:
  353. # is it time to stop? (based on global clock, using actual start)
  354. if tThisFlipGlobal > instruction_text.tStartRefresh + 1-frameTolerance:
  355. # keep track of stop time/frame for later
  356. instruction_text.tStop = t # not accounting for scr refresh
  357. instruction_text.frameNStop = frameN # exact frame index
  358. win.timeOnFlip(instruction_text, 'tStopRefresh') # time at next scr refresh
  359. instruction_text.setAutoDraw(False)
  360. # start/stop start_sound
  361. if start_sound.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  362. # keep track of start time/frame for later
  363. start_sound.frameNStart = frameN # exact frame index
  364. start_sound.tStart = t # local t and not account for scr refresh
  365. start_sound.tStartRefresh = tThisFlipGlobal # on global time
  366. start_sound.play(when=win) # sync with win flip
  367. # *exclamationMark* updates
  368. if exclamationMark.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  369. # keep track of start time/frame for later
  370. exclamationMark.frameNStart = frameN # exact frame index
  371. exclamationMark.tStart = t # local t and not account for scr refresh
  372. exclamationMark.tStartRefresh = tThisFlipGlobal # on global time
  373. win.timeOnFlip(exclamationMark, 'tStartRefresh') # time at next scr refresh
  374. exclamationMark.setAutoDraw(True)
  375. if exclamationMark.status == STARTED:
  376. # is it time to stop? (based on global clock, using actual start)
  377. if tThisFlipGlobal > exclamationMark.tStartRefresh + 0.5-frameTolerance:
  378. # keep track of stop time/frame for later
  379. exclamationMark.tStop = t # not accounting for scr refresh
  380. exclamationMark.frameNStop = frameN # exact frame index
  381. win.timeOnFlip(exclamationMark, 'tStopRefresh') # time at next scr refresh
  382. exclamationMark.setAutoDraw(False)
  383. # check for quit (typically the Esc key)
  384. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  385. core.quit()
  386. # check if all components have finished
  387. if not continueRoutine: # a component has requested a forced-end of Routine
  388. break
  389. continueRoutine = False # will revert to True if at least one component still running
  390. for thisComponent in instructionComponents:
  391. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  392. continueRoutine = True
  393. break # at least one component has not yet finished
  394. # refresh the screen
  395. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  396. win.flip()
  397. # -------Ending Routine "instruction"-------
  398. for thisComponent in instructionComponents:
  399. if hasattr(thisComponent, "setAutoDraw"):
  400. thisComponent.setAutoDraw(False)
  401. if trigger_instr_EEG.status == STARTED:
  402. trigger_instr_EEG.setData(int(0))
  403. trials.addData('trigger_instr_EEG.started', trigger_instr_EEG.tStart)
  404. trials.addData('trigger_instr_EEG.stopped', trigger_instr_EEG.tStop)
  405. trials.addData('instruction_text.started', instruction_text.tStartRefresh)
  406. trials.addData('instruction_text.stopped', instruction_text.tStopRefresh)
  407. start_sound.stop() # ensure sound has stopped at end of routine
  408. trials.addData('start_sound.started', start_sound.tStartRefresh)
  409. trials.addData('start_sound.stopped', start_sound.tStopRefresh)
  410. trials.addData('exclamationMark.started', exclamationMark.tStartRefresh)
  411. trials.addData('exclamationMark.stopped', exclamationMark.tStopRefresh)
  412. # the Routine "instruction" was not non-slip safe, so reset the non-slip timer
  413. routineTimer.reset()
  414. # ------Prepare to start Routine "baseline_3s"-------
  415. continueRoutine = True
  416. routineTimer.add(3.000000)
  417. # update component parameters for each repeat
  418. # 105,109,113 - remember 5,9,13 digits
  419. socket.annotation(str(100+numOfReps), 0)
  420. # EEG trigger
  421. eegTr = 100+numOfReps
  422. # keep track of which components have finished
  423. baseline_3sComponents = [trigger_baseline_EEG, fixCross]
  424. for thisComponent in baseline_3sComponents:
  425. thisComponent.tStart = None
  426. thisComponent.tStop = None
  427. thisComponent.tStartRefresh = None
  428. thisComponent.tStopRefresh = None
  429. if hasattr(thisComponent, 'status'):
  430. thisComponent.status = NOT_STARTED
  431. # reset timers
  432. t = 0
  433. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  434. baseline_3sClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  435. frameN = -1
  436. # -------Run Routine "baseline_3s"-------
  437. while continueRoutine and routineTimer.getTime() > 0:
  438. # get current time
  439. t = baseline_3sClock.getTime()
  440. tThisFlip = win.getFutureFlipTime(clock=baseline_3sClock)
  441. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  442. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  443. # update/draw components on each frame
  444. # *trigger_baseline_EEG* updates
  445. if trigger_baseline_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  446. # keep track of start time/frame for later
  447. trigger_baseline_EEG.frameNStart = frameN # exact frame index
  448. trigger_baseline_EEG.tStart = t # local t and not account for scr refresh
  449. trigger_baseline_EEG.tStartRefresh = tThisFlipGlobal # on global time
  450. win.timeOnFlip(trigger_baseline_EEG, 'tStartRefresh') # time at next scr refresh
  451. trigger_baseline_EEG.status = STARTED
  452. trigger_baseline_EEG.setData(int(eegTr))
  453. if trigger_baseline_EEG.status == STARTED:
  454. # is it time to stop? (based on global clock, using actual start)
  455. if tThisFlipGlobal > trigger_baseline_EEG.tStartRefresh + 0.02-frameTolerance:
  456. # keep track of stop time/frame for later
  457. trigger_baseline_EEG.tStop = t # not accounting for scr refresh
  458. trigger_baseline_EEG.frameNStop = frameN # exact frame index
  459. win.timeOnFlip(trigger_baseline_EEG, 'tStopRefresh') # time at next scr refresh
  460. trigger_baseline_EEG.status = FINISHED
  461. trigger_baseline_EEG.setData(int(0))
  462. # *fixCross* updates
  463. if fixCross.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  464. # keep track of start time/frame for later
  465. fixCross.frameNStart = frameN # exact frame index
  466. fixCross.tStart = t # local t and not account for scr refresh
  467. fixCross.tStartRefresh = tThisFlipGlobal # on global time
  468. win.timeOnFlip(fixCross, 'tStartRefresh') # time at next scr refresh
  469. fixCross.setAutoDraw(True)
  470. if fixCross.status == STARTED:
  471. # is it time to stop? (based on global clock, using actual start)
  472. if tThisFlipGlobal > fixCross.tStartRefresh + 3.0-frameTolerance:
  473. # keep track of stop time/frame for later
  474. fixCross.tStop = t # not accounting for scr refresh
  475. fixCross.frameNStop = frameN # exact frame index
  476. win.timeOnFlip(fixCross, 'tStopRefresh') # time at next scr refresh
  477. fixCross.setAutoDraw(False)
  478. # check for quit (typically the Esc key)
  479. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  480. core.quit()
  481. # check if all components have finished
  482. if not continueRoutine: # a component has requested a forced-end of Routine
  483. break
  484. continueRoutine = False # will revert to True if at least one component still running
  485. for thisComponent in baseline_3sComponents:
  486. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  487. continueRoutine = True
  488. break # at least one component has not yet finished
  489. # refresh the screen
  490. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  491. win.flip()
  492. # -------Ending Routine "baseline_3s"-------
  493. for thisComponent in baseline_3sComponents:
  494. if hasattr(thisComponent, "setAutoDraw"):
  495. thisComponent.setAutoDraw(False)
  496. if trigger_baseline_EEG.status == STARTED:
  497. trigger_baseline_EEG.setData(int(0))
  498. trials.addData('trigger_baseline_EEG.started', trigger_baseline_EEG.tStart)
  499. trials.addData('trigger_baseline_EEG.stopped', trigger_baseline_EEG.tStop)
  500. trials.addData('fixCross.started', fixCross.tStartRefresh)
  501. trials.addData('fixCross.stopped', fixCross.tStopRefresh)
  502. # set up handler to look after randomisation of conditions etc
  503. present_sounds = data.TrialHandler(nReps=1, method='sequential',
  504. extraInfo=expInfo, originPath=-1,
  505. trialList=data.importConditions('sounds.xlsx', selection=randomDigits(numOfReps)),
  506. seed=None, name='present_sounds')
  507. thisExp.addLoop(present_sounds) # add the loop to the experiment
  508. thisPresent_sound = present_sounds.trialList[0] # so we can initialise stimuli with some values
  509. # abbreviate parameter names if possible (e.g. rgb = thisPresent_sound.rgb)
  510. if thisPresent_sound != None:
  511. for paramName in thisPresent_sound:
  512. exec('{} = thisPresent_sound[paramName]'.format(paramName))
  513. for thisPresent_sound in present_sounds:
  514. currentLoop = present_sounds
  515. # abbreviate parameter names if possible (e.g. rgb = thisPresent_sound.rgb)
  516. if thisPresent_sound != None:
  517. for paramName in thisPresent_sound:
  518. exec('{} = thisPresent_sound[paramName]'.format(paramName))
  519. # ------Prepare to start Routine "digits"-------
  520. continueRoutine = True
  521. # update component parameters for each repeat
  522. digit = int(sounds[4:][:-4])
  523. socket.annotation(digit, 0)
  524. sound_digit.setSound(sounds, hamming=True)
  525. sound_digit.setVolume(1, log=False)
  526. # keep track of which components have finished
  527. digitsComponents = [trigger_digits_EEG, sound_digit, FixCross_answ]
  528. for thisComponent in digitsComponents:
  529. thisComponent.tStart = None
  530. thisComponent.tStop = None
  531. thisComponent.tStartRefresh = None
  532. thisComponent.tStopRefresh = None
  533. if hasattr(thisComponent, 'status'):
  534. thisComponent.status = NOT_STARTED
  535. # reset timers
  536. t = 0
  537. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  538. digitsClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  539. frameN = -1
  540. # -------Run Routine "digits"-------
  541. while continueRoutine:
  542. # get current time
  543. t = digitsClock.getTime()
  544. tThisFlip = win.getFutureFlipTime(clock=digitsClock)
  545. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  546. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  547. # update/draw components on each frame
  548. # *trigger_digits_EEG* updates
  549. if trigger_digits_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  550. # keep track of start time/frame for later
  551. trigger_digits_EEG.frameNStart = frameN # exact frame index
  552. trigger_digits_EEG.tStart = t # local t and not account for scr refresh
  553. trigger_digits_EEG.tStartRefresh = tThisFlipGlobal # on global time
  554. win.timeOnFlip(trigger_digits_EEG, 'tStartRefresh') # time at next scr refresh
  555. trigger_digits_EEG.status = STARTED
  556. trigger_digits_EEG.setData(int(digit))
  557. if trigger_digits_EEG.status == STARTED:
  558. # is it time to stop? (based on global clock, using actual start)
  559. if tThisFlipGlobal > trigger_digits_EEG.tStartRefresh + 0.02-frameTolerance:
  560. # keep track of stop time/frame for later
  561. trigger_digits_EEG.tStop = t # not accounting for scr refresh
  562. trigger_digits_EEG.frameNStop = frameN # exact frame index
  563. win.timeOnFlip(trigger_digits_EEG, 'tStopRefresh') # time at next scr refresh
  564. trigger_digits_EEG.status = FINISHED
  565. trigger_digits_EEG.setData(int(0))
  566. # start/stop sound_digit
  567. if sound_digit.status == NOT_STARTED and t >= 0.0-frameTolerance:
  568. # keep track of start time/frame for later
  569. sound_digit.frameNStart = frameN # exact frame index
  570. sound_digit.tStart = t # local t and not account for scr refresh
  571. sound_digit.tStartRefresh = tThisFlipGlobal # on global time
  572. sound_digit.play() # start the sound (it finishes automatically)
  573. # *FixCross_answ* updates
  574. if FixCross_answ.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  575. # keep track of start time/frame for later
  576. FixCross_answ.frameNStart = frameN # exact frame index
  577. FixCross_answ.tStart = t # local t and not account for scr refresh
  578. FixCross_answ.tStartRefresh = tThisFlipGlobal # on global time
  579. win.timeOnFlip(FixCross_answ, 'tStartRefresh') # time at next scr refresh
  580. FixCross_answ.setAutoDraw(True)
  581. if FixCross_answ.status == STARTED:
  582. # is it time to stop? (based on global clock, using actual start)
  583. if tThisFlipGlobal > FixCross_answ.tStartRefresh + 2.0-frameTolerance:
  584. # keep track of stop time/frame for later
  585. FixCross_answ.tStop = t # not accounting for scr refresh
  586. FixCross_answ.frameNStop = frameN # exact frame index
  587. win.timeOnFlip(FixCross_answ, 'tStopRefresh') # time at next scr refresh
  588. FixCross_answ.setAutoDraw(False)
  589. # check for quit (typically the Esc key)
  590. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  591. core.quit()
  592. # check if all components have finished
  593. if not continueRoutine: # a component has requested a forced-end of Routine
  594. break
  595. continueRoutine = False # will revert to True if at least one component still running
  596. for thisComponent in digitsComponents:
  597. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  598. continueRoutine = True
  599. break # at least one component has not yet finished
  600. # refresh the screen
  601. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  602. win.flip()
  603. # -------Ending Routine "digits"-------
  604. for thisComponent in digitsComponents:
  605. if hasattr(thisComponent, "setAutoDraw"):
  606. thisComponent.setAutoDraw(False)
  607. if trigger_digits_EEG.status == STARTED:
  608. trigger_digits_EEG.setData(int(0))
  609. present_sounds.addData('trigger_digits_EEG.started', trigger_digits_EEG.tStart)
  610. present_sounds.addData('trigger_digits_EEG.stopped', trigger_digits_EEG.tStop)
  611. sound_digit.stop() # ensure sound has stopped at end of routine
  612. present_sounds.addData('sound_digit.started', sound_digit.tStart)
  613. present_sounds.addData('sound_digit.stopped', sound_digit.tStop)
  614. present_sounds.addData('FixCross_answ.started', FixCross_answ.tStartRefresh)
  615. present_sounds.addData('FixCross_answ.stopped', FixCross_answ.tStopRefresh)
  616. # the Routine "digits" was not non-slip safe, so reset the non-slip timer
  617. routineTimer.reset()
  618. thisExp.nextEntry()
  619. # completed 1 repeats of 'present_sounds'
  620. # ------Prepare to start Routine "retention_1s"-------
  621. continueRoutine = True
  622. routineTimer.add(1.000000)
  623. # update component parameters for each repeat
  624. socket.annotation(171, 0)
  625. # keep track of which components have finished
  626. retention_1sComponents = [trigger_retention_EEG, fixCross_1s]
  627. for thisComponent in retention_1sComponents:
  628. thisComponent.tStart = None
  629. thisComponent.tStop = None
  630. thisComponent.tStartRefresh = None
  631. thisComponent.tStopRefresh = None
  632. if hasattr(thisComponent, 'status'):
  633. thisComponent.status = NOT_STARTED
  634. # reset timers
  635. t = 0
  636. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  637. retention_1sClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  638. frameN = -1
  639. # -------Run Routine "retention_1s"-------
  640. while continueRoutine and routineTimer.getTime() > 0:
  641. # get current time
  642. t = retention_1sClock.getTime()
  643. tThisFlip = win.getFutureFlipTime(clock=retention_1sClock)
  644. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  645. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  646. # update/draw components on each frame
  647. # *trigger_retention_EEG* updates
  648. if trigger_retention_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  649. # keep track of start time/frame for later
  650. trigger_retention_EEG.frameNStart = frameN # exact frame index
  651. trigger_retention_EEG.tStart = t # local t and not account for scr refresh
  652. trigger_retention_EEG.tStartRefresh = tThisFlipGlobal # on global time
  653. win.timeOnFlip(trigger_retention_EEG, 'tStartRefresh') # time at next scr refresh
  654. trigger_retention_EEG.status = STARTED
  655. trigger_retention_EEG.setData(int(171))
  656. if trigger_retention_EEG.status == STARTED:
  657. # is it time to stop? (based on global clock, using actual start)
  658. if tThisFlipGlobal > trigger_retention_EEG.tStartRefresh + 0.02-frameTolerance:
  659. # keep track of stop time/frame for later
  660. trigger_retention_EEG.tStop = t # not accounting for scr refresh
  661. trigger_retention_EEG.frameNStop = frameN # exact frame index
  662. win.timeOnFlip(trigger_retention_EEG, 'tStopRefresh') # time at next scr refresh
  663. trigger_retention_EEG.status = FINISHED
  664. trigger_retention_EEG.setData(int(0))
  665. # *fixCross_1s* updates
  666. if fixCross_1s.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  667. # keep track of start time/frame for later
  668. fixCross_1s.frameNStart = frameN # exact frame index
  669. fixCross_1s.tStart = t # local t and not account for scr refresh
  670. fixCross_1s.tStartRefresh = tThisFlipGlobal # on global time
  671. win.timeOnFlip(fixCross_1s, 'tStartRefresh') # time at next scr refresh
  672. fixCross_1s.setAutoDraw(True)
  673. if fixCross_1s.status == STARTED:
  674. # is it time to stop? (based on global clock, using actual start)
  675. if tThisFlipGlobal > fixCross_1s.tStartRefresh + 1.0-frameTolerance:
  676. # keep track of stop time/frame for later
  677. fixCross_1s.tStop = t # not accounting for scr refresh
  678. fixCross_1s.frameNStop = frameN # exact frame index
  679. win.timeOnFlip(fixCross_1s, 'tStopRefresh') # time at next scr refresh
  680. fixCross_1s.setAutoDraw(False)
  681. # check for quit (typically the Esc key)
  682. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  683. core.quit()
  684. # check if all components have finished
  685. if not continueRoutine: # a component has requested a forced-end of Routine
  686. break
  687. continueRoutine = False # will revert to True if at least one component still running
  688. for thisComponent in retention_1sComponents:
  689. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  690. continueRoutine = True
  691. break # at least one component has not yet finished
  692. # refresh the screen
  693. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  694. win.flip()
  695. # -------Ending Routine "retention_1s"-------
  696. for thisComponent in retention_1sComponents:
  697. if hasattr(thisComponent, "setAutoDraw"):
  698. thisComponent.setAutoDraw(False)
  699. if trigger_retention_EEG.status == STARTED:
  700. trigger_retention_EEG.setData(int(0))
  701. trials.addData('trigger_retention_EEG.started', trigger_retention_EEG.tStart)
  702. trials.addData('trigger_retention_EEG.stopped', trigger_retention_EEG.tStop)
  703. trials.addData('fixCross_1s.started', fixCross_1s.tStartRefresh)
  704. trials.addData('fixCross_1s.stopped', fixCross_1s.tStopRefresh)
  705. # ------Prepare to start Routine "repeat"-------
  706. continueRoutine = True
  707. # update component parameters for each repeat
  708. socket.annotation('180', 0)
  709. if skip_mic==1:
  710. continueRoutine = False
  711. mic_1 = microphone.AdvAudioCapture(name='mic_1', saveDir=wavDirName, stereo=False, chnl=0)
  712. # keep track of which components have finished
  713. repeatComponents = [trigger_mic_EEG, mic_1, mic_image]
  714. for thisComponent in repeatComponents:
  715. thisComponent.tStart = None
  716. thisComponent.tStop = None
  717. thisComponent.tStartRefresh = None
  718. thisComponent.tStopRefresh = None
  719. if hasattr(thisComponent, 'status'):
  720. thisComponent.status = NOT_STARTED
  721. # reset timers
  722. t = 0
  723. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  724. repeatClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  725. frameN = -1
  726. # -------Run Routine "repeat"-------
  727. while continueRoutine:
  728. # get current time
  729. t = repeatClock.getTime()
  730. tThisFlip = win.getFutureFlipTime(clock=repeatClock)
  731. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  732. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  733. # update/draw components on each frame
  734. # *trigger_mic_EEG* updates
  735. if trigger_mic_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  736. # keep track of start time/frame for later
  737. trigger_mic_EEG.frameNStart = frameN # exact frame index
  738. trigger_mic_EEG.tStart = t # local t and not account for scr refresh
  739. trigger_mic_EEG.tStartRefresh = tThisFlipGlobal # on global time
  740. win.timeOnFlip(trigger_mic_EEG, 'tStartRefresh') # time at next scr refresh
  741. trigger_mic_EEG.status = STARTED
  742. trigger_mic_EEG.setData(int(180))
  743. if trigger_mic_EEG.status == STARTED:
  744. # is it time to stop? (based on global clock, using actual start)
  745. if tThisFlipGlobal > trigger_mic_EEG.tStartRefresh + 0.02-frameTolerance:
  746. # keep track of stop time/frame for later
  747. trigger_mic_EEG.tStop = t # not accounting for scr refresh
  748. trigger_mic_EEG.frameNStop = frameN # exact frame index
  749. win.timeOnFlip(trigger_mic_EEG, 'tStopRefresh') # time at next scr refresh
  750. trigger_mic_EEG.status = FINISHED
  751. trigger_mic_EEG.setData(int(0))
  752. # *mic_1* updates
  753. if mic_1.status == NOT_STARTED and t >= 0-frameTolerance:
  754. # keep track of start time/frame for later
  755. mic_1.frameNStart = frameN # exact frame index
  756. mic_1.tStart = t # local t and not account for scr refresh
  757. mic_1.tStartRefresh = tThisFlipGlobal # on global time
  758. win.timeOnFlip(mic_1, 'tStartRefresh') # time at next scr refresh
  759. mic_1.status = STARTED
  760. mic_1.record(sec=micDuration, block=False) # start the recording thread
  761. if mic_1.status == STARTED and not mic_1.recorder.running:
  762. mic_1.status = FINISHED
  763. # *mic_image* updates
  764. if mic_image.status == NOT_STARTED and tThisFlip >= 0-frameTolerance:
  765. # keep track of start time/frame for later
  766. mic_image.frameNStart = frameN # exact frame index
  767. mic_image.tStart = t # local t and not account for scr refresh
  768. mic_image.tStartRefresh = tThisFlipGlobal # on global time
  769. win.timeOnFlip(mic_image, 'tStartRefresh') # time at next scr refresh
  770. mic_image.setAutoDraw(True)
  771. if mic_image.status == STARTED:
  772. # is it time to stop? (based on global clock, using actual start)
  773. if tThisFlipGlobal > mic_image.tStartRefresh + micDuration-frameTolerance:
  774. # keep track of stop time/frame for later
  775. mic_image.tStop = t # not accounting for scr refresh
  776. mic_image.frameNStop = frameN # exact frame index
  777. win.timeOnFlip(mic_image, 'tStopRefresh') # time at next scr refresh
  778. mic_image.setAutoDraw(False)
  779. # check for quit (typically the Esc key)
  780. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  781. core.quit()
  782. # check if all components have finished
  783. if not continueRoutine: # a component has requested a forced-end of Routine
  784. break
  785. continueRoutine = False # will revert to True if at least one component still running
  786. for thisComponent in repeatComponents:
  787. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  788. continueRoutine = True
  789. break # at least one component has not yet finished
  790. # refresh the screen
  791. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  792. win.flip()
  793. # -------Ending Routine "repeat"-------
  794. for thisComponent in repeatComponents:
  795. if hasattr(thisComponent, "setAutoDraw"):
  796. thisComponent.setAutoDraw(False)
  797. if trigger_mic_EEG.status == STARTED:
  798. trigger_mic_EEG.setData(int(0))
  799. trials.addData('trigger_mic_EEG.started', trigger_mic_EEG.tStart)
  800. trials.addData('trigger_mic_EEG.stopped', trigger_mic_EEG.tStop)
  801. # mic_1 stop & responses
  802. mic_1.stop() # sometimes helpful
  803. if not mic_1.savedFile:
  804. mic_1.savedFile = None
  805. # store data for trials (TrialHandler)
  806. trials.addData('mic_1.filename', mic_1.savedFile)
  807. trials.addData('mic_1.started', mic_1.tStart)
  808. trials.addData('mic_1.stopped', mic_1.tStop)
  809. trials.addData('mic_image.started', mic_image.tStartRefresh)
  810. trials.addData('mic_image.stopped', mic_image.tStopRefresh)
  811. # the Routine "repeat" was not non-slip safe, so reset the non-slip timer
  812. routineTimer.reset()
  813. # ------Prepare to start Routine "end_block"-------
  814. continueRoutine = True
  815. # update component parameters for each repeat
  816. socket.annotation('190', 0)
  817. end.setSound('num/end_block.wav', hamming=True)
  818. end.setVolume(1, log=False)
  819. # keep track of which components have finished
  820. end_blockComponents = [trigger_endBlock_EEG, end, FixCross_end]
  821. for thisComponent in end_blockComponents:
  822. thisComponent.tStart = None
  823. thisComponent.tStop = None
  824. thisComponent.tStartRefresh = None
  825. thisComponent.tStopRefresh = None
  826. if hasattr(thisComponent, 'status'):
  827. thisComponent.status = NOT_STARTED
  828. # reset timers
  829. t = 0
  830. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  831. end_blockClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  832. frameN = -1
  833. # -------Run Routine "end_block"-------
  834. while continueRoutine:
  835. # get current time
  836. t = end_blockClock.getTime()
  837. tThisFlip = win.getFutureFlipTime(clock=end_blockClock)
  838. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  839. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  840. # update/draw components on each frame
  841. # *trigger_endBlock_EEG* updates
  842. if trigger_endBlock_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  843. # keep track of start time/frame for later
  844. trigger_endBlock_EEG.frameNStart = frameN # exact frame index
  845. trigger_endBlock_EEG.tStart = t # local t and not account for scr refresh
  846. trigger_endBlock_EEG.tStartRefresh = tThisFlipGlobal # on global time
  847. win.timeOnFlip(trigger_endBlock_EEG, 'tStartRefresh') # time at next scr refresh
  848. trigger_endBlock_EEG.status = STARTED
  849. trigger_endBlock_EEG.setData(int(190))
  850. if trigger_endBlock_EEG.status == STARTED:
  851. # is it time to stop? (based on global clock, using actual start)
  852. if tThisFlipGlobal > trigger_endBlock_EEG.tStartRefresh + 0.02-frameTolerance:
  853. # keep track of stop time/frame for later
  854. trigger_endBlock_EEG.tStop = t # not accounting for scr refresh
  855. trigger_endBlock_EEG.frameNStop = frameN # exact frame index
  856. win.timeOnFlip(trigger_endBlock_EEG, 'tStopRefresh') # time at next scr refresh
  857. trigger_endBlock_EEG.status = FINISHED
  858. trigger_endBlock_EEG.setData(int(0))
  859. # start/stop end
  860. if end.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  861. # keep track of start time/frame for later
  862. end.frameNStart = frameN # exact frame index
  863. end.tStart = t # local t and not account for scr refresh
  864. end.tStartRefresh = tThisFlipGlobal # on global time
  865. end.play(when=win) # sync with win flip
  866. # *FixCross_end* updates
  867. if FixCross_end.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  868. # keep track of start time/frame for later
  869. FixCross_end.frameNStart = frameN # exact frame index
  870. FixCross_end.tStart = t # local t and not account for scr refresh
  871. FixCross_end.tStartRefresh = tThisFlipGlobal # on global time
  872. win.timeOnFlip(FixCross_end, 'tStartRefresh') # time at next scr refresh
  873. FixCross_end.setAutoDraw(True)
  874. if FixCross_end.status == STARTED:
  875. # is it time to stop? (based on global clock, using actual start)
  876. if tThisFlipGlobal > FixCross_end.tStartRefresh + 5.0-frameTolerance:
  877. # keep track of stop time/frame for later
  878. FixCross_end.tStop = t # not accounting for scr refresh
  879. FixCross_end.frameNStop = frameN # exact frame index
  880. win.timeOnFlip(FixCross_end, 'tStopRefresh') # time at next scr refresh
  881. FixCross_end.setAutoDraw(False)
  882. # check for quit (typically the Esc key)
  883. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  884. core.quit()
  885. # check if all components have finished
  886. if not continueRoutine: # a component has requested a forced-end of Routine
  887. break
  888. continueRoutine = False # will revert to True if at least one component still running
  889. for thisComponent in end_blockComponents:
  890. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  891. continueRoutine = True
  892. break # at least one component has not yet finished
  893. # refresh the screen
  894. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  895. win.flip()
  896. # -------Ending Routine "end_block"-------
  897. for thisComponent in end_blockComponents:
  898. if hasattr(thisComponent, "setAutoDraw"):
  899. thisComponent.setAutoDraw(False)
  900. if trigger_endBlock_EEG.status == STARTED:
  901. trigger_endBlock_EEG.setData(int(0))
  902. trials.addData('trigger_endBlock_EEG.started', trigger_endBlock_EEG.tStart)
  903. trials.addData('trigger_endBlock_EEG.stopped', trigger_endBlock_EEG.tStop)
  904. end.stop() # ensure sound has stopped at end of routine
  905. trials.addData('end.started', end.tStartRefresh)
  906. trials.addData('end.stopped', end.tStopRefresh)
  907. trials.addData('FixCross_end.started', FixCross_end.tStartRefresh)
  908. trials.addData('FixCross_end.stopped', FixCross_end.tStopRefresh)
  909. # the Routine "end_block" was not non-slip safe, so reset the non-slip timer
  910. routineTimer.reset()
  911. thisExp.nextEntry()
  912. # completed 1 repeats of 'trials'
  913. # ------Prepare to start Routine "rest"-------
  914. continueRoutine = True
  915. # update component parameters for each repeat
  916. socket.annotation('100', 0)
  917. rest_instruction.setColor('white', colorSpace='rgb')
  918. rest_instruction.setText(rest_inst
  919. )
  920. key_resp_2.keys = []
  921. key_resp_2.rt = []
  922. _key_resp_2_allKeys = []
  923. if rest_cond == 1:
  924. print("COME IN")
  925. # keep track of which components have finished
  926. restComponents = [trigger_rest_EEG, rest_instruction, key_resp_2]
  927. for thisComponent in restComponents:
  928. thisComponent.tStart = None
  929. thisComponent.tStop = None
  930. thisComponent.tStartRefresh = None
  931. thisComponent.tStopRefresh = None
  932. if hasattr(thisComponent, 'status'):
  933. thisComponent.status = NOT_STARTED
  934. # reset timers
  935. t = 0
  936. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  937. restClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  938. frameN = -1
  939. # -------Run Routine "rest"-------
  940. while continueRoutine:
  941. # get current time
  942. t = restClock.getTime()
  943. tThisFlip = win.getFutureFlipTime(clock=restClock)
  944. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  945. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  946. # update/draw components on each frame
  947. # *trigger_rest_EEG* updates
  948. if trigger_rest_EEG.status == NOT_STARTED and t >= 0.0-frameTolerance:
  949. # keep track of start time/frame for later
  950. trigger_rest_EEG.frameNStart = frameN # exact frame index
  951. trigger_rest_EEG.tStart = t # local t and not account for scr refresh
  952. trigger_rest_EEG.tStartRefresh = tThisFlipGlobal # on global time
  953. win.timeOnFlip(trigger_rest_EEG, 'tStartRefresh') # time at next scr refresh
  954. trigger_rest_EEG.status = STARTED
  955. trigger_rest_EEG.setData(int(100))
  956. if trigger_rest_EEG.status == STARTED:
  957. # is it time to stop? (based on global clock, using actual start)
  958. if tThisFlipGlobal > trigger_rest_EEG.tStartRefresh + 0.02-frameTolerance:
  959. # keep track of stop time/frame for later
  960. trigger_rest_EEG.tStop = t # not accounting for scr refresh
  961. trigger_rest_EEG.frameNStop = frameN # exact frame index
  962. win.timeOnFlip(trigger_rest_EEG, 'tStopRefresh') # time at next scr refresh
  963. trigger_rest_EEG.status = FINISHED
  964. trigger_rest_EEG.setData(int(0))
  965. # *rest_instruction* updates
  966. if rest_instruction.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  967. # keep track of start time/frame for later
  968. rest_instruction.frameNStart = frameN # exact frame index
  969. rest_instruction.tStart = t # local t and not account for scr refresh
  970. rest_instruction.tStartRefresh = tThisFlipGlobal # on global time
  971. win.timeOnFlip(rest_instruction, 'tStartRefresh') # time at next scr refresh
  972. rest_instruction.setAutoDraw(True)
  973. # *key_resp_2* updates
  974. waitOnFlip = False
  975. if key_resp_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  976. # keep track of start time/frame for later
  977. key_resp_2.frameNStart = frameN # exact frame index
  978. key_resp_2.tStart = t # local t and not account for scr refresh
  979. key_resp_2.tStartRefresh = tThisFlipGlobal # on global time
  980. win.timeOnFlip(key_resp_2, 'tStartRefresh') # time at next scr refresh
  981. key_resp_2.status = STARTED
  982. # keyboard checking is just starting
  983. waitOnFlip = True
  984. win.callOnFlip(key_resp_2.clock.reset) # t=0 on next screen flip
  985. win.callOnFlip(key_resp_2.clearEvents, eventType='keyboard') # clear events on next screen flip
  986. if key_resp_2.status == STARTED and not waitOnFlip:
  987. theseKeys = key_resp_2.getKeys(keyList=['space'], waitRelease=False)
  988. _key_resp_2_allKeys.extend(theseKeys)
  989. if len(_key_resp_2_allKeys):
  990. key_resp_2.keys = _key_resp_2_allKeys[-1].name # just the last key pressed
  991. key_resp_2.rt = _key_resp_2_allKeys[-1].rt
  992. # a response ends the routine
  993. continueRoutine = False
  994. # check for quit (typically the Esc key)
  995. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  996. core.quit()
  997. # check if all components have finished
  998. if not continueRoutine: # a component has requested a forced-end of Routine
  999. break
  1000. continueRoutine = False # will revert to True if at least one component still running
  1001. for thisComponent in restComponents:
  1002. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  1003. continueRoutine = True
  1004. break # at least one component has not yet finished
  1005. # refresh the screen
  1006. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  1007. win.flip()
  1008. # -------Ending Routine "rest"-------
  1009. for thisComponent in restComponents:
  1010. if hasattr(thisComponent, "setAutoDraw"):
  1011. thisComponent.setAutoDraw(False)
  1012. if trigger_rest_EEG.status == STARTED:
  1013. trigger_rest_EEG.setData(int(0))
  1014. trialSet_9.addData('trigger_rest_EEG.started', trigger_rest_EEG.tStart)
  1015. trialSet_9.addData('trigger_rest_EEG.stopped', trigger_rest_EEG.tStop)
  1016. trialSet_9.addData('rest_instruction.started', rest_instruction.tStartRefresh)
  1017. trialSet_9.addData('rest_instruction.stopped', rest_instruction.tStopRefresh)
  1018. # check responses
  1019. if key_resp_2.keys in ['', [], None]: # No response was made
  1020. key_resp_2.keys = None
  1021. trialSet_9.addData('key_resp_2.keys',key_resp_2.keys)
  1022. if key_resp_2.keys != None: # we had a response
  1023. trialSet_9.addData('key_resp_2.rt', key_resp_2.rt)
  1024. trialSet_9.addData('key_resp_2.started', key_resp_2.tStartRefresh)
  1025. trialSet_9.addData('key_resp_2.stopped', key_resp_2.tStopRefresh)
  1026. # the Routine "rest" was not non-slip safe, so reset the non-slip timer
  1027. routineTimer.reset()
  1028. thisExp.nextEntry()
  1029. # completed 1 repeats of 'trialSet_9'
  1030. thisExp.addData("globalClockTime", globalClock.getTime())
  1031. thisExp.nextEntry()
  1032. socket.stop_recording()
  1033. print('Script completed.')
  1034. # Flip one final time so any remaining win.callOnFlip()
  1035. # and win.timeOnFlip() tasks get executed before quitting
  1036. win.flip()
  1037. # these shouldn't be strictly necessary (should auto-save)
  1038. thisExp.saveAsWideText(filename+'.csv')
  1039. thisExp.saveAsPickle(filename)
  1040. logging.flush()
  1041. # make sure everything is closed down
  1042. thisExp.abort() # or data files will save again on exit
  1043. win.close()
  1044. core.quit()