Created
March 16, 2015 21:32
-
-
Save kastman/fa1adbaf95da1d65c175 to your computer and use it in GitHub Desktop.
launchScanTest
This file contains 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.81.03), Mon Mar 16 17:19:06 2015 | |
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 | |
# 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 | |
expName = 'launchScanTest' # from the Builder filename that created this script | |
expInfo = {u'session': u'001', u'participant': u''} | |
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 + '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=u'/Users/kastman/Desktop/launchScanTest.psyexp', | |
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=(1920, 1080), 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() | |
# Initialize components for Routine "instr" | |
instrClock = core.Clock() | |
doneText = visual.TextStim(win=win, ori=0, name='doneText', | |
text='You made it!', font='Arial', | |
pos=[0, 0], height=0.1, wrapWidth=None, | |
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 "trial"------- | |
t = 0 | |
trialClock.reset() # clock | |
frameN = -1 | |
# update component parameters for each repeat | |
from psychopy.hardware.emulator import launchScan | |
settings = dict( | |
sync='equal', | |
skip=5, | |
TR=2, | |
volumes=200 | |
) | |
scan = launchScan(win, settings) | |
# keep track of which components have finished | |
trialComponents = [] | |
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 | |
# 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) | |
# the Routine "trial" was not non-slip safe, so reset the non-slip timer | |
routineTimer.reset() | |
#------Prepare to start Routine "instr"------- | |
t = 0 | |
instrClock.reset() # clock | |
frameN = -1 | |
routineTimer.add(1.000000) | |
# update component parameters for each repeat | |
# keep track of which components have finished | |
instrComponents = [] | |
instrComponents.append(doneText) | |
for thisComponent in instrComponents: | |
if hasattr(thisComponent, 'status'): | |
thisComponent.status = NOT_STARTED | |
#-------Start Routine "instr"------- | |
continueRoutine = True | |
while continueRoutine and routineTimer.getTime() > 0: | |
# get current time | |
t = instrClock.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 # underestimates by a little under one frame | |
doneText.frameNStart = frameN # exact frame index | |
doneText.setAutoDraw(True) | |
if doneText.status == STARTED and t >= (0.0 + (1.0-win.monitorFramePeriod*0.75)): #most of one frame period left | |
doneText.setAutoDraw(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 instrComponents: | |
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 "instr"------- | |
for thisComponent in instrComponents: | |
if hasattr(thisComponent, "setAutoDraw"): | |
thisComponent.setAutoDraw(False) | |
win.close() | |
core.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment