Created
July 28, 2014 23:18
-
-
Save anonymous/a75bc3d479a6781462a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
""" | |
This experiment was created using PsychoPy2 Experiment Builder (v1.80.03), July 28, 2014, at 16:09 | |
If you publish work using this script please cite the relevant 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 division # so that 1/3=0.333 instead of 1/3=0 | |
from psychopy import visual, core, data, event, logging, sound, gui | |
from psychopy.constants import * # things like STARTED, FINISHED | |
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 | |
# Store info about the experiment session | |
expName = 'ButtonPushing' # 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 | |
# Setup filename for saving | |
filename = '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,gist | |
originPath=None, | |
savePickle=True, saveWideText=True, | |
dataFileName=filename) | |
#save a log file for detail verbose info | |
logFile = logging.LogFile(filename+'.log', level=logging.EXP) | |
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file | |
endExpNow = False # flag for 'escape' or other condition => quit the exp | |
# Start Code - component code to be run before the window creation | |
# Setup the Window | |
win = visual.Window(size=(1366, 768), 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 successfully | |
expInfo['frameRate']=win.getActualFrameRate() | |
if expInfo['frameRate']!=None: | |
frameDur = 1.0/round(expInfo['frameRate']) | |
else: | |
frameDur = 1.0/60.0 # couldn't get a reliable measure so guess | |
# Initialize components for Routine "trial" | |
trialClock = core.Clock() | |
image = visual.ImageStim(win=win, name='image', | |
image='sin', mask=None, | |
ori=0, pos=[0, 0], size=[0.5, 0.5], | |
color=[1,1,1], colorSpace=u'rgb', opacity=1, | |
flipHoriz=False, flipVert=False, | |
texRes=128, interpolate=False, depth=0.0) | |
# Initialize components for Routine "pause" | |
pauseClock = core.Clock() | |
ISI_2 = core.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='ISI_2') | |
# Initialize components for Routine "trial_2" | |
trial_2Clock = core.Clock() | |
image_2 = visual.ImageStim(win=win, name='image_2', | |
image='sin', mask=None, | |
ori=0, pos=[0, 0], size=[0.5, 0.5], | |
color=[1,1,1], colorSpace=u'rgb', opacity=1, | |
flipHoriz=False, flipVert=False, | |
texRes=128, interpolate=False, depth=0.0) | |
# Initialize components for Routine "pause" | |
pauseClock = core.Clock() | |
ISI_2 = core.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='ISI_2') | |
# 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 | |
RandomizedTrials = data.TrialHandler(nReps=5, method='random', | |
extraInfo=expInfo, originPath=None, | |
trialList=data.importConditions('RandomizeTest.xlsx'), | |
seed=None, name='RandomizedTrials') | |
thisExp.addLoop(RandomizedTrials) # add the loop to the experiment | |
thisRandomizedTrial = RandomizedTrials.trialList[0] # so we can initialise stimuli with some values | |
# abbreviate parameter names if possible (e.g. rgb=thisRandomizedTrial.rgb) | |
if thisRandomizedTrial != None: | |
for paramName in thisRandomizedTrial.keys(): | |
exec(paramName + '= thisRandomizedTrial.' + paramName) | |
for thisRandomizedTrial in RandomizedTrials: | |
currentLoop = RandomizedTrials | |
# abbreviate parameter names if possible (e.g. rgb = thisRandomizedTrial.rgb) | |
if thisRandomizedTrial != None: | |
for paramName in thisRandomizedTrial.keys(): | |
exec(paramName + '= thisRandomizedTrial.' + paramName) | |
# set up handler to look after randomisation of conditions etc | |
trials = data.TrialHandler(nReps=1, method='sequential', | |
extraInfo=expInfo, originPath=None, | |
trialList=[None], | |
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) | |
# set up handler to look after randomisation of conditions etc | |
Degradation1 = data.TrialHandler(nReps=1, method='sequential', | |
extraInfo=expInfo, originPath=None, | |
trialList=data.importConditions(ExcelName), | |
seed=None, name='Degradation1') | |
thisExp.addLoop(Degradation1) # add the loop to the experiment | |
thisDegradation1 = Degradation1.trialList[0] # so we can initialise stimuli with some values | |
# abbreviate parameter names if possible (e.g. rgb=thisDegradation1.rgb) | |
if thisDegradation1 != None: | |
for paramName in thisDegradation1.keys(): | |
exec(paramName + '= thisDegradation1.' + paramName) | |
for thisDegradation1 in Degradation1: | |
currentLoop = Degradation1 | |
# abbreviate parameter names if possible (e.g. rgb = thisDegradation1.rgb) | |
if thisDegradation1 != None: | |
for paramName in thisDegradation1.keys(): | |
exec(paramName + '= thisDegradation1.' + paramName) | |
#------Prepare to start Routine "trial"------- | |
t = 0 | |
trialClock.reset() # clock | |
frameN = -1 | |
# update component parameters for each repeat | |
image.setImage(Image) | |
key_resp_2 = event.BuilderKeyResponse() # create an object of type KeyResponse | |
key_resp_2.status = NOT_STARTED | |
# keep track of which components have finished | |
trialComponents = [] | |
trialComponents.append(image) | |
trialComponents.append(key_resp_2) | |
for thisComponent in trialComponents: | |
if hasattr(thisComponent, 'status'): | |
thisComponent.status = NOT_STARTED | |
#-------Start Routine "trial"------- | |
continueRoutine = True | |
while continueRoutine: | |
# 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 | |
# *image* updates | |
if t >= 0.0 and image.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
image.tStart = t # underestimates by a little under one frame | |
image.frameNStart = frameN # exact frame index | |
image.setAutoDraw(True) | |
# *key_resp_2* updates | |
if t >= 0.0 and key_resp_2.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
key_resp_2.tStart = t # underestimates by a little under one frame | |
key_resp_2.frameNStart = frameN # exact frame index | |
key_resp_2.status = STARTED | |
# keyboard checking is just starting | |
key_resp_2.clock.reset() # now t=0 | |
event.clearEvents(eventType='keyboard') | |
if key_resp_2.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 | |
key_resp_2.keys.extend(theseKeys) # storing all keys | |
key_resp_2.rt.append(key_resp_2.clock.getTime()) | |
# was this 'correct'? | |
if (key_resp_2.keys == str(u"'space'")) or (key_resp_2.keys == u"'space'"): | |
key_resp_2.corr = 1 | |
else: | |
key_resp_2.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 | |
routineTimer.reset() # if we abort early the non-slip timer needs reset | |
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() | |
else: # this Routine was not non-slip safe so reset non-slip timer | |
routineTimer.reset() | |
#-------Ending Routine "trial"------- | |
for thisComponent in trialComponents: | |
if hasattr(thisComponent, "setAutoDraw"): | |
thisComponent.setAutoDraw(False) | |
# check responses | |
if key_resp_2.keys in ['', [], None]: # No response was made | |
key_resp_2.keys=None | |
# was no response the correct answer?! | |
if str(u"'space'").lower() == 'none': key_resp_2.corr = 1 # correct non-response | |
else: key_resp_2.corr = 0 # failed to respond (incorrectly) | |
# store data for Degradation1 (TrialHandler) | |
Degradation1.addData('key_resp_2.keys',key_resp_2.keys) | |
Degradation1.addData('key_resp_2.corr', key_resp_2.corr) | |
if key_resp_2.keys != None: # we had a response | |
Degradation1.addData('key_resp_2.rt', key_resp_2.rt) | |
thisExp.nextEntry() | |
# completed 1 repeats of 'Degradation1' | |
thisExp.nextEntry() | |
# completed 1 repeats of 'trials' | |
#------Prepare to start Routine "pause"------- | |
t = 0 | |
pauseClock.reset() # clock | |
frameN = -1 | |
routineTimer.add(5.000000) | |
# update component parameters for each repeat | |
# keep track of which components have finished | |
pauseComponents = [] | |
pauseComponents.append(ISI_2) | |
for thisComponent in pauseComponents: | |
if hasattr(thisComponent, 'status'): | |
thisComponent.status = NOT_STARTED | |
#-------Start Routine "pause"------- | |
continueRoutine = True | |
while continueRoutine and routineTimer.getTime() > 0: | |
# get current time | |
t = pauseClock.getTime() | |
frameN = frameN + 1 # number of completed frames (so 0 is the first frame) | |
# update/draw components on each frame | |
# *ISI_2* period | |
if t >= 0.0 and ISI_2.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
ISI_2.tStart = t # underestimates by a little under one frame | |
ISI_2.frameNStart = frameN # exact frame index | |
ISI_2.start(5) | |
elif ISI_2.status == STARTED: #one frame should pass before updating params and completing | |
ISI_2.complete() #finish the static period | |
# check if all components have finished | |
if not continueRoutine: # a component has requested a forced-end of Routine | |
routineTimer.reset() # if we abort early the non-slip timer needs reset | |
break | |
continueRoutine = False # will revert to True if at least one component still running | |
for thisComponent in pauseComponents: | |
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 "pause"------- | |
for thisComponent in pauseComponents: | |
if hasattr(thisComponent, "setAutoDraw"): | |
thisComponent.setAutoDraw(False) | |
# set up handler to look after randomisation of conditions etc | |
trials_2 = data.TrialHandler(nReps=1, method='sequential', | |
extraInfo=expInfo, originPath=None, | |
trialList=[None], | |
seed=None, name='trials_2') | |
thisExp.addLoop(trials_2) # add the loop to the experiment | |
thisTrial_2 = trials_2.trialList[0] # so we can initialise stimuli with some values | |
# abbreviate parameter names if possible (e.g. rgb=thisTrial_2.rgb) | |
if thisTrial_2 != None: | |
for paramName in thisTrial_2.keys(): | |
exec(paramName + '= thisTrial_2.' + paramName) | |
for thisTrial_2 in trials_2: | |
currentLoop = trials_2 | |
# abbreviate parameter names if possible (e.g. rgb = thisTrial_2.rgb) | |
if thisTrial_2 != None: | |
for paramName in thisTrial_2.keys(): | |
exec(paramName + '= thisTrial_2.' + paramName) | |
# set up handler to look after randomisation of conditions etc | |
Degradation2 = data.TrialHandler(nReps=1, method='sequential', | |
extraInfo=expInfo, originPath=None, | |
trialList=data.importConditions(ExcelName), | |
seed=None, name='Degradation2') | |
thisExp.addLoop(Degradation2) # add the loop to the experiment | |
thisDegradation2 = Degradation2.trialList[0] # so we can initialise stimuli with some values | |
# abbreviate parameter names if possible (e.g. rgb=thisDegradation2.rgb) | |
if thisDegradation2 != None: | |
for paramName in thisDegradation2.keys(): | |
exec(paramName + '= thisDegradation2.' + paramName) | |
for thisDegradation2 in Degradation2: | |
currentLoop = Degradation2 | |
# abbreviate parameter names if possible (e.g. rgb = thisDegradation2.rgb) | |
if thisDegradation2 != None: | |
for paramName in thisDegradation2.keys(): | |
exec(paramName + '= thisDegradation2.' + paramName) | |
#------Prepare to start Routine "trial_2"------- | |
t = 0 | |
trial_2Clock.reset() # clock | |
frameN = -1 | |
# update component parameters for each repeat | |
image_2.setImage(Image) | |
key_resp_4 = event.BuilderKeyResponse() # create an object of type KeyResponse | |
key_resp_4.status = NOT_STARTED | |
# keep track of which components have finished | |
trial_2Components = [] | |
trial_2Components.append(image_2) | |
trial_2Components.append(key_resp_4) | |
for thisComponent in trial_2Components: | |
if hasattr(thisComponent, 'status'): | |
thisComponent.status = NOT_STARTED | |
#-------Start Routine "trial_2"------- | |
continueRoutine = True | |
while continueRoutine: | |
# get current time | |
t = trial_2Clock.getTime() | |
frameN = frameN + 1 # number of completed frames (so 0 is the first frame) | |
# update/draw components on each frame | |
# *image_2* updates | |
if t >= 0.0 and image_2.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
image_2.tStart = t # underestimates by a little under one frame | |
image_2.frameNStart = frameN # exact frame index | |
image_2.setAutoDraw(True) | |
# *key_resp_4* updates | |
if t >= 0.0 and key_resp_4.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
key_resp_4.tStart = t # underestimates by a little under one frame | |
key_resp_4.frameNStart = frameN # exact frame index | |
key_resp_4.status = STARTED | |
# keyboard checking is just starting | |
key_resp_4.clock.reset() # now t=0 | |
event.clearEvents(eventType='keyboard') | |
if key_resp_4.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 | |
key_resp_4.keys.extend(theseKeys) # storing all keys | |
key_resp_4.rt.append(key_resp_4.clock.getTime()) | |
# was this 'correct'? | |
if (key_resp_4.keys == str("'space'")) or (key_resp_4.keys == "'space'"): | |
key_resp_4.corr = 1 | |
else: | |
key_resp_4.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 | |
routineTimer.reset() # if we abort early the non-slip timer needs reset | |
break | |
continueRoutine = False # will revert to True if at least one component still running | |
for thisComponent in trial_2Components: | |
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() | |
else: # this Routine was not non-slip safe so reset non-slip timer | |
routineTimer.reset() | |
#-------Ending Routine "trial_2"------- | |
for thisComponent in trial_2Components: | |
if hasattr(thisComponent, "setAutoDraw"): | |
thisComponent.setAutoDraw(False) | |
# check responses | |
if key_resp_4.keys in ['', [], None]: # No response was made | |
key_resp_4.keys=None | |
# was no response the correct answer?! | |
if str("'space'").lower() == 'none': key_resp_4.corr = 1 # correct non-response | |
else: key_resp_4.corr = 0 # failed to respond (incorrectly) | |
# store data for Degradation2 (TrialHandler) | |
Degradation2.addData('key_resp_4.keys',key_resp_4.keys) | |
Degradation2.addData('key_resp_4.corr', key_resp_4.corr) | |
if key_resp_4.keys != None: # we had a response | |
Degradation2.addData('key_resp_4.rt', key_resp_4.rt) | |
thisExp.nextEntry() | |
# completed 1 repeats of 'Degradation2' | |
thisExp.nextEntry() | |
# completed 1 repeats of 'trials_2' | |
#------Prepare to start Routine "pause"------- | |
t = 0 | |
pauseClock.reset() # clock | |
frameN = -1 | |
routineTimer.add(5.000000) | |
# update component parameters for each repeat | |
# keep track of which components have finished | |
pauseComponents = [] | |
pauseComponents.append(ISI_2) | |
for thisComponent in pauseComponents: | |
if hasattr(thisComponent, 'status'): | |
thisComponent.status = NOT_STARTED | |
#-------Start Routine "pause"------- | |
continueRoutine = True | |
while continueRoutine and routineTimer.getTime() > 0: | |
# get current time | |
t = pauseClock.getTime() | |
frameN = frameN + 1 # number of completed frames (so 0 is the first frame) | |
# update/draw components on each frame | |
# *ISI_2* period | |
if t >= 0.0 and ISI_2.status == NOT_STARTED: | |
# keep track of start time/frame for later | |
ISI_2.tStart = t # underestimates by a little under one frame | |
ISI_2.frameNStart = frameN # exact frame index | |
ISI_2.start(5) | |
elif ISI_2.status == STARTED: #one frame should pass before updating params and completing | |
ISI_2.complete() #finish the static period | |
# check if all components have finished | |
if not continueRoutine: # a component has requested a forced-end of Routine | |
routineTimer.reset() # if we abort early the non-slip timer needs reset | |
break | |
continueRoutine = False # will revert to True if at least one component still running | |
for thisComponent in pauseComponents: | |
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 "pause"------- | |
for thisComponent in pauseComponents: | |
if hasattr(thisComponent, "setAutoDraw"): | |
thisComponent.setAutoDraw(False) | |
thisExp.nextEntry() | |
# completed 5 repeats of 'RandomizedTrials' | |
win.close() | |
core.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment