peavler_training_lastrun.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This experiment was created using PsychoPy3 Experiment Builder (v2020.1.3),
  5. on Сентябрь 21, 2020, at 16:47
  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. from psychopy import locale_setup
  13. from psychopy import prefs
  14. prefs.hardware['audioLib'] = 'pyo'
  15. prefs.hardware['audioLatencyMode'] = '3'
  16. from psychopy import sound, gui, visual, core, data, event, logging, clock, microphone
  17. from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
  18. STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
  19. import numpy as np # whole numpy lib is available, prepend 'np.'
  20. from numpy import (sin, cos, tan, log, log10, pi, average,
  21. sqrt, std, deg2rad, rad2deg, linspace, asarray)
  22. from numpy.random import random, randint, normal, shuffle
  23. import os # handy system and path functions
  24. import sys # to get file system encoding
  25. from psychopy.hardware import keyboard
  26. # Ensure that relative paths start from the same directory as this script
  27. _thisDir = os.path.dirname(os.path.abspath(__file__))
  28. os.chdir(_thisDir)
  29. # Store info about the experiment session
  30. psychopyVersion = '2020.1.3'
  31. expName = 'peavler_training' # from the Builder filename that created this script
  32. expInfo = {'participant': '', 'session': 'training'}
  33. dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
  34. if dlg.OK == False:
  35. core.quit() # user pressed cancel
  36. expInfo['date'] = data.getDateStr() # add a simple timestamp
  37. expInfo['expName'] = expName
  38. expInfo['psychopyVersion'] = psychopyVersion
  39. # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
  40. filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
  41. # An ExperimentHandler isn't essential but helps with data saving
  42. thisExp = data.ExperimentHandler(name=expName, version='',
  43. extraInfo=expInfo, runtimeInfo=None,
  44. originPath='D:\\GoogleDisk\\Neurotech_lab\\cogLoad_project\\scripts\\peavlerRepl\\v15\\peavler_training_lastrun.py',
  45. savePickle=True, saveWideText=True,
  46. dataFileName=filename)
  47. # save a log file for detail verbose info
  48. logFile = logging.LogFile(filename+'.log', level=logging.EXP)
  49. logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
  50. endExpNow = False # flag for 'escape' or other condition => quit the exp
  51. frameTolerance = 0.001 # how close to onset before 'same' frame
  52. # Start Code - component code to be run before the window creation
  53. wavDirName = filename + '_wav'
  54. if not os.path.isdir(wavDirName):
  55. os.makedirs(wavDirName) # to hold .wav files
  56. # Setup the Window
  57. win = visual.Window(
  58. size=[1920, 1080], fullscr=True, screen=0,
  59. winType='pyglet', allowGUI=False, allowStencil=False,
  60. monitor='testMonitor', color=[0, 0, 0], colorSpace='rgb',
  61. blendMode='avg', useFBO=True,
  62. units='height')
  63. # Enable sound input/output:
  64. microphone.switchOn()
  65. # store frame rate of monitor if we can measure it
  66. expInfo['frameRate'] = win.getActualFrameRate()
  67. if expInfo['frameRate'] != None:
  68. frameDur = 1.0 / round(expInfo['frameRate'])
  69. else:
  70. frameDur = 1.0 / 60.0 # could not measure, so guess
  71. # create a default keyboard (e.g. to check for escape)
  72. defaultKeyboard = keyboard.Keyboard()
  73. # Initialize components for Routine "randomizer"
  74. randomizerClock = core.Clock()
  75. from numpy.random import choice
  76. import random
  77. from numpy import arange, concatenate
  78. def randomDigits(numOfReps):
  79. if numOfReps<=10:
  80. return choice(10, size=numOfReps, replace=False)
  81. else:
  82. arr1 = list(choice(10, size=10, replace=False))
  83. arr2 = list(choice(10, size=numOfReps-10, replace=False))
  84. while arr2[0] == arr1[-1]:
  85. random.shuffle(arr2)
  86. return arr1+arr2
  87. # Initialize components for Routine "instruction"
  88. instructionClock = core.Clock()
  89. instruction_text = visual.TextStim(win=win, name='instruction_text',
  90. text='default text',
  91. font='Arial',
  92. pos=(0, 0), height=0.056, wrapWidth=None, ori=0,
  93. color='white', colorSpace='rgb', opacity=1,
  94. languageStyle='LTR',
  95. depth=0.0);
  96. start_sound = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  97. name='start_sound')
  98. start_sound.setVolume(1)
  99. exclamationMark = visual.TextStim(win=win, name='exclamationMark',
  100. text='!',
  101. font='Arial',
  102. pos=(0, 0), height=0.076, wrapWidth=None, ori=0,
  103. color=[1,1,1], colorSpace='rgb', opacity=1,
  104. languageStyle='LTR',
  105. depth=-2.0);
  106. # Initialize components for Routine "baseline_2s"
  107. baseline_2sClock = core.Clock()
  108. fixCross = visual.ImageStim(
  109. win=win,
  110. name='fixCross',
  111. image='num/FixCross.png', mask=None,
  112. ori=0, pos=(0, 0), size=None,
  113. color=[1,1,1], colorSpace='rgb', opacity=1,
  114. flipHoriz=False, flipVert=False,
  115. texRes=128, interpolate=True, depth=0.0)
  116. # Initialize components for Routine "digits"
  117. digitsClock = core.Clock()
  118. sound_digit = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  119. name='sound_digit')
  120. sound_digit.setVolume(1)
  121. FixCross_answ = visual.ImageStim(
  122. win=win,
  123. name='FixCross_answ',
  124. image='num/FixCross.png', mask=None,
  125. ori=0, pos=(0, 0), size=None,
  126. color=[1,1,1], colorSpace='rgb', opacity=1,
  127. flipHoriz=False, flipVert=False,
  128. texRes=128, interpolate=True, depth=-1.0)
  129. # Initialize components for Routine "retention_1s"
  130. retention_1sClock = core.Clock()
  131. fixCross_1s = visual.ImageStim(
  132. win=win,
  133. name='fixCross_1s',
  134. image='num/FixCross.png', mask=None,
  135. ori=0, pos=(0, 0), size=None,
  136. color=[1,1,1], colorSpace='rgb', opacity=1,
  137. flipHoriz=False, flipVert=False,
  138. texRes=128, interpolate=True, depth=0.0)
  139. # Initialize components for Routine "repeat"
  140. repeatClock = core.Clock()
  141. mic_image = visual.ImageStim(
  142. win=win,
  143. name='mic_image',
  144. image='num/mic_white.png', mask=None,
  145. ori=0, pos=(0, 0), size=(0.67, 0.36),
  146. color=[1,1,1], colorSpace='rgb', opacity=1,
  147. flipHoriz=False, flipVert=False,
  148. texRes=128, interpolate=True, depth=-2.0)
  149. # Initialize components for Routine "end_block"
  150. end_blockClock = core.Clock()
  151. end = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  152. name='end')
  153. end.setVolume(1)
  154. FixCross_end = visual.ImageStim(
  155. win=win,
  156. name='FixCross_end',
  157. image='num/FixCross.png', mask=None,
  158. ori=0, pos=(0, 0), size=None,
  159. color=[1,1,1], colorSpace='rgb', opacity=0,
  160. flipHoriz=False, flipVert=False,
  161. texRes=128, interpolate=True, depth=-1.0)
  162. # Initialize components for Routine "rest"
  163. restClock = core.Clock()
  164. rest_instruction = visual.TextStim(win=win, name='rest_instruction',
  165. text='default text',
  166. font='Arial',
  167. pos=(0, 0), height=0.056, wrapWidth=None, ori=0,
  168. color='white', colorSpace='rgb', opacity=1,
  169. languageStyle='LTR',
  170. depth=0.0);
  171. key_resp_2 = keyboard.Keyboard()
  172. # Create some handy timers
  173. globalClock = core.Clock() # to track the time since experiment started
  174. routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
  175. # ------Prepare to start Routine "randomizer"-------
  176. continueRoutine = True
  177. # update component parameters for each repeat
  178. # keep track of which components have finished
  179. randomizerComponents = []
  180. for thisComponent in randomizerComponents:
  181. thisComponent.tStart = None
  182. thisComponent.tStop = None
  183. thisComponent.tStartRefresh = None
  184. thisComponent.tStopRefresh = None
  185. if hasattr(thisComponent, 'status'):
  186. thisComponent.status = NOT_STARTED
  187. # reset timers
  188. t = 0
  189. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  190. randomizerClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  191. frameN = -1
  192. # -------Run Routine "randomizer"-------
  193. while continueRoutine:
  194. # get current time
  195. t = randomizerClock.getTime()
  196. tThisFlip = win.getFutureFlipTime(clock=randomizerClock)
  197. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  198. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  199. # update/draw components on each frame
  200. # check for quit (typically the Esc key)
  201. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  202. core.quit()
  203. # check if all components have finished
  204. if not continueRoutine: # a component has requested a forced-end of Routine
  205. break
  206. continueRoutine = False # will revert to True if at least one component still running
  207. for thisComponent in randomizerComponents:
  208. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  209. continueRoutine = True
  210. break # at least one component has not yet finished
  211. # refresh the screen
  212. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  213. win.flip()
  214. # -------Ending Routine "randomizer"-------
  215. for thisComponent in randomizerComponents:
  216. if hasattr(thisComponent, "setAutoDraw"):
  217. thisComponent.setAutoDraw(False)
  218. # the Routine "randomizer" was not non-slip safe, so reset the non-slip timer
  219. routineTimer.reset()
  220. # set up handler to look after randomisation of conditions etc
  221. trials = data.TrialHandler(nReps=1, method='random',
  222. extraInfo=expInfo, originPath=-1,
  223. trialList=data.importConditions('trainingTrials_'+str(int(expInfo['participant'])%2)+'.xlsx'),
  224. seed=None, name='trials')
  225. thisExp.addLoop(trials) # add the loop to the experiment
  226. thisTrial = trials.trialList[0] # so we can initialise stimuli with some values
  227. # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
  228. if thisTrial != None:
  229. for paramName in thisTrial:
  230. exec('{} = thisTrial[paramName]'.format(paramName))
  231. for thisTrial in trials:
  232. currentLoop = trials
  233. # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
  234. if thisTrial != None:
  235. for paramName in thisTrial:
  236. exec('{} = thisTrial[paramName]'.format(paramName))
  237. # ------Prepare to start Routine "instruction"-------
  238. continueRoutine = True
  239. # update component parameters for each repeat
  240. instruction_text.setColor(instrCol, colorSpace='rgb')
  241. instruction_text.setText(inst)
  242. start_sound.setSound('num/start.wav', hamming=True)
  243. start_sound.setVolume(1, log=False)
  244. # keep track of which components have finished
  245. instructionComponents = [instruction_text, start_sound, exclamationMark]
  246. for thisComponent in instructionComponents:
  247. thisComponent.tStart = None
  248. thisComponent.tStop = None
  249. thisComponent.tStartRefresh = None
  250. thisComponent.tStopRefresh = None
  251. if hasattr(thisComponent, 'status'):
  252. thisComponent.status = NOT_STARTED
  253. # reset timers
  254. t = 0
  255. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  256. instructionClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  257. frameN = -1
  258. # -------Run Routine "instruction"-------
  259. while continueRoutine:
  260. # get current time
  261. t = instructionClock.getTime()
  262. tThisFlip = win.getFutureFlipTime(clock=instructionClock)
  263. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  264. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  265. # update/draw components on each frame
  266. # *instruction_text* updates
  267. if instruction_text.status == NOT_STARTED and tThisFlip >= 0.5-frameTolerance:
  268. # keep track of start time/frame for later
  269. instruction_text.frameNStart = frameN # exact frame index
  270. instruction_text.tStart = t # local t and not account for scr refresh
  271. instruction_text.tStartRefresh = tThisFlipGlobal # on global time
  272. win.timeOnFlip(instruction_text, 'tStartRefresh') # time at next scr refresh
  273. instruction_text.setAutoDraw(True)
  274. if instruction_text.status == STARTED:
  275. # is it time to stop? (based on global clock, using actual start)
  276. if tThisFlipGlobal > instruction_text.tStartRefresh + 1-frameTolerance:
  277. # keep track of stop time/frame for later
  278. instruction_text.tStop = t # not accounting for scr refresh
  279. instruction_text.frameNStop = frameN # exact frame index
  280. win.timeOnFlip(instruction_text, 'tStopRefresh') # time at next scr refresh
  281. instruction_text.setAutoDraw(False)
  282. # start/stop start_sound
  283. if start_sound.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  284. # keep track of start time/frame for later
  285. start_sound.frameNStart = frameN # exact frame index
  286. start_sound.tStart = t # local t and not account for scr refresh
  287. start_sound.tStartRefresh = tThisFlipGlobal # on global time
  288. start_sound.play(when=win) # sync with win flip
  289. # *exclamationMark* updates
  290. if exclamationMark.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  291. # keep track of start time/frame for later
  292. exclamationMark.frameNStart = frameN # exact frame index
  293. exclamationMark.tStart = t # local t and not account for scr refresh
  294. exclamationMark.tStartRefresh = tThisFlipGlobal # on global time
  295. win.timeOnFlip(exclamationMark, 'tStartRefresh') # time at next scr refresh
  296. exclamationMark.setAutoDraw(True)
  297. if exclamationMark.status == STARTED:
  298. # is it time to stop? (based on global clock, using actual start)
  299. if tThisFlipGlobal > exclamationMark.tStartRefresh + 0.5-frameTolerance:
  300. # keep track of stop time/frame for later
  301. exclamationMark.tStop = t # not accounting for scr refresh
  302. exclamationMark.frameNStop = frameN # exact frame index
  303. win.timeOnFlip(exclamationMark, 'tStopRefresh') # time at next scr refresh
  304. exclamationMark.setAutoDraw(False)
  305. # check for quit (typically the Esc key)
  306. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  307. core.quit()
  308. # check if all components have finished
  309. if not continueRoutine: # a component has requested a forced-end of Routine
  310. break
  311. continueRoutine = False # will revert to True if at least one component still running
  312. for thisComponent in instructionComponents:
  313. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  314. continueRoutine = True
  315. break # at least one component has not yet finished
  316. # refresh the screen
  317. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  318. win.flip()
  319. # -------Ending Routine "instruction"-------
  320. for thisComponent in instructionComponents:
  321. if hasattr(thisComponent, "setAutoDraw"):
  322. thisComponent.setAutoDraw(False)
  323. trials.addData('instruction_text.started', instruction_text.tStartRefresh)
  324. trials.addData('instruction_text.stopped', instruction_text.tStopRefresh)
  325. start_sound.stop() # ensure sound has stopped at end of routine
  326. trials.addData('start_sound.started', start_sound.tStartRefresh)
  327. trials.addData('start_sound.stopped', start_sound.tStopRefresh)
  328. trials.addData('exclamationMark.started', exclamationMark.tStartRefresh)
  329. trials.addData('exclamationMark.stopped', exclamationMark.tStopRefresh)
  330. # the Routine "instruction" was not non-slip safe, so reset the non-slip timer
  331. routineTimer.reset()
  332. # ------Prepare to start Routine "baseline_2s"-------
  333. continueRoutine = True
  334. routineTimer.add(3.000000)
  335. # update component parameters for each repeat
  336. # keep track of which components have finished
  337. baseline_2sComponents = [fixCross]
  338. for thisComponent in baseline_2sComponents:
  339. thisComponent.tStart = None
  340. thisComponent.tStop = None
  341. thisComponent.tStartRefresh = None
  342. thisComponent.tStopRefresh = None
  343. if hasattr(thisComponent, 'status'):
  344. thisComponent.status = NOT_STARTED
  345. # reset timers
  346. t = 0
  347. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  348. baseline_2sClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  349. frameN = -1
  350. # -------Run Routine "baseline_2s"-------
  351. while continueRoutine and routineTimer.getTime() > 0:
  352. # get current time
  353. t = baseline_2sClock.getTime()
  354. tThisFlip = win.getFutureFlipTime(clock=baseline_2sClock)
  355. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  356. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  357. # update/draw components on each frame
  358. # *fixCross* updates
  359. if fixCross.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  360. # keep track of start time/frame for later
  361. fixCross.frameNStart = frameN # exact frame index
  362. fixCross.tStart = t # local t and not account for scr refresh
  363. fixCross.tStartRefresh = tThisFlipGlobal # on global time
  364. win.timeOnFlip(fixCross, 'tStartRefresh') # time at next scr refresh
  365. fixCross.setAutoDraw(True)
  366. if fixCross.status == STARTED:
  367. # is it time to stop? (based on global clock, using actual start)
  368. if tThisFlipGlobal > fixCross.tStartRefresh + 3-frameTolerance:
  369. # keep track of stop time/frame for later
  370. fixCross.tStop = t # not accounting for scr refresh
  371. fixCross.frameNStop = frameN # exact frame index
  372. win.timeOnFlip(fixCross, 'tStopRefresh') # time at next scr refresh
  373. fixCross.setAutoDraw(False)
  374. # check for quit (typically the Esc key)
  375. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  376. core.quit()
  377. # check if all components have finished
  378. if not continueRoutine: # a component has requested a forced-end of Routine
  379. break
  380. continueRoutine = False # will revert to True if at least one component still running
  381. for thisComponent in baseline_2sComponents:
  382. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  383. continueRoutine = True
  384. break # at least one component has not yet finished
  385. # refresh the screen
  386. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  387. win.flip()
  388. # -------Ending Routine "baseline_2s"-------
  389. for thisComponent in baseline_2sComponents:
  390. if hasattr(thisComponent, "setAutoDraw"):
  391. thisComponent.setAutoDraw(False)
  392. trials.addData('fixCross.started', fixCross.tStartRefresh)
  393. trials.addData('fixCross.stopped', fixCross.tStopRefresh)
  394. # set up handler to look after randomisation of conditions etc
  395. present_sounds = data.TrialHandler(nReps=1, method='sequential',
  396. extraInfo=expInfo, originPath=-1,
  397. trialList=data.importConditions('sounds.xlsx', selection=randomDigits(numOfReps)),
  398. seed=None, name='present_sounds')
  399. thisExp.addLoop(present_sounds) # add the loop to the experiment
  400. thisPresent_sound = present_sounds.trialList[0] # so we can initialise stimuli with some values
  401. # abbreviate parameter names if possible (e.g. rgb = thisPresent_sound.rgb)
  402. if thisPresent_sound != None:
  403. for paramName in thisPresent_sound:
  404. exec('{} = thisPresent_sound[paramName]'.format(paramName))
  405. for thisPresent_sound in present_sounds:
  406. currentLoop = present_sounds
  407. # abbreviate parameter names if possible (e.g. rgb = thisPresent_sound.rgb)
  408. if thisPresent_sound != None:
  409. for paramName in thisPresent_sound:
  410. exec('{} = thisPresent_sound[paramName]'.format(paramName))
  411. # ------Prepare to start Routine "digits"-------
  412. continueRoutine = True
  413. # update component parameters for each repeat
  414. sound_digit.setSound(sounds, hamming=True)
  415. sound_digit.setVolume(1, log=False)
  416. # keep track of which components have finished
  417. digitsComponents = [sound_digit, FixCross_answ]
  418. for thisComponent in digitsComponents:
  419. thisComponent.tStart = None
  420. thisComponent.tStop = None
  421. thisComponent.tStartRefresh = None
  422. thisComponent.tStopRefresh = None
  423. if hasattr(thisComponent, 'status'):
  424. thisComponent.status = NOT_STARTED
  425. # reset timers
  426. t = 0
  427. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  428. digitsClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  429. frameN = -1
  430. # -------Run Routine "digits"-------
  431. while continueRoutine:
  432. # get current time
  433. t = digitsClock.getTime()
  434. tThisFlip = win.getFutureFlipTime(clock=digitsClock)
  435. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  436. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  437. # update/draw components on each frame
  438. # start/stop sound_digit
  439. if sound_digit.status == NOT_STARTED and t >= 0.0-frameTolerance:
  440. # keep track of start time/frame for later
  441. sound_digit.frameNStart = frameN # exact frame index
  442. sound_digit.tStart = t # local t and not account for scr refresh
  443. sound_digit.tStartRefresh = tThisFlipGlobal # on global time
  444. sound_digit.play() # start the sound (it finishes automatically)
  445. # *FixCross_answ* updates
  446. if FixCross_answ.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  447. # keep track of start time/frame for later
  448. FixCross_answ.frameNStart = frameN # exact frame index
  449. FixCross_answ.tStart = t # local t and not account for scr refresh
  450. FixCross_answ.tStartRefresh = tThisFlipGlobal # on global time
  451. win.timeOnFlip(FixCross_answ, 'tStartRefresh') # time at next scr refresh
  452. FixCross_answ.setAutoDraw(True)
  453. if FixCross_answ.status == STARTED:
  454. # is it time to stop? (based on global clock, using actual start)
  455. if tThisFlipGlobal > FixCross_answ.tStartRefresh + 2.0-frameTolerance:
  456. # keep track of stop time/frame for later
  457. FixCross_answ.tStop = t # not accounting for scr refresh
  458. FixCross_answ.frameNStop = frameN # exact frame index
  459. win.timeOnFlip(FixCross_answ, 'tStopRefresh') # time at next scr refresh
  460. FixCross_answ.setAutoDraw(False)
  461. # check for quit (typically the Esc key)
  462. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  463. core.quit()
  464. # check if all components have finished
  465. if not continueRoutine: # a component has requested a forced-end of Routine
  466. break
  467. continueRoutine = False # will revert to True if at least one component still running
  468. for thisComponent in digitsComponents:
  469. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  470. continueRoutine = True
  471. break # at least one component has not yet finished
  472. # refresh the screen
  473. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  474. win.flip()
  475. # -------Ending Routine "digits"-------
  476. for thisComponent in digitsComponents:
  477. if hasattr(thisComponent, "setAutoDraw"):
  478. thisComponent.setAutoDraw(False)
  479. sound_digit.stop() # ensure sound has stopped at end of routine
  480. present_sounds.addData('sound_digit.started', sound_digit.tStart)
  481. present_sounds.addData('sound_digit.stopped', sound_digit.tStop)
  482. present_sounds.addData('FixCross_answ.started', FixCross_answ.tStartRefresh)
  483. present_sounds.addData('FixCross_answ.stopped', FixCross_answ.tStopRefresh)
  484. # the Routine "digits" was not non-slip safe, so reset the non-slip timer
  485. routineTimer.reset()
  486. thisExp.nextEntry()
  487. # completed 1 repeats of 'present_sounds'
  488. # ------Prepare to start Routine "retention_1s"-------
  489. continueRoutine = True
  490. routineTimer.add(1.000000)
  491. # update component parameters for each repeat
  492. # keep track of which components have finished
  493. retention_1sComponents = [fixCross_1s]
  494. for thisComponent in retention_1sComponents:
  495. thisComponent.tStart = None
  496. thisComponent.tStop = None
  497. thisComponent.tStartRefresh = None
  498. thisComponent.tStopRefresh = None
  499. if hasattr(thisComponent, 'status'):
  500. thisComponent.status = NOT_STARTED
  501. # reset timers
  502. t = 0
  503. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  504. retention_1sClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  505. frameN = -1
  506. # -------Run Routine "retention_1s"-------
  507. while continueRoutine and routineTimer.getTime() > 0:
  508. # get current time
  509. t = retention_1sClock.getTime()
  510. tThisFlip = win.getFutureFlipTime(clock=retention_1sClock)
  511. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  512. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  513. # update/draw components on each frame
  514. # *fixCross_1s* updates
  515. if fixCross_1s.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  516. # keep track of start time/frame for later
  517. fixCross_1s.frameNStart = frameN # exact frame index
  518. fixCross_1s.tStart = t # local t and not account for scr refresh
  519. fixCross_1s.tStartRefresh = tThisFlipGlobal # on global time
  520. win.timeOnFlip(fixCross_1s, 'tStartRefresh') # time at next scr refresh
  521. fixCross_1s.setAutoDraw(True)
  522. if fixCross_1s.status == STARTED:
  523. # is it time to stop? (based on global clock, using actual start)
  524. if tThisFlipGlobal > fixCross_1s.tStartRefresh + 1.0-frameTolerance:
  525. # keep track of stop time/frame for later
  526. fixCross_1s.tStop = t # not accounting for scr refresh
  527. fixCross_1s.frameNStop = frameN # exact frame index
  528. win.timeOnFlip(fixCross_1s, 'tStopRefresh') # time at next scr refresh
  529. fixCross_1s.setAutoDraw(False)
  530. # check for quit (typically the Esc key)
  531. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  532. core.quit()
  533. # check if all components have finished
  534. if not continueRoutine: # a component has requested a forced-end of Routine
  535. break
  536. continueRoutine = False # will revert to True if at least one component still running
  537. for thisComponent in retention_1sComponents:
  538. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  539. continueRoutine = True
  540. break # at least one component has not yet finished
  541. # refresh the screen
  542. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  543. win.flip()
  544. # -------Ending Routine "retention_1s"-------
  545. for thisComponent in retention_1sComponents:
  546. if hasattr(thisComponent, "setAutoDraw"):
  547. thisComponent.setAutoDraw(False)
  548. trials.addData('fixCross_1s.started', fixCross_1s.tStartRefresh)
  549. trials.addData('fixCross_1s.stopped', fixCross_1s.tStopRefresh)
  550. # ------Prepare to start Routine "repeat"-------
  551. continueRoutine = True
  552. # update component parameters for each repeat
  553. if skip_mic==1:
  554. continueRoutine = False
  555. mic_1 = microphone.AdvAudioCapture(name='mic_1', saveDir=wavDirName, stereo=False, chnl=0)
  556. # keep track of which components have finished
  557. repeatComponents = [mic_1, mic_image]
  558. for thisComponent in repeatComponents:
  559. thisComponent.tStart = None
  560. thisComponent.tStop = None
  561. thisComponent.tStartRefresh = None
  562. thisComponent.tStopRefresh = None
  563. if hasattr(thisComponent, 'status'):
  564. thisComponent.status = NOT_STARTED
  565. # reset timers
  566. t = 0
  567. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  568. repeatClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  569. frameN = -1
  570. # -------Run Routine "repeat"-------
  571. while continueRoutine:
  572. # get current time
  573. t = repeatClock.getTime()
  574. tThisFlip = win.getFutureFlipTime(clock=repeatClock)
  575. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  576. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  577. # update/draw components on each frame
  578. # *mic_1* updates
  579. if mic_1.status == NOT_STARTED and t >= 0-frameTolerance:
  580. # keep track of start time/frame for later
  581. mic_1.frameNStart = frameN # exact frame index
  582. mic_1.tStart = t # local t and not account for scr refresh
  583. mic_1.tStartRefresh = tThisFlipGlobal # on global time
  584. win.timeOnFlip(mic_1, 'tStartRefresh') # time at next scr refresh
  585. mic_1.status = STARTED
  586. mic_1.record(sec=micDuration, block=False) # start the recording thread
  587. if mic_1.status == STARTED and not mic_1.recorder.running:
  588. mic_1.status = FINISHED
  589. # *mic_image* updates
  590. if mic_image.status == NOT_STARTED and tThisFlip >= 0-frameTolerance:
  591. # keep track of start time/frame for later
  592. mic_image.frameNStart = frameN # exact frame index
  593. mic_image.tStart = t # local t and not account for scr refresh
  594. mic_image.tStartRefresh = tThisFlipGlobal # on global time
  595. win.timeOnFlip(mic_image, 'tStartRefresh') # time at next scr refresh
  596. mic_image.setAutoDraw(True)
  597. if mic_image.status == STARTED:
  598. # is it time to stop? (based on global clock, using actual start)
  599. if tThisFlipGlobal > mic_image.tStartRefresh + micDuration-frameTolerance:
  600. # keep track of stop time/frame for later
  601. mic_image.tStop = t # not accounting for scr refresh
  602. mic_image.frameNStop = frameN # exact frame index
  603. win.timeOnFlip(mic_image, 'tStopRefresh') # time at next scr refresh
  604. mic_image.setAutoDraw(False)
  605. # check for quit (typically the Esc key)
  606. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  607. core.quit()
  608. # check if all components have finished
  609. if not continueRoutine: # a component has requested a forced-end of Routine
  610. break
  611. continueRoutine = False # will revert to True if at least one component still running
  612. for thisComponent in repeatComponents:
  613. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  614. continueRoutine = True
  615. break # at least one component has not yet finished
  616. # refresh the screen
  617. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  618. win.flip()
  619. # -------Ending Routine "repeat"-------
  620. for thisComponent in repeatComponents:
  621. if hasattr(thisComponent, "setAutoDraw"):
  622. thisComponent.setAutoDraw(False)
  623. # mic_1 stop & responses
  624. mic_1.stop() # sometimes helpful
  625. if not mic_1.savedFile:
  626. mic_1.savedFile = None
  627. # store data for trials (TrialHandler)
  628. trials.addData('mic_1.filename', mic_1.savedFile)
  629. trials.addData('mic_1.started', mic_1.tStart)
  630. trials.addData('mic_1.stopped', mic_1.tStop)
  631. trials.addData('mic_image.started', mic_image.tStartRefresh)
  632. trials.addData('mic_image.stopped', mic_image.tStopRefresh)
  633. # the Routine "repeat" was not non-slip safe, so reset the non-slip timer
  634. routineTimer.reset()
  635. # ------Prepare to start Routine "end_block"-------
  636. continueRoutine = True
  637. # update component parameters for each repeat
  638. end.setSound('num/end_block.wav', hamming=True)
  639. end.setVolume(1, log=False)
  640. # keep track of which components have finished
  641. end_blockComponents = [end, FixCross_end]
  642. for thisComponent in end_blockComponents:
  643. thisComponent.tStart = None
  644. thisComponent.tStop = None
  645. thisComponent.tStartRefresh = None
  646. thisComponent.tStopRefresh = None
  647. if hasattr(thisComponent, 'status'):
  648. thisComponent.status = NOT_STARTED
  649. # reset timers
  650. t = 0
  651. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  652. end_blockClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  653. frameN = -1
  654. # -------Run Routine "end_block"-------
  655. while continueRoutine:
  656. # get current time
  657. t = end_blockClock.getTime()
  658. tThisFlip = win.getFutureFlipTime(clock=end_blockClock)
  659. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  660. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  661. # update/draw components on each frame
  662. # start/stop end
  663. if end.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  664. # keep track of start time/frame for later
  665. end.frameNStart = frameN # exact frame index
  666. end.tStart = t # local t and not account for scr refresh
  667. end.tStartRefresh = tThisFlipGlobal # on global time
  668. end.play(when=win) # sync with win flip
  669. # *FixCross_end* updates
  670. if FixCross_end.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  671. # keep track of start time/frame for later
  672. FixCross_end.frameNStart = frameN # exact frame index
  673. FixCross_end.tStart = t # local t and not account for scr refresh
  674. FixCross_end.tStartRefresh = tThisFlipGlobal # on global time
  675. win.timeOnFlip(FixCross_end, 'tStartRefresh') # time at next scr refresh
  676. FixCross_end.setAutoDraw(True)
  677. if FixCross_end.status == STARTED:
  678. # is it time to stop? (based on global clock, using actual start)
  679. if tThisFlipGlobal > FixCross_end.tStartRefresh + 5.0-frameTolerance:
  680. # keep track of stop time/frame for later
  681. FixCross_end.tStop = t # not accounting for scr refresh
  682. FixCross_end.frameNStop = frameN # exact frame index
  683. win.timeOnFlip(FixCross_end, 'tStopRefresh') # time at next scr refresh
  684. FixCross_end.setAutoDraw(False)
  685. # check for quit (typically the Esc key)
  686. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  687. core.quit()
  688. # check if all components have finished
  689. if not continueRoutine: # a component has requested a forced-end of Routine
  690. break
  691. continueRoutine = False # will revert to True if at least one component still running
  692. for thisComponent in end_blockComponents:
  693. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  694. continueRoutine = True
  695. break # at least one component has not yet finished
  696. # refresh the screen
  697. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  698. win.flip()
  699. # -------Ending Routine "end_block"-------
  700. for thisComponent in end_blockComponents:
  701. if hasattr(thisComponent, "setAutoDraw"):
  702. thisComponent.setAutoDraw(False)
  703. end.stop() # ensure sound has stopped at end of routine
  704. trials.addData('end.started', end.tStartRefresh)
  705. trials.addData('end.stopped', end.tStopRefresh)
  706. trials.addData('FixCross_end.started', FixCross_end.tStartRefresh)
  707. trials.addData('FixCross_end.stopped', FixCross_end.tStopRefresh)
  708. # the Routine "end_block" was not non-slip safe, so reset the non-slip timer
  709. routineTimer.reset()
  710. thisExp.nextEntry()
  711. # completed 1 repeats of 'trials'
  712. # ------Prepare to start Routine "rest"-------
  713. continueRoutine = True
  714. # update component parameters for each repeat
  715. rest_instruction.setColor('white', colorSpace='rgb')
  716. rest_instruction.setText('Конец тренировки')
  717. key_resp_2.keys = []
  718. key_resp_2.rt = []
  719. _key_resp_2_allKeys = []
  720. # keep track of which components have finished
  721. restComponents = [rest_instruction, key_resp_2]
  722. for thisComponent in restComponents:
  723. thisComponent.tStart = None
  724. thisComponent.tStop = None
  725. thisComponent.tStartRefresh = None
  726. thisComponent.tStopRefresh = None
  727. if hasattr(thisComponent, 'status'):
  728. thisComponent.status = NOT_STARTED
  729. # reset timers
  730. t = 0
  731. _timeToFirstFrame = win.getFutureFlipTime(clock="now")
  732. restClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
  733. frameN = -1
  734. # -------Run Routine "rest"-------
  735. while continueRoutine:
  736. # get current time
  737. t = restClock.getTime()
  738. tThisFlip = win.getFutureFlipTime(clock=restClock)
  739. tThisFlipGlobal = win.getFutureFlipTime(clock=None)
  740. frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
  741. # update/draw components on each frame
  742. # *rest_instruction* updates
  743. if rest_instruction.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  744. # keep track of start time/frame for later
  745. rest_instruction.frameNStart = frameN # exact frame index
  746. rest_instruction.tStart = t # local t and not account for scr refresh
  747. rest_instruction.tStartRefresh = tThisFlipGlobal # on global time
  748. win.timeOnFlip(rest_instruction, 'tStartRefresh') # time at next scr refresh
  749. rest_instruction.setAutoDraw(True)
  750. # *key_resp_2* updates
  751. waitOnFlip = False
  752. if key_resp_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
  753. # keep track of start time/frame for later
  754. key_resp_2.frameNStart = frameN # exact frame index
  755. key_resp_2.tStart = t # local t and not account for scr refresh
  756. key_resp_2.tStartRefresh = tThisFlipGlobal # on global time
  757. win.timeOnFlip(key_resp_2, 'tStartRefresh') # time at next scr refresh
  758. key_resp_2.status = STARTED
  759. # keyboard checking is just starting
  760. waitOnFlip = True
  761. win.callOnFlip(key_resp_2.clock.reset) # t=0 on next screen flip
  762. win.callOnFlip(key_resp_2.clearEvents, eventType='keyboard') # clear events on next screen flip
  763. if key_resp_2.status == STARTED and not waitOnFlip:
  764. theseKeys = key_resp_2.getKeys(keyList=['space'], waitRelease=False)
  765. _key_resp_2_allKeys.extend(theseKeys)
  766. if len(_key_resp_2_allKeys):
  767. key_resp_2.keys = _key_resp_2_allKeys[-1].name # just the last key pressed
  768. key_resp_2.rt = _key_resp_2_allKeys[-1].rt
  769. # a response ends the routine
  770. continueRoutine = False
  771. # check for quit (typically the Esc key)
  772. if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
  773. core.quit()
  774. # check if all components have finished
  775. if not continueRoutine: # a component has requested a forced-end of Routine
  776. break
  777. continueRoutine = False # will revert to True if at least one component still running
  778. for thisComponent in restComponents:
  779. if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
  780. continueRoutine = True
  781. break # at least one component has not yet finished
  782. # refresh the screen
  783. if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
  784. win.flip()
  785. # -------Ending Routine "rest"-------
  786. for thisComponent in restComponents:
  787. if hasattr(thisComponent, "setAutoDraw"):
  788. thisComponent.setAutoDraw(False)
  789. thisExp.addData('rest_instruction.started', rest_instruction.tStartRefresh)
  790. thisExp.addData('rest_instruction.stopped', rest_instruction.tStopRefresh)
  791. # check responses
  792. if key_resp_2.keys in ['', [], None]: # No response was made
  793. key_resp_2.keys = None
  794. thisExp.addData('key_resp_2.keys',key_resp_2.keys)
  795. if key_resp_2.keys != None: # we had a response
  796. thisExp.addData('key_resp_2.rt', key_resp_2.rt)
  797. thisExp.addData('key_resp_2.started', key_resp_2.tStartRefresh)
  798. thisExp.addData('key_resp_2.stopped', key_resp_2.tStopRefresh)
  799. thisExp.nextEntry()
  800. # the Routine "rest" was not non-slip safe, so reset the non-slip timer
  801. routineTimer.reset()
  802. # Flip one final time so any remaining win.callOnFlip()
  803. # and win.timeOnFlip() tasks get executed before quitting
  804. win.flip()
  805. # these shouldn't be strictly necessary (should auto-save)
  806. thisExp.saveAsWideText(filename+'.csv')
  807. thisExp.saveAsPickle(filename)
  808. logging.flush()
  809. # make sure everything is closed down
  810. thisExp.abort() # or data files will save again on exit
  811. win.close()
  812. core.quit()