dynamic_selective_inspect_lastrun.py 30.2 KB
Newer Older
1
#!/usr/bin/env python
David Bridges's avatar
_  
David Bridges committed
2 3
# -*- coding: utf-8 -*-
"""
4
This experiment was created using PsychoPy3 Experiment Builder (v3.2.3),
5
    on October 07, 2019, at 10:49
6 7 8 9 10 11
If you publish work using this script the most relevant publication is:

    Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) 
        PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. 
        https://doi.org/10.3758/s13428-018-01193-y

David Bridges's avatar
_  
David Bridges committed
12 13 14
"""

from __future__ import absolute_import, division
15 16 17 18

from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
David Bridges's avatar
_  
David Bridges committed
19 20
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
21

David Bridges's avatar
_  
David Bridges committed
22 23 24 25 26 27 28
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding

29 30
from psychopy.hardware import keyboard

David Bridges's avatar
_  
David Bridges committed
31
# Ensure that relative paths start from the same directory as this script
32
_thisDir = os.path.dirname(os.path.abspath(__file__))
David Bridges's avatar
_  
David Bridges committed
33 34 35
os.chdir(_thisDir)

# Store info about the experiment session
36
psychopyVersion = '3.2.3'
David Bridges's avatar
_  
David Bridges committed
37 38 39 40
expName = 'dynamic_selective_inspect'  # from the Builder filename that created this script
expInfo = {'session': '001', 'participant': ''}
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
41
expInfo['psychopyVersion'] = psychopyVersion
David Bridges's avatar
_  
David Bridges committed
42 43 44 45 46 47 48

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
49
    originPath='D:\\OneDrive - The University of Nottingham\\workshops\\examples2019\\builder\\dynamic stimuli\\selective\\dynamic_selective_inspect_lastrun.py',
David Bridges's avatar
_  
David Bridges committed
50 51 52 53 54 55 56
    savePickle=True, saveWideText=True,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp
57
frameTolerance = 0.001  # how close to onset before 'same' frame
David Bridges's avatar
_  
David Bridges committed
58 59 60 61 62

# Start Code - component code to be run before the window creation

# Setup the Window
win = visual.Window(
63 64 65 66
    size=[1920, 1080], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=True, allowStencil=False,
    monitor='testMonitor', color='white', colorSpace='rgb',
    blendMode='avg', useFBO=True, 
David Bridges's avatar
_  
David Bridges committed
67 68 69 70 71 72 73 74
    units='height')
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
    frameDur = 1.0 / round(expInfo['frameRate'])
else:
    frameDur = 1.0 / 60.0  # could not measure, so guess

75 76 77
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard()

David Bridges's avatar
_  
David Bridges committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
# Initialize components for Routine "instruct"
instructClock = core.Clock()
instructFirst = visual.TextStim(win=win, name='instructFirst',
    text='On each trial you have to search the screen to find the ball\n(by moving the mouse around)\n\nClick the mouse to get started',
    font='Arial',
    units='height', pos=(0, 0.3), height=0.05, wrapWidth=None, ori=0, 
    color='black', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
finishInstruct = event.Mouse(win=win)
x, y = [None, None]
finishInstruct.mouseClock = core.Clock()

# Initialize components for Routine "trial"
trialClock = core.Clock()
imageStimulus = visual.ImageStim(
94 95 96
    win=win,
    name='imageStimulus', units='norm', 
    image='images/7751351978_d87ea5d14e_k.jpg', mask=None,
David Bridges's avatar
_  
David Bridges committed
97 98 99 100 101
    ori=0, pos=(0, 0), size=(2, 2),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)
imageAperture = visual.ImageStim(
102 103
    win=win,
    name='imageAperture', units='height', 
David Bridges's avatar
_  
David Bridges committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    image='images/plainWhite.png', mask='images/circleMask.png',
    ori=0, pos=[0,0], size=(4, 4),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=512, interpolate=True, depth=-1.0)
mouse = event.Mouse(win=win)
x, y = [None, None]
mouse.mouseClock = core.Clock()

# Initialize components for Routine "explanation"
explanationClock = core.Clock()
instruct2 = visual.TextStim(win=win, name='instruct2',
    text='This is essentially the same thing but\nthe mask is now smaller ( w,h = 2,2 in height units) so you can see \nwhat was happening.',
    font='Arial',
    units='height', pos=(0, 0.3), height=0.05, wrapWidth=None, ori=0, 
    color='black', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
explanationFinish = event.Mouse(win=win)
x, y = [None, None]
explanationFinish.mouseClock = core.Clock()

# Initialize components for Routine "showMeHow"
showMeHowClock = core.Clock()
imageStimulus_2 = visual.ImageStim(
129 130
    win=win,
    name='imageStimulus_2', units='norm', 
David Bridges's avatar
_  
David Bridges committed
131 132 133 134 135 136
    image='sin', mask=None,
    ori=0, pos=(0, 0), size=(2, 2),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)
imageAperture_2 = visual.ImageStim(
137 138
    win=win,
    name='imageAperture_2', units='height', 
David Bridges's avatar
_  
David Bridges committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    image='images/plainWhite.png', mask='images/circleMask.png',
    ori=0, pos=[0,0], size=(1,1),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=512, interpolate=True, depth=-1.0)
mouse_2 = event.Mouse(win=win)
x, y = [None, None]
mouse_2.mouseClock = core.Clock()

# Initialize components for Routine "thanks"
thanksClock = core.Clock()
text = visual.TextStim(win=win, name='text',
    text="That's all there is to it.\n\nBye!",
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);

# Create some handy timers
globalClock = core.Clock()  # to track the time since experiment started
routineTimer = core.CountdownTimer()  # to track time remaining of each (non-slip) routine 

# ------Prepare to start Routine "instruct"-------
# update component parameters for each repeat
# setup some python lists for storing info about the finishInstruct
gotValidClick = False  # until a click is received
# keep track of which components have finished
instructComponents = [instructFirst, finishInstruct]
for thisComponent in instructComponents:
169 170 171 172
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
David Bridges's avatar
_  
David Bridges committed
173 174
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
175 176 177 178 179 180
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
instructClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1
continueRoutine = True
David Bridges's avatar
_  
David Bridges committed
181

182
# -------Run Routine "instruct"-------
David Bridges's avatar
_  
David Bridges committed
183 184 185
while continueRoutine:
    # get current time
    t = instructClock.getTime()
186 187
    tThisFlip = win.getFutureFlipTime(clock=instructClock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
David Bridges's avatar
_  
David Bridges committed
188 189 190 191
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *instructFirst* updates
192
    if instructFirst.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
193 194
        # keep track of start time/frame for later
        instructFirst.frameNStart = frameN  # exact frame index
195 196 197
        instructFirst.tStart = t  # local t and not account for scr refresh
        instructFirst.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(instructFirst, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
198 199
        instructFirst.setAutoDraw(True)
    # *finishInstruct* updates
200
    if finishInstruct.status == NOT_STARTED and t >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
201 202
        # keep track of start time/frame for later
        finishInstruct.frameNStart = frameN  # exact frame index
203 204 205
        finishInstruct.tStart = t  # local t and not account for scr refresh
        finishInstruct.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(finishInstruct, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
206 207 208
        finishInstruct.status = STARTED
        finishInstruct.mouseClock.reset()
        prevButtonState = finishInstruct.getPressed()  # if button is down already this ISN'T a new click
209
    if finishInstruct.status == STARTED:  # only update if started and not finished!
David Bridges's avatar
_  
David Bridges committed
210 211 212 213 214
        buttons = finishInstruct.getPressed()
        if buttons != prevButtonState:  # button state changed?
            prevButtonState = buttons
            if sum(buttons) > 0:  # state changed to a new click
                continueRoutine = False    
215 216 217 218
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
David Bridges's avatar
_  
David Bridges committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in instructComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "instruct"-------
for thisComponent in instructComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
236 237
thisExp.addData('instructFirst.started', instructFirst.tStartRefresh)
thisExp.addData('instructFirst.stopped', instructFirst.tStopRefresh)
David Bridges's avatar
_  
David Bridges committed
238
# store data for thisExp (ExperimentHandler)
239 240
thisExp.addData('finishInstruct.started', finishInstruct.tStart)
thisExp.addData('finishInstruct.stopped', finishInstruct.tStop)
David Bridges's avatar
_  
David Bridges committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
thisExp.nextEntry()
# the Routine "instruct" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=1, method='random', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('conditions.xlsx'),
    seed=None, name='trials')
thisExp.addLoop(trials)  # add the loop to the experiment
thisTrial = trials.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
    for paramName in thisTrial:
        exec('{} = thisTrial[paramName]'.format(paramName))

for thisTrial in trials:
    currentLoop = trials
    # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
    if thisTrial != None:
        for paramName in thisTrial:
            exec('{} = thisTrial[paramName]'.format(paramName))
    
    # ------Prepare to start Routine "trial"-------
    # update component parameters for each repeat
    # setup some python lists for storing info about the mouse
    gotValidClick = False  # until a click is received
    mouse.mouseClock.reset()
    # keep track of which components have finished
    trialComponents = [imageStimulus, imageAperture, mouse]
    for thisComponent in trialComponents:
272 273 274 275
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
David Bridges's avatar
_  
David Bridges committed
276 277
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
278 279 280 281 282 283
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    trialClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
    frameN = -1
    continueRoutine = True
David Bridges's avatar
_  
David Bridges committed
284
    
285
    # -------Run Routine "trial"-------
David Bridges's avatar
_  
David Bridges committed
286 287 288
    while continueRoutine:
        # get current time
        t = trialClock.getTime()
289 290
        tThisFlip = win.getFutureFlipTime(clock=trialClock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
David Bridges's avatar
_  
David Bridges committed
291 292 293 294
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *imageStimulus* updates
295
        if imageStimulus.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
296 297
            # keep track of start time/frame for later
            imageStimulus.frameNStart = frameN  # exact frame index
298 299 300
            imageStimulus.tStart = t  # local t and not account for scr refresh
            imageStimulus.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(imageStimulus, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
301 302 303
            imageStimulus.setAutoDraw(True)
        
        # *imageAperture* updates
304
        if imageAperture.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
305 306
            # keep track of start time/frame for later
            imageAperture.frameNStart = frameN  # exact frame index
307 308 309
            imageAperture.tStart = t  # local t and not account for scr refresh
            imageAperture.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(imageAperture, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
310 311 312 313
            imageAperture.setAutoDraw(True)
        if imageAperture.status == STARTED:  # only update if drawing
            imageAperture.setPos(mouse.getPos(), log=False)
        # *mouse* updates
314
        if mouse.status == NOT_STARTED and t >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
315 316
            # keep track of start time/frame for later
            mouse.frameNStart = frameN  # exact frame index
317 318 319
            mouse.tStart = t  # local t and not account for scr refresh
            mouse.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
320 321
            mouse.status = STARTED
            prevButtonState = mouse.getPressed()  # if button is down already this ISN'T a new click
322
        if mouse.status == STARTED:  # only update if started and not finished!
David Bridges's avatar
_  
David Bridges committed
323 324 325 326 327 328
            buttons = mouse.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    # abort routine on response
                    continueRoutine = False
329 330 331 332
        
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
David Bridges's avatar
_  
David Bridges committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in trialComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # -------Ending Routine "trial"-------
    for thisComponent in trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
351 352 353 354
    trials.addData('imageStimulus.started', imageStimulus.tStartRefresh)
    trials.addData('imageStimulus.stopped', imageStimulus.tStopRefresh)
    trials.addData('imageAperture.started', imageAperture.tStartRefresh)
    trials.addData('imageAperture.stopped', imageAperture.tStopRefresh)
David Bridges's avatar
_  
David Bridges committed
355 356 357 358 359 360 361 362
    # store data for trials (TrialHandler)
    x, y = mouse.getPos()
    buttons = mouse.getPressed()
    trials.addData('mouse.x', x)
    trials.addData('mouse.y', y)
    trials.addData('mouse.leftButton', buttons[0])
    trials.addData('mouse.midButton', buttons[1])
    trials.addData('mouse.rightButton', buttons[2])
363 364
    trials.addData('mouse.started', mouse.tStart)
    trials.addData('mouse.stopped', mouse.tStop)
David Bridges's avatar
_  
David Bridges committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378
    # the Routine "trial" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    thisExp.nextEntry()
    
# completed 1 repeats of 'trials'


# ------Prepare to start Routine "explanation"-------
# update component parameters for each repeat
# setup some python lists for storing info about the explanationFinish
gotValidClick = False  # until a click is received
# keep track of which components have finished
explanationComponents = [instruct2, explanationFinish]
for thisComponent in explanationComponents:
379 380 381 382
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
David Bridges's avatar
_  
David Bridges committed
383 384
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
385 386 387 388 389 390
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
explanationClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1
continueRoutine = True
David Bridges's avatar
_  
David Bridges committed
391

392
# -------Run Routine "explanation"-------
David Bridges's avatar
_  
David Bridges committed
393 394 395
while continueRoutine:
    # get current time
    t = explanationClock.getTime()
396 397
    tThisFlip = win.getFutureFlipTime(clock=explanationClock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
David Bridges's avatar
_  
David Bridges committed
398 399 400 401
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *instruct2* updates
402
    if instruct2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
403 404
        # keep track of start time/frame for later
        instruct2.frameNStart = frameN  # exact frame index
405 406 407
        instruct2.tStart = t  # local t and not account for scr refresh
        instruct2.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(instruct2, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
408 409
        instruct2.setAutoDraw(True)
    # *explanationFinish* updates
410
    if explanationFinish.status == NOT_STARTED and t >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
411 412
        # keep track of start time/frame for later
        explanationFinish.frameNStart = frameN  # exact frame index
413 414 415
        explanationFinish.tStart = t  # local t and not account for scr refresh
        explanationFinish.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(explanationFinish, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
416 417 418
        explanationFinish.status = STARTED
        explanationFinish.mouseClock.reset()
        prevButtonState = explanationFinish.getPressed()  # if button is down already this ISN'T a new click
419
    if explanationFinish.status == STARTED:  # only update if started and not finished!
David Bridges's avatar
_  
David Bridges committed
420 421 422 423 424
        buttons = explanationFinish.getPressed()
        if buttons != prevButtonState:  # button state changed?
            prevButtonState = buttons
            if sum(buttons) > 0:  # state changed to a new click
                continueRoutine = False    
425 426 427 428
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
David Bridges's avatar
_  
David Bridges committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in explanationComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "explanation"-------
for thisComponent in explanationComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
446 447
thisExp.addData('instruct2.started', instruct2.tStartRefresh)
thisExp.addData('instruct2.stopped', instruct2.tStopRefresh)
David Bridges's avatar
_  
David Bridges committed
448
# store data for thisExp (ExperimentHandler)
449 450
thisExp.addData('explanationFinish.started', explanationFinish.tStart)
thisExp.addData('explanationFinish.stopped', explanationFinish.tStop)
David Bridges's avatar
_  
David Bridges committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
thisExp.nextEntry()
# the Routine "explanation" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# set up handler to look after randomisation of conditions etc
showMeTrials = data.TrialHandler(nReps=1, method='random', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('conditions.xlsx'),
    seed=None, name='showMeTrials')
thisExp.addLoop(showMeTrials)  # add the loop to the experiment
thisShowMeTrial = showMeTrials.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisShowMeTrial.rgb)
if thisShowMeTrial != None:
    for paramName in thisShowMeTrial:
        exec('{} = thisShowMeTrial[paramName]'.format(paramName))

for thisShowMeTrial in showMeTrials:
    currentLoop = showMeTrials
    # abbreviate parameter names if possible (e.g. rgb = thisShowMeTrial.rgb)
    if thisShowMeTrial != None:
        for paramName in thisShowMeTrial:
            exec('{} = thisShowMeTrial[paramName]'.format(paramName))
    
    # ------Prepare to start Routine "showMeHow"-------
    # update component parameters for each repeat
    imageStimulus_2.setImage(imageFile)
    # setup some python lists for storing info about the mouse_2
    mouse_2.x = []
    mouse_2.y = []
    mouse_2.leftButton = []
    mouse_2.midButton = []
    mouse_2.rightButton = []
    mouse_2.time = []
    gotValidClick = False  # until a click is received
    # keep track of which components have finished
    showMeHowComponents = [imageStimulus_2, imageAperture_2, mouse_2]
    for thisComponent in showMeHowComponents:
488 489 490 491
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
David Bridges's avatar
_  
David Bridges committed
492 493
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
494 495 496 497 498 499
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    showMeHowClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
    frameN = -1
    continueRoutine = True
David Bridges's avatar
_  
David Bridges committed
500
    
501
    # -------Run Routine "showMeHow"-------
David Bridges's avatar
_  
David Bridges committed
502 503 504
    while continueRoutine:
        # get current time
        t = showMeHowClock.getTime()
505 506
        tThisFlip = win.getFutureFlipTime(clock=showMeHowClock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
David Bridges's avatar
_  
David Bridges committed
507 508 509 510
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *imageStimulus_2* updates
511
        if imageStimulus_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
512 513
            # keep track of start time/frame for later
            imageStimulus_2.frameNStart = frameN  # exact frame index
514 515 516
            imageStimulus_2.tStart = t  # local t and not account for scr refresh
            imageStimulus_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(imageStimulus_2, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
517 518 519
            imageStimulus_2.setAutoDraw(True)
        
        # *imageAperture_2* updates
520
        if imageAperture_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
521 522
            # keep track of start time/frame for later
            imageAperture_2.frameNStart = frameN  # exact frame index
523 524 525
            imageAperture_2.tStart = t  # local t and not account for scr refresh
            imageAperture_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(imageAperture_2, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
526 527 528 529
            imageAperture_2.setAutoDraw(True)
        if imageAperture_2.status == STARTED:  # only update if drawing
            imageAperture_2.setPos(mouse.getPos(), log=False)
        # *mouse_2* updates
530
        if mouse_2.status == NOT_STARTED and t >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
531 532
            # keep track of start time/frame for later
            mouse_2.frameNStart = frameN  # exact frame index
533 534 535
            mouse_2.tStart = t  # local t and not account for scr refresh
            mouse_2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(mouse_2, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
536 537 538
            mouse_2.status = STARTED
            mouse_2.mouseClock.reset()
            prevButtonState = mouse_2.getPressed()  # if button is down already this ISN'T a new click
539
        if mouse_2.status == STARTED:  # only update if started and not finished!
David Bridges's avatar
_  
David Bridges committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
            buttons = mouse_2.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click
                    x, y = mouse_2.getPos()
                    mouse_2.x.append(x)
                    mouse_2.y.append(y)
                    buttons = mouse_2.getPressed()
                    mouse_2.leftButton.append(buttons[0])
                    mouse_2.midButton.append(buttons[1])
                    mouse_2.rightButton.append(buttons[2])
                    mouse_2.time.append(mouse_2.mouseClock.getTime())
                    # abort routine on response
                    continueRoutine = False
        
555 556 557 558
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
        
David Bridges's avatar
_  
David Bridges committed
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in showMeHowComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # -------Ending Routine "showMeHow"-------
    for thisComponent in showMeHowComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
576 577 578 579
    showMeTrials.addData('imageStimulus_2.started', imageStimulus_2.tStartRefresh)
    showMeTrials.addData('imageStimulus_2.stopped', imageStimulus_2.tStopRefresh)
    showMeTrials.addData('imageAperture_2.started', imageAperture_2.tStartRefresh)
    showMeTrials.addData('imageAperture_2.stopped', imageAperture_2.tStopRefresh)
David Bridges's avatar
_  
David Bridges committed
580 581 582 583 584 585 586
    # store data for showMeTrials (TrialHandler)
    if len(mouse_2.x): showMeTrials.addData('mouse_2.x', mouse_2.x[0])
    if len(mouse_2.y): showMeTrials.addData('mouse_2.y', mouse_2.y[0])
    if len(mouse_2.leftButton): showMeTrials.addData('mouse_2.leftButton', mouse_2.leftButton[0])
    if len(mouse_2.midButton): showMeTrials.addData('mouse_2.midButton', mouse_2.midButton[0])
    if len(mouse_2.rightButton): showMeTrials.addData('mouse_2.rightButton', mouse_2.rightButton[0])
    if len(mouse_2.time): showMeTrials.addData('mouse_2.time', mouse_2.time[0])
587 588
    showMeTrials.addData('mouse_2.started', mouse_2.tStart)
    showMeTrials.addData('mouse_2.stopped', mouse_2.tStop)
David Bridges's avatar
_  
David Bridges committed
589 590 591 592 593 594 595 596 597 598 599 600 601
    # the Routine "showMeHow" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    thisExp.nextEntry()
    
# completed 1 repeats of 'showMeTrials'


# ------Prepare to start Routine "thanks"-------
routineTimer.add(1.000000)
# update component parameters for each repeat
# keep track of which components have finished
thanksComponents = [text]
for thisComponent in thanksComponents:
602 603 604 605
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
David Bridges's avatar
_  
David Bridges committed
606 607
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
608 609 610 611 612 613
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
thanksClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1
continueRoutine = True
David Bridges's avatar
_  
David Bridges committed
614

615
# -------Run Routine "thanks"-------
David Bridges's avatar
_  
David Bridges committed
616 617 618
while continueRoutine and routineTimer.getTime() > 0:
    # get current time
    t = thanksClock.getTime()
619 620
    tThisFlip = win.getFutureFlipTime(clock=thanksClock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
David Bridges's avatar
_  
David Bridges committed
621 622 623 624
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *text* updates
625
    if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
David Bridges's avatar
_  
David Bridges committed
626 627
        # keep track of start time/frame for later
        text.frameNStart = frameN  # exact frame index
628 629 630
        text.tStart = t  # local t and not account for scr refresh
        text.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(text, 'tStartRefresh')  # time at next scr refresh
David Bridges's avatar
_  
David Bridges committed
631
        text.setAutoDraw(True)
632 633 634 635 636 637 638 639 640 641 642 643
    if text.status == STARTED:
        # is it time to stop? (based on global clock, using actual start)
        if tThisFlipGlobal > text.tStartRefresh + 1.0-frameTolerance:
            # keep track of stop time/frame for later
            text.tStop = t  # not accounting for scr refresh
            text.frameNStop = frameN  # exact frame index
            win.timeOnFlip(text, 'tStopRefresh')  # time at next scr refresh
            text.setAutoDraw(False)
    
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
David Bridges's avatar
_  
David Bridges committed
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
    
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in thanksComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "thanks"-------
for thisComponent in thanksComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
662 663 664 665 666 667
thisExp.addData('text.started', text.tStartRefresh)
thisExp.addData('text.stopped', text.tStopRefresh)

# Flip one final time so any remaining win.callOnFlip() 
# and win.timeOnFlip() tasks get executed before quitting
win.flip()
David Bridges's avatar
_  
David Bridges committed
668 669 670 671 672 673 674 675 676

# these shouldn't be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+'.csv')
thisExp.saveAsPickle(filename)
logging.flush()
# make sure everything is closed down
thisExp.abort()  # or data files will save again on exit
win.close()
core.quit()