Butterfly.py 31.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2020.1.3),
    on Mon Jan  4 12:52:39 2021
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

"""

from __future__ import absolute_import, division

import psychopy
psychopy.useVersion('2020.1')


from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding

from psychopy.hardware import keyboard



# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)

# Store info about the experiment session
psychopyVersion = '2020.1.3'
expName = 'DPT'  # from the Builder filename that created this script
expInfo = {'Participant_Initials': ''}
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion

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

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath='/Users/briannakeenan/Desktop/Butterfly/Butterfly.py',
    savePickle=True, saveWideText=True,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.WARNING)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp
frameTolerance = 0.001  # how close to onset before 'same' frame

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

# Setup the Window
win = visual.Window(
    size=[1440, 900], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    units='pix')
# 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

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

# Initialize components for Routine "TrialFixITI"
TrialFixITIClock = core.Clock()
TrialFixation = visual.TextStim(win=win, name='TrialFixation',
    text='+',
    font='Arial',
    pos=[0, 0], height=50, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
TrialFixation2 = visual.TextStim(win=win, name='TrialFixation2',
    text='+',
    font='Arial',
    pos=(0, 0), height=80, wrapWidth=None, ori=0, 
    color='blue', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);
TrialFixation3 = visual.TextStim(win=win, name='TrialFixation3',
    text='+',
    font='Arial',
    pos=(0, 0), height=80, wrapWidth=None, ori=0, 
    color='red', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-2.0);
TrialFixation4 = visual.TextStim(win=win, name='TrialFixation4',
    text='+',
    font='Arial',
    pos=(0, 0), height=50, wrapWidth=None, ori=0, 
    color='blue', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-3.0);

# Initialize components for Routine "Dot"
DotClock = core.Clock()
Grid = visual.ImageStim(
    win=win,
    name='Grid', 
    image='Grid.png', mask=None,
    ori=0, pos=(0, 0), size=[600,600],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)
Obj1 = visual.ImageStim(
    win=win,
    name='Obj1', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150, 150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-1.0)
Obj2 = visual.ImageStim(
    win=win,
    name='Obj2', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150, 150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-2.0)
Obj3 = visual.ImageStim(
    win=win,
    name='Obj3', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-3.0)
Obj4 = visual.ImageStim(
    win=win,
    name='Obj4', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-4.0)
Obj5 = visual.ImageStim(
    win=win,
    name='Obj5', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-5.0)
Obj6 = visual.ImageStim(
    win=win,
    name='Obj6', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-6.0)
Obj7 = visual.ImageStim(
    win=win,
    name='Obj7', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-7.0)
Obj8 = visual.ImageStim(
    win=win,
    name='Obj8', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-8.0)
Obj9 = visual.ImageStim(
    win=win,
    name='Obj9', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-9.0)
Face = visual.ImageStim(
    win=win,
    name='Face', 
    image='Face.png', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1.0,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-10.0)
Butterfly = visual.ImageStim(
    win=win,
    name='Butterfly', 
    image='sin', mask=None,
    ori=0, pos=[0,0], size=[150,150],
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-11.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 

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

for thisTrial_block in trial_block:
    currentLoop = trial_block
    # abbreviate parameter names if possible (e.g. rgb = thisTrial_block.rgb)
    if thisTrial_block != None:
        for paramName in thisTrial_block:
            exec('{} = thisTrial_block[paramName]'.format(paramName))
    
    # ------Prepare to start Routine "TrialFixITI"-------
    continueRoutine = True
    routineTimer.add(0.500000)
    # update component parameters for each repeat
    # keep track of which components have finished
    TrialFixITIComponents = [TrialFixation, TrialFixation2, TrialFixation3, TrialFixation4]
    for thisComponent in TrialFixITIComponents:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    TrialFixITIClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
    frameN = -1
    
    # -------Run Routine "TrialFixITI"-------
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = TrialFixITIClock.getTime()
        tThisFlip = win.getFutureFlipTime(clock=TrialFixITIClock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *TrialFixation* updates
        if TrialFixation.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            TrialFixation.frameNStart = frameN  # exact frame index
            TrialFixation.tStart = t  # local t and not account for scr refresh
            TrialFixation.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(TrialFixation, 'tStartRefresh')  # time at next scr refresh
            TrialFixation.setAutoDraw(True)
        if TrialFixation.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > TrialFixation.tStartRefresh + .1-frameTolerance:
                # keep track of stop time/frame for later
                TrialFixation.tStop = t  # not accounting for scr refresh
                TrialFixation.frameNStop = frameN  # exact frame index
                win.timeOnFlip(TrialFixation, 'tStopRefresh')  # time at next scr refresh
                TrialFixation.setAutoDraw(False)
        
        # *TrialFixation2* updates
        if TrialFixation2.status == NOT_STARTED and tThisFlip >= 0.1-frameTolerance:
            # keep track of start time/frame for later
            TrialFixation2.frameNStart = frameN  # exact frame index
            TrialFixation2.tStart = t  # local t and not account for scr refresh
            TrialFixation2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(TrialFixation2, 'tStartRefresh')  # time at next scr refresh
            TrialFixation2.setAutoDraw(True)
        if TrialFixation2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > TrialFixation2.tStartRefresh + .15-frameTolerance:
                # keep track of stop time/frame for later
                TrialFixation2.tStop = t  # not accounting for scr refresh
                TrialFixation2.frameNStop = frameN  # exact frame index
                win.timeOnFlip(TrialFixation2, 'tStopRefresh')  # time at next scr refresh
                TrialFixation2.setAutoDraw(False)
        
        # *TrialFixation3* updates
        if TrialFixation3.status == NOT_STARTED and tThisFlip >= 0.25-frameTolerance:
            # keep track of start time/frame for later
            TrialFixation3.frameNStart = frameN  # exact frame index
            TrialFixation3.tStart = t  # local t and not account for scr refresh
            TrialFixation3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(TrialFixation3, 'tStartRefresh')  # time at next scr refresh
            TrialFixation3.setAutoDraw(True)
        if TrialFixation3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > TrialFixation3.tStartRefresh + .15-frameTolerance:
                # keep track of stop time/frame for later
                TrialFixation3.tStop = t  # not accounting for scr refresh
                TrialFixation3.frameNStop = frameN  # exact frame index
                win.timeOnFlip(TrialFixation3, 'tStopRefresh')  # time at next scr refresh
                TrialFixation3.setAutoDraw(False)
        
        # *TrialFixation4* updates
        if TrialFixation4.status == NOT_STARTED and tThisFlip >= .4-frameTolerance:
            # keep track of start time/frame for later
            TrialFixation4.frameNStart = frameN  # exact frame index
            TrialFixation4.tStart = t  # local t and not account for scr refresh
            TrialFixation4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(TrialFixation4, 'tStartRefresh')  # time at next scr refresh
            TrialFixation4.setAutoDraw(True)
        if TrialFixation4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > TrialFixation4.tStartRefresh + .1-frameTolerance:
                # keep track of stop time/frame for later
                TrialFixation4.tStop = t  # not accounting for scr refresh
                TrialFixation4.frameNStop = frameN  # exact frame index
                win.timeOnFlip(TrialFixation4, 'tStopRefresh')  # time at next scr refresh
                TrialFixation4.setAutoDraw(False)
        
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in TrialFixITIComponents:
            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 "TrialFixITI"-------
    for thisComponent in TrialFixITIComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    trial_block.addData('TrialFixation.started', TrialFixation.tStartRefresh)
    trial_block.addData('TrialFixation.stopped', TrialFixation.tStopRefresh)
    trial_block.addData('TrialFixation2.started', TrialFixation2.tStartRefresh)
    trial_block.addData('TrialFixation2.stopped', TrialFixation2.tStopRefresh)
    trial_block.addData('TrialFixation3.started', TrialFixation3.tStartRefresh)
    trial_block.addData('TrialFixation3.stopped', TrialFixation3.tStopRefresh)
    trial_block.addData('TrialFixation4.started', TrialFixation4.tStartRefresh)
    trial_block.addData('TrialFixation4.stopped', TrialFixation4.tStopRefresh)
    
    # ------Prepare to start Routine "Dot"-------
    continueRoutine = True
    routineTimer.add(5.000000)
    # update component parameters for each repeat
    Obj1.setPos(Obj1_Loc)
    Obj1.setImage(Obj1_IMG)
    Obj2.setPos(Obj2_Loc)
    Obj2.setImage(Obj2_IMG)
    Obj3.setPos(Obj3_Loc)
    Obj3.setImage(Obj3_IMG)
    Obj4.setPos(Obj4_Loc)
    Obj4.setImage(Obj4_IMG)
    Obj5.setPos(Obj5_Loc)
    Obj5.setImage(Obj5_IMG)
    Obj6.setPos(Obj6_Loc)
    Obj6.setImage(Obj6_IMG)
    Obj7.setPos(Obj7_Loc)
    Obj7.setImage(Obj7_IMG)
    Obj8.setPos(Obj8_Loc)
    Obj8.setImage(Obj8_IMG)
    Obj9.setPos(Obj9_Loc)
    Obj9.setImage(Obj9_IMG)
    Face.setOpacity(FaceOpacity)
    Face.setPos(FaceLoc)
    Butterfly.setPos(ButterflyLoc)
    Butterfly.setImage(Butterfly_IMG)
    # keep track of which components have finished
    DotComponents = [Grid, Obj1, Obj2, Obj3, Obj4, Obj5, Obj6, Obj7, Obj8, Obj9, Face, Butterfly]
    for thisComponent in DotComponents:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    DotClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
    frameN = -1
    
    # -------Run Routine "Dot"-------
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = DotClock.getTime()
        tThisFlip = win.getFutureFlipTime(clock=DotClock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *Grid* updates
        if Grid.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Grid.frameNStart = frameN  # exact frame index
            Grid.tStart = t  # local t and not account for scr refresh
            Grid.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Grid, 'tStartRefresh')  # time at next scr refresh
            Grid.setAutoDraw(True)
        if Grid.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Grid.tStartRefresh + 1.0-frameTolerance:
                # keep track of stop time/frame for later
                Grid.tStop = t  # not accounting for scr refresh
                Grid.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Grid, 'tStopRefresh')  # time at next scr refresh
                Grid.setAutoDraw(False)
        
        # *Obj1* updates
        if Obj1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj1.frameNStart = frameN  # exact frame index
            Obj1.tStart = t  # local t and not account for scr refresh
            Obj1.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj1, 'tStartRefresh')  # time at next scr refresh
            Obj1.setAutoDraw(True)
        if Obj1.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj1.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj1.tStop = t  # not accounting for scr refresh
                Obj1.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj1, 'tStopRefresh')  # time at next scr refresh
                Obj1.setAutoDraw(False)
        
        # *Obj2* updates
        if Obj2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj2.frameNStart = frameN  # exact frame index
            Obj2.tStart = t  # local t and not account for scr refresh
            Obj2.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj2, 'tStartRefresh')  # time at next scr refresh
            Obj2.setAutoDraw(True)
        if Obj2.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj2.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj2.tStop = t  # not accounting for scr refresh
                Obj2.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj2, 'tStopRefresh')  # time at next scr refresh
                Obj2.setAutoDraw(False)
        
        # *Obj3* updates
        if Obj3.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj3.frameNStart = frameN  # exact frame index
            Obj3.tStart = t  # local t and not account for scr refresh
            Obj3.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj3, 'tStartRefresh')  # time at next scr refresh
            Obj3.setAutoDraw(True)
        if Obj3.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj3.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj3.tStop = t  # not accounting for scr refresh
                Obj3.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj3, 'tStopRefresh')  # time at next scr refresh
                Obj3.setAutoDraw(False)
        
        # *Obj4* updates
        if Obj4.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj4.frameNStart = frameN  # exact frame index
            Obj4.tStart = t  # local t and not account for scr refresh
            Obj4.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj4, 'tStartRefresh')  # time at next scr refresh
            Obj4.setAutoDraw(True)
        if Obj4.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj4.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj4.tStop = t  # not accounting for scr refresh
                Obj4.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj4, 'tStopRefresh')  # time at next scr refresh
                Obj4.setAutoDraw(False)
        
        # *Obj5* updates
        if Obj5.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj5.frameNStart = frameN  # exact frame index
            Obj5.tStart = t  # local t and not account for scr refresh
            Obj5.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj5, 'tStartRefresh')  # time at next scr refresh
            Obj5.setAutoDraw(True)
        if Obj5.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj5.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj5.tStop = t  # not accounting for scr refresh
                Obj5.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj5, 'tStopRefresh')  # time at next scr refresh
                Obj5.setAutoDraw(False)
        
        # *Obj6* updates
        if Obj6.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj6.frameNStart = frameN  # exact frame index
            Obj6.tStart = t  # local t and not account for scr refresh
            Obj6.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj6, 'tStartRefresh')  # time at next scr refresh
            Obj6.setAutoDraw(True)
        if Obj6.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj6.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj6.tStop = t  # not accounting for scr refresh
                Obj6.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj6, 'tStopRefresh')  # time at next scr refresh
                Obj6.setAutoDraw(False)
        
        # *Obj7* updates
        if Obj7.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj7.frameNStart = frameN  # exact frame index
            Obj7.tStart = t  # local t and not account for scr refresh
            Obj7.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj7, 'tStartRefresh')  # time at next scr refresh
            Obj7.setAutoDraw(True)
        if Obj7.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj7.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj7.tStop = t  # not accounting for scr refresh
                Obj7.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj7, 'tStopRefresh')  # time at next scr refresh
                Obj7.setAutoDraw(False)
        
        # *Obj8* updates
        if Obj8.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj8.frameNStart = frameN  # exact frame index
            Obj8.tStart = t  # local t and not account for scr refresh
            Obj8.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj8, 'tStartRefresh')  # time at next scr refresh
            Obj8.setAutoDraw(True)
        if Obj8.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj8.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj8.tStop = t  # not accounting for scr refresh
                Obj8.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj8, 'tStopRefresh')  # time at next scr refresh
                Obj8.setAutoDraw(False)
        
        # *Obj9* updates
        if Obj9.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Obj9.frameNStart = frameN  # exact frame index
            Obj9.tStart = t  # local t and not account for scr refresh
            Obj9.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Obj9, 'tStartRefresh')  # time at next scr refresh
            Obj9.setAutoDraw(True)
        if Obj9.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Obj9.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Obj9.tStop = t  # not accounting for scr refresh
                Obj9.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Obj9, 'tStopRefresh')  # time at next scr refresh
                Obj9.setAutoDraw(False)
        
        # *Face* updates
        if Face.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Face.frameNStart = frameN  # exact frame index
            Face.tStart = t  # local t and not account for scr refresh
            Face.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Face, 'tStartRefresh')  # time at next scr refresh
            Face.setAutoDraw(True)
        if Face.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Face.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Face.tStop = t  # not accounting for scr refresh
                Face.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Face, 'tStopRefresh')  # time at next scr refresh
                Face.setAutoDraw(False)
        
        # *Butterfly* updates
        if Butterfly.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            Butterfly.frameNStart = frameN  # exact frame index
            Butterfly.tStart = t  # local t and not account for scr refresh
            Butterfly.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(Butterfly, 'tStartRefresh')  # time at next scr refresh
            Butterfly.setAutoDraw(True)
        if Butterfly.status == STARTED:
            # is it time to stop? (based on global clock, using actual start)
            if tThisFlipGlobal > Butterfly.tStartRefresh + 5-frameTolerance:
                # keep track of stop time/frame for later
                Butterfly.tStop = t  # not accounting for scr refresh
                Butterfly.frameNStop = frameN  # exact frame index
                win.timeOnFlip(Butterfly, 'tStopRefresh')  # time at next scr refresh
                Butterfly.setAutoDraw(False)
        
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in DotComponents:
            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 "Dot"-------
    for thisComponent in DotComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    trial_block.addData('Grid.started', Grid.tStartRefresh)
    trial_block.addData('Grid.stopped', Grid.tStopRefresh)
    trial_block.addData('Obj1.started', Obj1.tStartRefresh)
    trial_block.addData('Obj1.stopped', Obj1.tStopRefresh)
    trial_block.addData('Obj2.started', Obj2.tStartRefresh)
    trial_block.addData('Obj2.stopped', Obj2.tStopRefresh)
    trial_block.addData('Obj3.started', Obj3.tStartRefresh)
    trial_block.addData('Obj3.stopped', Obj3.tStopRefresh)
    trial_block.addData('Obj4.started', Obj4.tStartRefresh)
    trial_block.addData('Obj4.stopped', Obj4.tStopRefresh)
    trial_block.addData('Obj5.started', Obj5.tStartRefresh)
    trial_block.addData('Obj5.stopped', Obj5.tStopRefresh)
    trial_block.addData('Obj6.started', Obj6.tStartRefresh)
    trial_block.addData('Obj6.stopped', Obj6.tStopRefresh)
    trial_block.addData('Obj7.started', Obj7.tStartRefresh)
    trial_block.addData('Obj7.stopped', Obj7.tStopRefresh)
    trial_block.addData('Obj8.started', Obj8.tStartRefresh)
    trial_block.addData('Obj8.stopped', Obj8.tStopRefresh)
    trial_block.addData('Obj9.started', Obj9.tStartRefresh)
    trial_block.addData('Obj9.stopped', Obj9.tStopRefresh)
    trial_block.addData('Face.started', Face.tStartRefresh)
    trial_block.addData('Face.stopped', Face.tStopRefresh)
    trial_block.addData('Butterfly.started', Butterfly.tStartRefresh)
    trial_block.addData('Butterfly.stopped', Butterfly.tStopRefresh)
    thisExp.nextEntry()
    
# completed 1 repeats of 'trial_block'

# get names of stimulus parameters
if trial_block.trialList in ([], [None], None):
    params = []
else:
    params = trial_block.trialList[0].keys()
# save data for this loop
trial_block.saveAsExcel(filename + '.xlsx', sheetName='trial_block',
    stimOut=params,
    dataOut=['n','all_mean','all_std', 'all_raw'])
trial_block.saveAsText(filename + 'trial_block.csv', delim=',',
    stimOut=params,
    dataOut=['n','all_mean','all_std', 'all_raw'])

# Flip one final time so any remaining win.callOnFlip() 
# and win.timeOnFlip() tasks get executed before quitting
win.flip()

# 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()