FaceDiscrimiationTaskPilot.py 28.5 KB
Newer Older
Visual Cognition Lab's avatar
Visual Cognition Lab committed
1 2 3 4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v3.0.5),
Visual Cognition Lab's avatar
Visual Cognition Lab committed
5
    on Tue Apr 30 11:39:58 2019
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
If you publish work using this script please cite the PsychoPy publications:
    Peirce, JW (2007) PsychoPy - Psychophysics software in Python.
        Journal of Neuroscience Methods, 162(1-2), 8-13.
    Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy.
        Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"""

from __future__ import absolute_import, division
from psychopy import locale_setup, 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


# 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 = '3.0.5'
Visual Cognition Lab's avatar
Visual Cognition Lab committed
31
expName = '2WorkingTest'  # from the Builder filename that created this script
Visual Cognition Lab's avatar
Visual Cognition Lab committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, 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/%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,
Visual Cognition Lab's avatar
Visual Cognition Lab committed
46
    originPath='/Users/Anna/Desktop/Working Test/2WorkingTest_lastrun.py',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
47 48 49 50 51 52
    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

Visual Cognition Lab's avatar
Visual Cognition Lab committed
53 54
endExpNow = False  # flag for 'escape' or other condition => quit the exp

Visual Cognition Lab's avatar
Visual Cognition Lab committed
55 56 57 58
# Start Code - component code to be run before the window creation

# Setup the Window
win = visual.Window(
Visual Cognition Lab's avatar
Visual Cognition Lab committed
59 60 61
    size=[1440, 900], fullscr=False, screen=0,
    allowGUI=True, allowStencil=False,
    monitor='testMonitor', color=[-1,-1,-1], colorSpace='rgb',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
62 63 64 65 66 67 68 69 70 71 72 73
    blendMode='avg', useFBO=True,
    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

# Initialize components for Routine "Instra1"
Instra1Clock = core.Clock()
text = visual.TextStim(win=win, name='text',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
74
    text='In each trial, two photos of faces will be displayed on your screen for a limited amount of time. Please indicate if the photos are of the same person or different people. \n \nPress  0 for same and 1 for different.\n\nClick the SPACE BAR to begin',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
    font='Arial',
    pos=(0,0), height=0.03, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);

# Initialize components for Routine "image"
imageClock = core.Clock()
Image = visual.ImageStim(
    win=win, name='Image',
    image='sin', mask=None,
    ori=0, pos=(0, 0), size=None,
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)

# Initialize components for Routine "Mask"
MaskClock = core.Clock()
mask = visual.ImageStim(
    win=win, name='mask',
    image='sin', mask=None,
    ori=0, pos=(0, 0), size=None,
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)

# Initialize components for Routine "Resp"
RespClock = core.Clock()
text_3 = visual.TextStim(win=win, name='text_3',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
104
    text='1=SAME 0=DIFFERENT',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
105 106 107 108 109 110
    font='Arial',
    pos=(0,0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);

Visual Cognition Lab's avatar
Visual Cognition Lab committed
111 112 113
# Initialize components for Routine "Space"
SpaceClock = core.Clock()
text_8 = visual.TextStim(win=win, name='text_8',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
114
    text="Press the space bar when you're ready for the next trial. ",
Visual Cognition Lab's avatar
Visual Cognition Lab committed
115 116 117 118 119 120
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);

Visual Cognition Lab's avatar
Visual Cognition Lab committed
121 122 123
# Initialize components for Routine "Debrief"
DebriefClock = core.Clock()
text_2 = visual.TextStim(win=win, name='text_2',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
124
    text='This will be the debriefing.\n\nCLICK THE SPACE BAR TO RECEiVE YOUR MTURK COMPLETION CODE.',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
125 126 127 128 129 130 131 132
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);

# Initialize components for Routine "numgen"
numgenClock = core.Clock()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
133
val_num = visual.TextStim(win=win, name='val_num',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
134 135
    text='default text',
    font='Arial',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
136
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
Visual Cognition Lab's avatar
Visual Cognition Lab committed
137 138 139 140 141 142 143 144
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
mturk = randint(1000000,9999999)
thisExp.addData("mturk", mturk)
text_5 = visual.TextStim(win=win, name='text_5',
    text='This is your mturk completion code:',
    font='Arial',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
145
    pos=(0, .2), height=0.1, wrapWidth=None, ori=0, 
Visual Cognition Lab's avatar
Visual Cognition Lab committed
146 147 148 149
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-2.0);
text_6 = visual.TextStim(win=win, name='text_6',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
150
    text='NOTE: Write down this number now as it will no longer be available when you click esc to close out of the experiment.',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
151
    font='Arial',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
152
    pos=(0, -.1), height=0.03, wrapWidth=None, ori=0, 
Visual Cognition Lab's avatar
Visual Cognition Lab committed
153 154 155
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-3.0);
Visual Cognition Lab's avatar
Visual Cognition Lab committed
156
text_7 = visual.TextStim(win=win, name='text_7',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
157
    text='In order to receive payment...',
Visual Cognition Lab's avatar
Visual Cognition Lab committed
158 159 160 161 162 163 164 165 166 167 168 169
    font='Arial',
    pos=(0, -.25), height=0.05, wrapWidth=None, ori=0, 
    color='red', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-4.0);
text_4 = visual.TextStim(win=win, name='text_4',
    text='Click the escape key (esc) *twice*\n1st click: exit full screen\n2nd click: submit and save data\n',
    font='Arial',
    pos=(0, -.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-5.0);
Visual Cognition Lab's avatar
Visual Cognition Lab committed
170 171 172 173 174 175 176 177 178 179 180

# 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 "Instra1"-------
t = 0
Instra1Clock.reset()  # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
Visual Cognition Lab's avatar
Visual Cognition Lab committed
181
key_resp_instra = event.BuilderKeyResponse()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
182
# keep track of which components have finished
Visual Cognition Lab's avatar
Visual Cognition Lab committed
183
Instra1Components = [text, key_resp_instra]
Visual Cognition Lab's avatar
Visual Cognition Lab committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
for thisComponent in Instra1Components:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

# -------Start Routine "Instra1"-------
while continueRoutine:
    # get current time
    t = Instra1Clock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *text* updates
    if t >= 0.0 and text.status == NOT_STARTED:
        # keep track of start time/frame for later
        text.tStart = t
        text.frameNStart = frameN  # exact frame index
        text.setAutoDraw(True)
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
202 203
    # *key_resp_instra* updates
    if t >= 0.0 and key_resp_instra.status == NOT_STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
204
        # keep track of start time/frame for later
Visual Cognition Lab's avatar
Visual Cognition Lab committed
205 206 207
        key_resp_instra.tStart = t
        key_resp_instra.frameNStart = frameN  # exact frame index
        key_resp_instra.status = STARTED
Visual Cognition Lab's avatar
Visual Cognition Lab committed
208
        # keyboard checking is just starting
Visual Cognition Lab's avatar
Visual Cognition Lab committed
209
        win.callOnFlip(key_resp_instra.clock.reset)  # t=0 on next screen flip
Visual Cognition Lab's avatar
Visual Cognition Lab committed
210
        event.clearEvents(eventType='keyboard')
Visual Cognition Lab's avatar
Visual Cognition Lab committed
211
    if key_resp_instra.status == STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
212
        theseKeys = event.getKeys(keyList=['space'])
Visual Cognition Lab's avatar
Visual Cognition Lab committed
213 214 215 216
        
        # check for quit:
        if "escape" in theseKeys:
            endExpNow = True
Visual Cognition Lab's avatar
Visual Cognition Lab committed
217
        if len(theseKeys) > 0:  # at least one key was pressed
Visual Cognition Lab's avatar
Visual Cognition Lab committed
218 219
            key_resp_instra.keys = theseKeys[-1]  # just the last key pressed
            key_resp_instra.rt = key_resp_instra.clock.getTime()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
220 221 222
            # a response ends the routine
            continueRoutine = False
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
223 224 225 226
    # check for quit (typically the Esc key)
    if endExpNow or event.getKeys(keyList=["escape"]):
        core.quit()
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
    # 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 Instra1Components:
        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 "Instra1"-------
for thisComponent in Instra1Components:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
# check responses
Visual Cognition Lab's avatar
Visual Cognition Lab committed
245 246 247 248 249
if key_resp_instra.keys in ['', [], None]:  # No response was made
    key_resp_instra.keys=None
thisExp.addData('key_resp_instra.keys',key_resp_instra.keys)
if key_resp_instra.keys != None:  # we had a response
    thisExp.addData('key_resp_instra.rt', key_resp_instra.rt)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
thisExp.nextEntry()
# the Routine "Instra1" 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('trialTypes4.csv'),
    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 "image"-------
    t = 0
    imageClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    # update component parameters for each repeat
    Image.setImage(stimFile)
    # keep track of which components have finished
    imageComponents = [Image]
    for thisComponent in imageComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "image"-------
    while continueRoutine:
        # get current time
        t = imageClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *Image* updates
        if t >= 0.0 and Image.status == NOT_STARTED:
            # keep track of start time/frame for later
            Image.tStart = t
            Image.frameNStart = frameN  # exact frame index
            Image.setAutoDraw(True)
        frameRemains = 0.0 + imagetime- win.monitorFramePeriod * 0.75  # most of one frame period left
        if Image.status == STARTED and t >= frameRemains:
            Image.setAutoDraw(False)
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
303 304 305 306
        # check for quit (typically the Esc key)
        if endExpNow or event.getKeys(keyList=["escape"]):
            core.quit()
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
        # 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 imageComponents:
            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 "image"-------
    for thisComponent in imageComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # the Routine "image" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    
    # ------Prepare to start Routine "Mask"-------
    t = 0
    MaskClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    # update component parameters for each repeat
    mask.setImage(maskFile)
    # keep track of which components have finished
    MaskComponents = [mask]
    for thisComponent in MaskComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "Mask"-------
    while continueRoutine:
        # get current time
        t = MaskClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *mask* updates
        if t >= 0.0 and mask.status == NOT_STARTED:
            # keep track of start time/frame for later
            mask.tStart = t
            mask.frameNStart = frameN  # exact frame index
            mask.setAutoDraw(True)
        frameRemains = 0.0 + masktime- win.monitorFramePeriod * 0.75  # most of one frame period left
        if mask.status == STARTED and t >= frameRemains:
            mask.setAutoDraw(False)
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
357 358 359 360
        # check for quit (typically the Esc key)
        if endExpNow or event.getKeys(keyList=["escape"]):
            core.quit()
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
        # 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 MaskComponents:
            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 "Mask"-------
    for thisComponent in MaskComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # the Routine "Mask" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    
    # ------Prepare to start Routine "Resp"-------
    t = 0
    RespClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    # update component parameters for each repeat
Visual Cognition Lab's avatar
Visual Cognition Lab committed
387
    trial_key_resp_ = event.BuilderKeyResponse()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
388
    # keep track of which components have finished
Visual Cognition Lab's avatar
Visual Cognition Lab committed
389
    RespComponents = [trial_key_resp_, text_3]
Visual Cognition Lab's avatar
Visual Cognition Lab committed
390 391 392 393 394 395 396 397 398 399 400
    for thisComponent in RespComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "Resp"-------
    while continueRoutine:
        # get current time
        t = RespClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
401 402
        # *trial_key_resp_* updates
        if t >= 0.0 and trial_key_resp_.status == NOT_STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
403
            # keep track of start time/frame for later
Visual Cognition Lab's avatar
Visual Cognition Lab committed
404 405 406
            trial_key_resp_.tStart = t
            trial_key_resp_.frameNStart = frameN  # exact frame index
            trial_key_resp_.status = STARTED
Visual Cognition Lab's avatar
Visual Cognition Lab committed
407
            # keyboard checking is just starting
Visual Cognition Lab's avatar
Visual Cognition Lab committed
408 409
            win.callOnFlip(trial_key_resp_.clock.reset)  # t=0 on next screen flip
        if trial_key_resp_.status == STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
410
            theseKeys = event.getKeys(keyList=['0', '1'])
Visual Cognition Lab's avatar
Visual Cognition Lab committed
411 412 413 414
            
            # check for quit:
            if "escape" in theseKeys:
                endExpNow = True
Visual Cognition Lab's avatar
Visual Cognition Lab committed
415
            if len(theseKeys) > 0:  # at least one key was pressed
Visual Cognition Lab's avatar
Visual Cognition Lab committed
416 417
                trial_key_resp_.keys = theseKeys[-1]  # just the last key pressed
                trial_key_resp_.rt = trial_key_resp_.clock.getTime()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
418
                # was this 'correct'?
Visual Cognition Lab's avatar
Visual Cognition Lab committed
419 420
                if (trial_key_resp_.keys == str(corrAns)) or (trial_key_resp_.keys == corrAns):
                    trial_key_resp_.corr = 1
Visual Cognition Lab's avatar
Visual Cognition Lab committed
421
                else:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
422
                    trial_key_resp_.corr = 0
Visual Cognition Lab's avatar
Visual Cognition Lab committed
423 424 425 426 427 428 429 430 431 432
                # a response ends the routine
                continueRoutine = False
        
        # *text_3* updates
        if t >= 0.0 and text_3.status == NOT_STARTED:
            # keep track of start time/frame for later
            text_3.tStart = t
            text_3.frameNStart = frameN  # exact frame index
            text_3.setAutoDraw(True)
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
433 434 435 436
        # check for quit (typically the Esc key)
        if endExpNow or event.getKeys(keyList=["escape"]):
            core.quit()
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
        # 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 RespComponents:
            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 "Resp"-------
    for thisComponent in RespComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # check responses
Visual Cognition Lab's avatar
Visual Cognition Lab committed
455 456
    if trial_key_resp_.keys in ['', [], None]:  # No response was made
        trial_key_resp_.keys=None
Visual Cognition Lab's avatar
Visual Cognition Lab committed
457 458
        # was no response the correct answer?!
        if str(corrAns).lower() == 'none':
Visual Cognition Lab's avatar
Visual Cognition Lab committed
459
           trial_key_resp_.corr = 1;  # correct non-response
Visual Cognition Lab's avatar
Visual Cognition Lab committed
460
        else:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
461
           trial_key_resp_.corr = 0;  # failed to respond (incorrectly)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
462
    # store data for trials (TrialHandler)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
463 464 465 466
    trials.addData('trial_key_resp_.keys',trial_key_resp_.keys)
    trials.addData('trial_key_resp_.corr', trial_key_resp_.corr)
    if trial_key_resp_.keys != None:  # we had a response
        trials.addData('trial_key_resp_.rt', trial_key_resp_.rt)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
467 468
    # the Routine "Resp" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
469 470 471 472 473 474 475
    
    # ------Prepare to start Routine "Space"-------
    t = 0
    SpaceClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    # update component parameters for each repeat
Visual Cognition Lab's avatar
Visual Cognition Lab committed
476
    key_resp_pause = event.BuilderKeyResponse()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
477
    # keep track of which components have finished
Visual Cognition Lab's avatar
Visual Cognition Lab committed
478
    SpaceComponents = [key_resp_pause, text_8]
Visual Cognition Lab's avatar
Visual Cognition Lab committed
479 480 481 482 483 484 485 486 487 488 489
    for thisComponent in SpaceComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "Space"-------
    while continueRoutine:
        # get current time
        t = SpaceClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
Visual Cognition Lab's avatar
Visual Cognition Lab committed
490 491
        # *key_resp_pause* updates
        if t >= 0.0 and key_resp_pause.status == NOT_STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
492
            # keep track of start time/frame for later
Visual Cognition Lab's avatar
Visual Cognition Lab committed
493 494 495
            key_resp_pause.tStart = t
            key_resp_pause.frameNStart = frameN  # exact frame index
            key_resp_pause.status = STARTED
Visual Cognition Lab's avatar
Visual Cognition Lab committed
496
            # keyboard checking is just starting
Visual Cognition Lab's avatar
Visual Cognition Lab committed
497
            win.callOnFlip(key_resp_pause.clock.reset)  # t=0 on next screen flip
Visual Cognition Lab's avatar
Visual Cognition Lab committed
498
            event.clearEvents(eventType='keyboard')
Visual Cognition Lab's avatar
Visual Cognition Lab committed
499
        if key_resp_pause.status == STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
500 501 502 503 504 505
            theseKeys = event.getKeys(keyList=['space'])
            
            # check for quit:
            if "escape" in theseKeys:
                endExpNow = True
            if len(theseKeys) > 0:  # at least one key was pressed
Visual Cognition Lab's avatar
Visual Cognition Lab committed
506 507
                key_resp_pause.keys = theseKeys[-1]  # just the last key pressed
                key_resp_pause.rt = key_resp_pause.clock.getTime()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
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
                # a response ends the routine
                continueRoutine = False
        
        # *text_8* updates
        if t >= 0.0 and text_8.status == NOT_STARTED:
            # keep track of start time/frame for later
            text_8.tStart = t
            text_8.frameNStart = frameN  # exact frame index
            text_8.setAutoDraw(True)
        
        # check for quit (typically the Esc key)
        if endExpNow or event.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 SpaceComponents:
            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 "Space"-------
    for thisComponent in SpaceComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    # check responses
Visual Cognition Lab's avatar
Visual Cognition Lab committed
540 541 542 543 544
    if key_resp_pause.keys in ['', [], None]:  # No response was made
        key_resp_pause.keys=None
    trials.addData('key_resp_pause.keys',key_resp_pause.keys)
    if key_resp_pause.keys != None:  # we had a response
        trials.addData('key_resp_pause.rt', key_resp_pause.rt)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
545 546
    # the Routine "Space" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
547 548 549 550 551 552 553 554 555 556 557
    thisExp.nextEntry()
    
# completed 1 repeats of 'trials'


# ------Prepare to start Routine "Debrief"-------
t = 0
DebriefClock.reset()  # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
Visual Cognition Lab's avatar
Visual Cognition Lab committed
558
key_resp_debrief = event.BuilderKeyResponse()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
559
# keep track of which components have finished
Visual Cognition Lab's avatar
Visual Cognition Lab committed
560
DebriefComponents = [text_2, key_resp_debrief]
Visual Cognition Lab's avatar
Visual Cognition Lab committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
for thisComponent in DebriefComponents:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

# -------Start Routine "Debrief"-------
while continueRoutine:
    # get current time
    t = DebriefClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *text_2* updates
    if t >= 0.0 and text_2.status == NOT_STARTED:
        # keep track of start time/frame for later
        text_2.tStart = t
        text_2.frameNStart = frameN  # exact frame index
        text_2.setAutoDraw(True)
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
579 580
    # *key_resp_debrief* updates
    if t >= 0.0 and key_resp_debrief.status == NOT_STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
581
        # keep track of start time/frame for later
Visual Cognition Lab's avatar
Visual Cognition Lab committed
582 583 584
        key_resp_debrief.tStart = t
        key_resp_debrief.frameNStart = frameN  # exact frame index
        key_resp_debrief.status = STARTED
Visual Cognition Lab's avatar
Visual Cognition Lab committed
585
        # keyboard checking is just starting
Visual Cognition Lab's avatar
Visual Cognition Lab committed
586
        win.callOnFlip(key_resp_debrief.clock.reset)  # t=0 on next screen flip
Visual Cognition Lab's avatar
Visual Cognition Lab committed
587
        event.clearEvents(eventType='keyboard')
Visual Cognition Lab's avatar
Visual Cognition Lab committed
588
    if key_resp_debrief.status == STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
589
        theseKeys = event.getKeys(keyList=['space'])
Visual Cognition Lab's avatar
Visual Cognition Lab committed
590 591 592 593
        
        # check for quit:
        if "escape" in theseKeys:
            endExpNow = True
Visual Cognition Lab's avatar
Visual Cognition Lab committed
594
        if len(theseKeys) > 0:  # at least one key was pressed
Visual Cognition Lab's avatar
Visual Cognition Lab committed
595 596
            key_resp_debrief.keys = theseKeys[-1]  # just the last key pressed
            key_resp_debrief.rt = key_resp_debrief.clock.getTime()
Visual Cognition Lab's avatar
Visual Cognition Lab committed
597 598 599
            # a response ends the routine
            continueRoutine = False
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
600 601 602 603
    # check for quit (typically the Esc key)
    if endExpNow or event.getKeys(keyList=["escape"]):
        core.quit()
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
    # 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 DebriefComponents:
        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 "Debrief"-------
for thisComponent in DebriefComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
# check responses
Visual Cognition Lab's avatar
Visual Cognition Lab committed
622 623 624 625 626
if key_resp_debrief.keys in ['', [], None]:  # No response was made
    key_resp_debrief.keys=None
thisExp.addData('key_resp_debrief.keys',key_resp_debrief.keys)
if key_resp_debrief.keys != None:  # we had a response
    thisExp.addData('key_resp_debrief.rt', key_resp_debrief.rt)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
627 628 629 630 631 632 633 634 635 636
thisExp.nextEntry()
# the Routine "Debrief" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# ------Prepare to start Routine "numgen"-------
t = 0
numgenClock.reset()  # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
Visual Cognition Lab's avatar
Visual Cognition Lab committed
637
val_num.setText(mturk)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
638 639

# keep track of which components have finished
Visual Cognition Lab's avatar
Visual Cognition Lab committed
640
numgenComponents = [val_num, text_5, text_6, text_7, text_4]
Visual Cognition Lab's avatar
Visual Cognition Lab committed
641 642 643 644 645 646 647 648 649 650 651
for thisComponent in numgenComponents:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

# -------Start Routine "numgen"-------
while continueRoutine:
    # get current time
    t = numgenClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
652 653
    # *val_num* updates
    if t >= 0.0 and val_num.status == NOT_STARTED:
Visual Cognition Lab's avatar
Visual Cognition Lab committed
654
        # keep track of start time/frame for later
Visual Cognition Lab's avatar
Visual Cognition Lab committed
655 656 657
        val_num.tStart = t
        val_num.frameNStart = frameN  # exact frame index
        val_num.setAutoDraw(True)
Visual Cognition Lab's avatar
Visual Cognition Lab committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    
    
    # *text_5* updates
    if t >= 0.0 and text_5.status == NOT_STARTED:
        # keep track of start time/frame for later
        text_5.tStart = t
        text_5.frameNStart = frameN  # exact frame index
        text_5.setAutoDraw(True)
    
    # *text_6* updates
    if t >= 0.0 and text_6.status == NOT_STARTED:
        # keep track of start time/frame for later
        text_6.tStart = t
        text_6.frameNStart = frameN  # exact frame index
        text_6.setAutoDraw(True)
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687
    # *text_7* updates
    if t >= 0.0 and text_7.status == NOT_STARTED:
        # keep track of start time/frame for later
        text_7.tStart = t
        text_7.frameNStart = frameN  # exact frame index
        text_7.setAutoDraw(True)
    
    # *text_4* updates
    if t >= 0.0 and text_4.status == NOT_STARTED:
        # keep track of start time/frame for later
        text_4.tStart = t
        text_4.frameNStart = frameN  # exact frame index
        text_4.setAutoDraw(True)
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
688 689 690 691
    # check for quit (typically the Esc key)
    if endExpNow or event.getKeys(keyList=["escape"]):
        core.quit()
    
Visual Cognition Lab's avatar
Visual Cognition Lab committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
    # 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 numgenComponents:
        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 "numgen"-------
for thisComponent in numgenComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)

# the Routine "numgen" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

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