Skip to content

Instantly share code, notes, and snippets.

@cooperpellaton
Created March 3, 2018 06:00
Show Gist options
  • Save cooperpellaton/429f5f4833a52fba444364e2d95a0455 to your computer and use it in GitHub Desktop.
Save cooperpellaton/429f5f4833a52fba444364e2d95a0455 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy2 Experiment Builder (v1.84.2),
on Fri Mar 2 18:33:49 2018
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, gui, visual, core, data, event, logging, sound
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__)).decode(sys.getfilesystemencoding())
os.chdir(_thisDir)
# Store info about the experiment session
expName = 'postTestBETA' # from the Builder filename that created this script
expInfo = {u'session': u'001', u'participant': u''}
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
# 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,
originPath=None,
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.DEBUG)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
# Start Code - component code to be run before the window creation
# Setup the Window
win = visual.Window(
size=(1440, 900), fullscr=True, screen=0,
allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True)
# 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 "intro"
introClock = core.Clock()
introText = visual.TextStim(win=win, name='introText',
text='YOU WILL NOW VIEW ANOTHER SERIES OF WORDS. THESE ARE THE SAME WORDS YOU WERE ASKED TO REMEMBER DURING THE PREVIOUS SEGMENTS. WHEN YOU SEE THE WORD, YOU WILL AGAIN BE ASKED TO INDICATE WHETHER THIS WORD WAS ASSOCIATED WITH A PICTURE OF A FACE OR A PICTURE OF A HOUSE. AFTER SOME RESPONSES YOU MAY BE ASKED A FOLLOW UP QUESTION ASKING YOU MORE ABOUT THE IMAGE THAT WAS LINKED WITH THAT WORD. IF YOU DO NOT KNOW THE ANSWER, PLEASE MAKE YOUR BEST GUESS. YOU WILL HAVE 6 SECONDS PER QUESTION TO RESPOND, SO PLEASE TAKE YOUR TIME AND BE AS ACCURATE AS POSSIBLE. PLEASE PRESS THE SPACE BAR WHEN YOU ARE READY TO BEGIN.',
font='Arial',
pos=(0, 0), height=0.07, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=0.0);
#a thing for the trial loops
import random
#selectRows = [0,1,2,3,4]
selectRows = random.sample(range(1, 120),40)
#make choices based on the participant number
#first handle if it's not a number, and make it a num if it is.
pnum = expInfo[u'participant']
try:
participantNum = int(pnum)
input = "Stim/StimLists/StimListTest"+pnum+".xlsx"
except:
#if it's not a number, make it 1
participantNum = 1
input = "Stim/StimLists/StimListTest.xlsx"
finally:
if participantNum % 2 == 1:
fhOdd = True
e,f = 'd','k'
else:
fhOdd = False
e,f = 'k','d'
#Get handling for trial responses knocked out
#Display correct key for trials
if fhOdd == True:
recallKeyText = """"D" = BUILDING, "K" = FACE"""
else:
recallKeyText = """"D" = FACE, "K" = BUILDING"""
#Do the same for probes
#first instantiate questions and keys
houseProbe1 = "IS THIS A RESIDENTIAL OR A COMMERCIAL BUILDING?"
houseProbe2 = "IS THIS A ONE STORY OR A MULTISTORY BUILDING?"
houseProbe3 = "IS THIS A LIGHT COLORED OR DARK COLORED BUILDING?"
faceProbe1 = "IS THIS A MALE FACE OR A FEMALE FACE?"
faceProbe2 = "IS THIS PERSON A YOUNGER PERSON OR AN OLDER PERSON?"
faceProbe3 = "IS THIS PERSON WHITE OR NOT WHITE?"
#Next instantiate related keys based on even or odd
if fhOdd == True:
houseKey1 = """"D" = RESIDENTIAL, "K" = COMMERCIAL"""
houseKey2 = """"D" = ONE STORY, "K" = MULTISTORY"""
houseKey3 = """"D" = LIGHT, "K" = DARK"""
faceKey1 = """"D" = MALE, "K" = FEMALE"""
faceKey2 = """"D" = YOUNGER, "K" = OLDER"""
faceKey3 = """"D" = WHITE, "K" = NOT WHITE"""
else:
houseKey1 = """"D" = COMMERCIAL, "K" = RESIDENTIAL"""
houseKey2 = """"D" = MULTISTORY, "K" = ONE STORY"""
houseKey3 = """"D" = DARK, "K" = LIGHT"""
faceKey1 = """"D" = FEMALE, "K" = MALE"""
faceKey2 = """"D" = OLDER, "K" = YOUNGER"""
faceKey3 = """"D" = NOT WHITE, "K" = WHITE"""
#Now we'll establish pairs.
housePair1 = (houseProbe1, houseKey1)
housePair2 = (houseProbe2, houseKey2)
housePair3 = (houseProbe3, houseKey3)
facePair1 = (faceProbe1, faceKey1)
facePair2 = (faceProbe2, faceKey2)
facePair3 = (faceProbe3, faceKey3)
#Now we put them in a list so we can access them
houseList = [housePair1, housePair2, housePair3]
faceList = [facePair1, facePair2, facePair3]
#We want to be able to choose the correct key press in probe questions
#I dislike how hard-coded this is but it should work
def correctKey(associate, questionnum, correct):
if associate.upper() == "HOUSE":
if questionnum == 0:
if correct.upper() == "RESIDENTIAL":
return e
elif correct.upper() == "COMMERCIAL":
return f
elif questionnum == 1:
if correct.upper() == "ONE STORY":
return e
elif correct.upper() == "MULTISTORY":
return f
elif questionnum == 2:
if correct.upper() == "LIGHT":
return e
elif correct.upper() == "DARK":
return f
elif associate.upper() == "FACE":
if questionnum == 0:
if correct.upper() == "MALE":
return e
elif correct.upper() == "FEMALE":
return f
elif questionnum == 1:
if correct.upper() == "YOUNG":
return e
elif correct.upper() == "OLD":
return f
elif questionnum == 2:
if correct.upper() == "WHITE":
return e
elif correct.upper() == "NON WHITE":
return f
# Initialize components for Routine "trial"
trialClock = core.Clock()
prompt = visual.TextStim(win=win, name='prompt',
text='default text',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=0.0);
recallKey = visual.TextStim(win=win, name='recallKey',
text=recallKeyText,
font='Arial',
pos=(0, -0.7), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=-1.0);
# Initialize components for Routine "controlFlow"
controlFlowClock = core.Clock()
#instantiate some variables.
nRepsFace = 0
nRepsHouse = 0
pick = 0
passIn = ""
ask = ""
key = "keyStart"
stimData = []
probeCorrect = ""
# Initialize components for Routine "correctFace"
correctFaceClock = core.Clock()
askF = visual.TextStim(win=win, name='askF',
text='default text',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=0.0);
keyF = visual.TextStim(win=win, name='keyF',
text='default text',
font='Arial',
pos=(0, -0.7), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=-1.0);
# Initialize components for Routine "correctHouse"
correctHouseClock = core.Clock()
askH = visual.TextStim(win=win, name='askH',
text='default text',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=0.0);
keyH = visual.TextStim(win=win, name='keyH',
text='default text',
font='Arial',
pos=(0, -0.7), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
depth=-1.0);
# Initialize components for Routine "done"
doneClock = core.Clock()
doneText = visual.TextStim(win=win, name='doneText',
text='THE EXPERIMENT IS NOW COMPLETE. PLEASE RETURN THE COMPUTER TO THE RESEARCHER AND LET HIM OR HER KNOW THAT YOU ARE FINISHED. THANK YOU FOR YOUR PARTICIPATION. PRESS THE SPACE BAR TO EXIT THIS SCREEN. ',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
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 "intro"-------
t = 0
introClock.reset() # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
endIntro = event.BuilderKeyResponse()
# keep track of which components have finished
introComponents = [introText, endIntro]
for thisComponent in introComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "intro"-------
while continueRoutine:
# get current time
t = introClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *introText* updates
if t >= 0.0 and introText.status == NOT_STARTED:
# keep track of start time/frame for later
introText.tStart = t
introText.frameNStart = frameN # exact frame index
introText.setAutoDraw(True)
# *endIntro* updates
if t >= 0.0 and endIntro.status == NOT_STARTED:
# keep track of start time/frame for later
endIntro.tStart = t
endIntro.frameNStart = frameN # exact frame index
endIntro.status = STARTED
# keyboard checking is just starting
win.callOnFlip(endIntro.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if endIntro.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
endIntro.keys = theseKeys[-1] # just the last key pressed
endIntro.rt = endIntro.clock.getTime()
# a response ends the routine
continueRoutine = False
# 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 introComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "intro"-------
for thisComponent in introComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if endIntro.keys in ['', [], None]: # No response was made
endIntro.keys=None
thisExp.addData('endIntro.keys',endIntro.keys)
if endIntro.keys != None: # we had a response
thisExp.addData('endIntro.rt', endIntro.rt)
thisExp.nextEntry()
# the Routine "intro" 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(input, selection=selectRows),
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.keys():
exec(paramName + '= thisTrial.' + paramName)
for thisTrial in trials:
currentLoop = trials
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
for paramName in thisTrial.keys():
exec(paramName + '= thisTrial.' + paramName)
# ------Prepare to start Routine "trial"-------
t = 0
trialClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(7.000000)
# update component parameters for each repeat
prompt.setText(NOUN)
recallResp = event.BuilderKeyResponse()
#handle correct responses for trials
if ASSOCIATE.upper() == "HOUSE":
recallRespCorrect = e
elif ASSOCIATE.upper() == "FACE":
recallRespCorrect = f
# keep track of which components have finished
trialComponents = [prompt, recallKey, recallResp]
for thisComponent in trialComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "trial"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = trialClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *prompt* updates
if t >= 0.5 and prompt.status == NOT_STARTED:
# keep track of start time/frame for later
prompt.tStart = t
prompt.frameNStart = frameN # exact frame index
prompt.setAutoDraw(True)
frameRemains = 0.5 + 6.5- win.monitorFramePeriod * 0.75 # most of one frame period left
if prompt.status == STARTED and t >= frameRemains:
prompt.setAutoDraw(False)
# *recallKey* updates
if t >= 0.5 and recallKey.status == NOT_STARTED:
# keep track of start time/frame for later
recallKey.tStart = t
recallKey.frameNStart = frameN # exact frame index
recallKey.setAutoDraw(True)
frameRemains = 0.5 + 6.5- win.monitorFramePeriod * 0.75 # most of one frame period left
if recallKey.status == STARTED and t >= frameRemains:
recallKey.setAutoDraw(False)
# *recallResp* updates
if t >= 0.5 and recallResp.status == NOT_STARTED:
# keep track of start time/frame for later
recallResp.tStart = t
recallResp.frameNStart = frameN # exact frame index
recallResp.status = STARTED
# keyboard checking is just starting
win.callOnFlip(recallResp.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
frameRemains = 0.5 + 6.5- win.monitorFramePeriod * 0.75 # most of one frame period left
if recallResp.status == STARTED and t >= frameRemains:
recallResp.status = STOPPED
if recallResp.status == STARTED:
theseKeys = event.getKeys(keyList=['d', 'k'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
recallResp.keys = theseKeys[-1] # just the last key pressed
recallResp.rt = recallResp.clock.getTime()
# was this 'correct'?
if (recallResp.keys == str(recallRespCorrect)) or (recallResp.keys == recallRespCorrect):
recallResp.corr = 1
else:
recallResp.corr = 0
# a response ends the routine
continueRoutine = False
# 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
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# 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)
# check responses
if recallResp.keys in ['', [], None]: # No response was made
recallResp.keys=None
# was no response the correct answer?!
if str(recallRespCorrect).lower() == 'none':
recallResp.corr = 1 # correct non-response
else:
recallResp.corr = 0 # failed to respond (incorrectly)
# store data for trials (TrialHandler)
trials.addData('recallResp.keys',recallResp.keys)
trials.addData('recallResp.corr', recallResp.corr)
if recallResp.keys != None: # we had a response
trials.addData('recallResp.rt', recallResp.rt)
# ------Prepare to start Routine "controlFlow"-------
t = 0
controlFlowClock.reset() # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
#Tells us to select a random probe if participant responds correctly.
#Also tells us that if the associate is correctly identified as a face to select a face-related probe.
#If the associate is correctly identified as a house, randomly select a house-related probe.
if recallResp.corr == 1:
passIn = ASSOCIATE.upper()
pick = randint(0,2)
stimData = [MF_RC.upper(),YO_OM.upper(),WN_LD.upper()]
probeCorrect = correctKey(ASSOCIATE, pick, stimData[pick])
# print(ASSOCIATE)
if ASSOCIATE == "House":
nRepsHouse = 1
nRepsFace = 0
ask = houseList[pick][0]
key = houseList[pick][1]
elif ASSOCIATE == "Face":
nRepsFace = 1
nRepsHouse = 0
ask = faceList[pick][0]
key = faceList[pick][1]
#If answer is incorrect, skip follow up probes and move to next word stimulus.
else:
nRepsFace = 0
nRepsHouse = 0
# keep track of which components have finished
controlFlowComponents = []
for thisComponent in controlFlowComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "controlFlow"-------
while continueRoutine:
# get current time
t = controlFlowClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# 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 controlFlowComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "controlFlow"-------
for thisComponent in controlFlowComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "controlFlow" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# print(recallRespCorrect)
# print(theseKeys[-1])
# set up handler to look after randomisation of conditions etc
# print("starting face handler")
faceQ = data.TrialHandler(nReps=nRepsFace, method='random',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='faceQ')
thisExp.addLoop(faceQ) # add the loop to the experiment
thisFaceQ = faceQ.trialList[0] # so we can initialise stimuli with some values
# print(faceQ)
# abbreviate parameter names if possible (e.g. rgb = thisFaceQ.rgb)
if thisFaceQ != None:
for paramName in thisFaceQ.keys():
exec(paramName + '= thisFaceQ.' + paramName)
for thisFaceQ in faceQ:
currentLoop = faceQ
# abbreviate parameter names if possible (e.g. rgb = thisFaceQ.rgb)
if thisFaceQ != None:
for paramName in thisFaceQ.keys():
exec(paramName + '= thisFaceQ.' + paramName)
# ------Prepare to start Routine "correctFace"-------
#print("Correct Face routine running.")
t = 0
correctFaceClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(6.000000)
# update component parameters for each repeat
askF.setText(ask)
keyF.setText(key)
probeRespF = event.BuilderKeyResponse()
# keep track of which components have finished
correctFaceComponents = [askF, keyF, probeRespF]
for thisComponent in correctFaceComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "correctFace"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = correctFaceClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *askF* updates
if t >= 0.0 and askF.status == NOT_STARTED:
# keep track of start time/frame for later
askF.tStart = t
askF.frameNStart = frameN # exact frame index
askF.setAutoDraw(True)
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if askF.status == STARTED and t >= frameRemains:
askF.setAutoDraw(False)
# *keyF* updates
if t >= 0.0 and keyF.status == NOT_STARTED:
# keep track of start time/frame for later
keyF.tStart = t
keyF.frameNStart = frameN # exact frame index
keyF.setAutoDraw(True)
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if keyF.status == STARTED and t >= frameRemains:
keyF.setAutoDraw(False)
# *probeRespF* updates
if t >= 0.0 and probeRespF.status == NOT_STARTED:
# keep track of start time/frame for later
probeRespF.tStart = t
probeRespF.frameNStart = frameN # exact frame index
probeRespF.status = STARTED
# keyboard checking is just starting
win.callOnFlip(probeRespF.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if probeRespF.status == STARTED and t >= frameRemains:
probeRespF.status = STOPPED
if probeRespF.status == STARTED:
theseKeys = event.getKeys(keyList=['d', 'k'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
probeRespF.keys = theseKeys[-1] # just the last key pressed
probeRespF.rt = probeRespF.clock.getTime()
# was this 'correct'?
if (probeRespF.keys == str(probeCorrect)) or (probeRespF.keys == probeCorrect):
probeRespF.corr = 1
else:
probeRespF.corr = 0
# a response ends the routine
continueRoutine = False
# 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 correctFaceComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "correctFace"-------
for thisComponent in correctFaceComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if probeRespF.keys in ['', [], None]: # No response was made
probeRespF.keys=None
# was no response the correct answer?!
if str(probeCorrect).lower() == 'none':
probeRespF.corr = 1 # correct non-response
else:
probeRespF.corr = 0 # failed to respond (incorrectly)
# store data for faceQ (TrialHandler)
faceQ.addData('probeRespF.keys',probeRespF.keys)
faceQ.addData('probeRespF.corr', probeRespF.corr)
if probeRespF.keys != None: # we had a response
faceQ.addData('probeRespF.rt', probeRespF.rt)
faceQ.addData('probe', ask)
# completed nRepsFace repeats of 'faceQ'
# set up handler to look after randomisation of conditions etc
# print("starting house handler")
houseQ = data.TrialHandler(nReps=nRepsHouse, method='random',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='houseQ')
thisExp.addLoop(houseQ) # add the loop to the experiment
thisHouseQ = houseQ.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisHouseQ.rgb)
# print(houseQ)
if thisHouseQ != None:
for paramName in thisHouseQ.keys():
exec(paramName + '= thisHouseQ.' + paramName)
for thisHouseQ in houseQ:
currentLoop = houseQ
# abbreviate parameter names if possible (e.g. rgb = thisHouseQ.rgb)
if thisHouseQ != None:
for paramName in thisHouseQ.keys():
exec(paramName + '= thisHouseQ.' + paramName)
# ------Prepare to start Routine "correctHouse"-------
# print("Correct House routine running.")
t = 0
correctHouseClock.reset() # clock
frameN = -1
continueRoutine = True
routineTimer.add(6.000000)
# update component parameters for each repeat
askH.setText(ask)
keyH.setText(key)
probeRespH = event.BuilderKeyResponse()
# keep track of which components have finished
correctHouseComponents = [askH, keyH, probeRespH]
for thisComponent in correctHouseComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "correctHouse"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = correctHouseClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *askH* updates
if t >= 0.0 and askH.status == NOT_STARTED:
# keep track of start time/frame for later
askH.tStart = t
askH.frameNStart = frameN # exact frame index
askH.setAutoDraw(True)
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if askH.status == STARTED and t >= frameRemains:
askH.setAutoDraw(False)
# *keyH* updates
if t >= 0.0 and keyH.status == NOT_STARTED:
# keep track of start time/frame for later
keyH.tStart = t
keyH.frameNStart = frameN # exact frame index
keyH.setAutoDraw(True)
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if keyH.status == STARTED and t >= frameRemains:
keyH.setAutoDraw(False)
# *probeRespH* updates
if t >= 0.0 and probeRespH.status == NOT_STARTED:
# keep track of start time/frame for later
probeRespH.tStart = t
probeRespH.frameNStart = frameN # exact frame index
probeRespH.status = STARTED
# keyboard checking is just starting
win.callOnFlip(probeRespH.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
frameRemains = 0.0 + 6- win.monitorFramePeriod * 0.75 # most of one frame period left
if probeRespH.status == STARTED and t >= frameRemains:
probeRespH.status = STOPPED
if probeRespH.status == STARTED:
theseKeys = event.getKeys(keyList=['d', 'k'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
probeRespH.keys = theseKeys[-1] # just the last key pressed
probeRespH.rt = probeRespH.clock.getTime()
# was this 'correct'?
if (probeRespH.keys == str(probeCorrect)) or (probeRespH.keys == probeCorrect):
probeRespH.corr = 1
else:
probeRespH.corr = 0
# a response ends the routine
continueRoutine = False
# 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 correctHouseComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "correctHouse"-------
for thisComponent in correctHouseComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if probeRespH.keys in ['', [], None]: # No response was made
probeRespH.keys=None
# was no response the correct answer?!
if str(probeCorrect).lower() == 'none':
probeRespH.corr = 1 # correct non-response
else:
probeRespH.corr = 0 # failed to respond (incorrectly)
# store data for houseQ (TrialHandler)
houseQ.addData('probeRespH.keys',probeRespH.keys)
houseQ.addData('probeRespH.corr', probeRespH.corr)
if probeRespH.keys != None: # we had a response
houseQ.addData('probeRespH.rt', probeRespH.rt)
houseQ.addData('probe',ask)
# completed nRepsHouse repeats of 'houseQ'
thisExp.nextEntry()
# completed 1 repeats of 'trials'
# ------Prepare to start Routine "done"-------
t = 0
doneClock.reset() # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
endDone = event.BuilderKeyResponse()
# keep track of which components have finished
doneComponents = [doneText, endDone]
for thisComponent in doneComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "done"-------
while continueRoutine:
# get current time
t = doneClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *doneText* updates
if t >= 0.0 and doneText.status == NOT_STARTED:
# keep track of start time/frame for later
doneText.tStart = t
doneText.frameNStart = frameN # exact frame index
doneText.setAutoDraw(True)
# *endDone* updates
if t >= 0.0 and endDone.status == NOT_STARTED:
# keep track of start time/frame for later
endDone.tStart = t
endDone.frameNStart = frameN # exact frame index
endDone.status = STARTED
# keyboard checking is just starting
win.callOnFlip(endDone.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if endDone.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
endDone.keys = theseKeys[-1] # just the last key pressed
endDone.rt = endDone.clock.getTime()
# a response ends the routine
continueRoutine = False
# 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 doneComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "done"-------
for thisComponent in doneComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if endDone.keys in ['', [], None]: # No response was made
endDone.keys=None
thisExp.addData('endDone.keys',endDone.keys)
if endDone.keys != None: # we had a response
thisExp.addData('endDone.rt', endDone.rt)
thisExp.nextEntry()
# the Routine "done" 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment