Skip to content

Instantly share code, notes, and snippets.

@jeremygray
Last active June 26, 2017 20:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremygray/9062586 to your computer and use it in GitHub Desktop.
Save jeremygray/9062586 to your computer and use it in GitHub Desktop.
PsychoPy timing test script. (public domain)
** If you haven't done so, you may need to unzip these files before attempting to run the experiment **
** All three files should be in the same directory, then run timeFrames.psyexp in PsychoPy 1.79 or later **
This PsychoPy experiment allows you to test the refresh timing of your screen at a variety of rates. Feel free to add a BlackBoxToolkit or simple photometer to the system to confirm that the physical times fall exactly as expected from the times reported here.
The key to good timing is that the stimuli are specified in terms of the number of frames rather than as a number of (milli)seconds. It is also helpful to reduce potential interference, and so turning off internet access and bluetooth, and quitting any extra software is recommended.
This experiment is not intended as a demo as such, and it does contain some code segments. These are designed to go and check exactly when the screen flipped for each stimulus onset/offset. These times can be viewed in the resulting data files (summarised in the data/----.xlsx file and given chronologically in the data/----.csv file).
PsychoPy, by default, generates a log file that contains a great deal of data (more than you would normally want to analyse) about the way that your experiment ran. This contains very precise timing information, also based on the screen refresh events that are used in this experiment.
You can easily change the number of trials (repeats) by clicking on the trials loop and you can easily change the durations tested by changing the trials.csv file.
<PsychoPy2experiment version="1.79.00" encoding="utf-8">
<Settings>
<Param name="Show mouse" val="False" valType="bool" updates="None"/>
<Param name="Save csv file" val="False" valType="bool" updates="None"/>
<Param name="Monitor" val="testMonitor" valType="str" updates="None"/>
<Param name="Enable Escape" val="True" valType="bool" updates="None"/>
<Param name="color" val="$[0,0,0]" valType="str" updates="None"/>
<Param name="Window size (pixels)" val="[1920, 1080]" valType="code" updates="None"/>
<Param name="Full-screen window" val="True" valType="bool" updates="None"/>
<Param name="colorSpace" val="rgb" valType="str" updates="None"/>
<Param name="Save log file" val="True" valType="bool" updates="None"/>
<Param name="Experiment info" val="{u'strict': u'False', u'participant': u'frameTimingTest'}" valType="code" updates="None"/>
<Param name="Save excel file" val="True" valType="bool" updates="None"/>
<Param name="Save wide csv file" val="True" valType="bool" updates="None"/>
<Param name="Save psydat file" val="True" valType="bool" updates="None"/>
<Param name="expName" val="timingTest" valType="str" updates="None"/>
<Param name="logging level" val="info" valType="code" updates="None"/>
<Param name="Units" val="use prefs" valType="str" updates="None"/>
<Param name="Show info dlg" val="True" valType="bool" updates="None"/>
<Param name="Saved data folder" val="" valType="code" updates="None"/>
<Param name="Screen" val="1" valType="num" updates="None"/>
</Settings>
<Routines>
<Routine name="end">
<TextComponent name="text_end">
<Param name="opacity" val="1" valType="code" updates="constant"/>
<Param name="colorSpace" val="rgb" valType="str" updates="constant"/>
<Param name="name" val="text_end" valType="code" updates="None"/>
<Param name="wrapWidth" val="" valType="code" updates="constant"/>
<Param name="color" val="white" valType="str" updates="constant"/>
<Param name="text" val="Finished!&#10;&#10;Datafiles:&#10; data/-------.csv for trial-by-trial&#10; data/-------.xlsx for summary view" valType="str" updates="constant"/>
<Param name="stopVal" val="3" valType="code" updates="constant"/>
<Param name="durationEstim" val="" valType="code" updates="None"/>
<Param name="pos" val="[0, 0]" valType="code" updates="constant"/>
<Param name="flip" val="" valType="str" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="units" val="from exp settings" valType="str" updates="None"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="ori" val="0" valType="code" updates="constant"/>
<Param name="stopType" val="duration (s)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="font" val="Arial" valType="str" updates="constant"/>
<Param name="letterHeight" val="0.1" valType="code" updates="constant"/>
</TextComponent>
<CodeComponent name="code">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="code" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="win.setRecordFrameIntervals(False)" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="show_black">
<ImageComponent name="blackRect">
<Param name="opacity" val="1" valType="code" updates="constant"/>
<Param name="flipVert" val="False" valType="bool" updates="constant"/>
<Param name="colorSpace" val="rgb" valType="str" updates="constant"/>
<Param name="name" val="blackRect" valType="code" updates="constant"/>
<Param name="color" val="black" valType="str" updates="constant"/>
<Param name="stopVal" val="duration" valType="code" updates="constant"/>
<Param name="durationEstim" val="1" valType="code" updates="None"/>
<Param name="mask" val="None" valType="str" updates="constant"/>
<Param name="pos" val="[0, 0]" valType="code" updates="constant"/>
<Param name="interpolate" val="linear" valType="str" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="units" val="from exp settings" valType="str" updates="None"/>
<Param name="texture resolution" val="128" valType="code" updates="constant"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="ori" val="0" valType="code" updates="constant"/>
<Param name="stopType" val="duration (frames)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="flipHoriz" val="False" valType="bool" updates="constant"/>
<Param name="image" val="None" valType="str" updates="constant"/>
<Param name="advancedParams"/>
<Param name="size" val="[0.5, 0.5]" valType="code" updates="constant"/>
</ImageComponent>
</Routine>
<Routine name="start">
<TextComponent name="text">
<Param name="opacity" val="1" valType="code" updates="constant"/>
<Param name="colorSpace" val="rgb" valType="str" updates="constant"/>
<Param name="name" val="text" valType="code" updates="None"/>
<Param name="wrapWidth" val="" valType="code" updates="constant"/>
<Param name="color" val="white" valType="str" updates="constant"/>
<Param name="text" val="Press space bar to start the&#13;&#10;timing tests.&#13;&#10;&#13;&#10;Press &lt;esc&gt; to quit." valType="str" updates="constant"/>
<Param name="stopVal" val="" valType="code" updates="constant"/>
<Param name="durationEstim" val="" valType="code" updates="None"/>
<Param name="pos" val="[0, 0]" valType="code" updates="constant"/>
<Param name="flip" val="" valType="str" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="units" val="from exp settings" valType="str" updates="None"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="ori" val="0" valType="code" updates="constant"/>
<Param name="stopType" val="duration (s)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="font" val="Arial" valType="str" updates="constant"/>
<Param name="letterHeight" val="0.1" valType="code" updates="constant"/>
</TextComponent>
<KeyboardComponent name="key_resp_2">
<Param name="correctAns" val="" valType="str" updates="constant"/>
<Param name="storeCorrect" val="False" valType="bool" updates="constant"/>
<Param name="name" val="key_resp_2" valType="code" updates="None"/>
<Param name="stopVal" val="" valType="code" updates="constant"/>
<Param name="durationEstim" val="" valType="code" updates="None"/>
<Param name="forceEndRoutine" val="True" valType="bool" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="discard previous" val="True" valType="bool" updates="constant"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="allowedKeys" val="&quot;space&quot;" valType="code" updates="constant"/>
<Param name="stopType" val="duration (s)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="store" val="nothing" valType="str" updates="constant"/>
</KeyboardComponent>
<CodeComponent name="record_frames">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="record_frames" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="win.setRecordFrameIntervals(True)&#10;" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="get_t1">
<CodeComponent name="get_t1_code">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="get_t1_code" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="black = win.lastFrameT-t0 #duration of first interval&#10;t1 = win.lastFrameT #needed to get duration2&#10;trials.addData('black', black) #store this in data file" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="get_t0">
<CodeComponent name="get_t0_code">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="get_t0_code" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="t0 = win.lastFrameT #trial started when last win flip occured&#10;trials.addData('t0', t0) #store this in data file" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="get_t2">
<CodeComponent name="get_t2_code">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="get_t2_code" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="white = win.lastFrameT-t1 #duration of second interval&#10;trials.addData('white', white) #store this in data file" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="check_system">
<TextComponent name="sysCheck_text">
<Param name="opacity" val="1" valType="code" updates="constant"/>
<Param name="colorSpace" val="rgb" valType="str" updates="constant"/>
<Param name="name" val="sysCheck_text" valType="code" updates="None"/>
<Param name="wrapWidth" val="" valType="code" updates="constant"/>
<Param name="color" val="white" valType="str" updates="constant"/>
<Param name="text" val="Checking system configuration" valType="str" updates="constant"/>
<Param name="stopVal" val="1.0" valType="code" updates="constant"/>
<Param name="durationEstim" val="" valType="code" updates="None"/>
<Param name="pos" val="[0, 0.9]" valType="code" updates="constant"/>
<Param name="flip" val="" valType="str" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="units" val="norm" valType="str" updates="None"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="ori" val="0" valType="code" updates="constant"/>
<Param name="stopType" val="duration (s)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="font" val="Arial" valType="str" updates="constant"/>
<Param name="letterHeight" val="0.1" valType="code" updates="constant"/>
</TextComponent>
<CodeComponent name="runtime_info">
<Param name="Begin Experiment" val="" valType="extendedCode" updates="constant"/>
<Param name="name" val="runtime_info" valType="code" updates="None"/>
<Param name="Each Frame" val="" valType="extendedCode" updates="constant"/>
<Param name="Begin Routine" val="from psychopy import info&#10;&#10;i = info.RunTimeInfo(win=win, verbose=True, userProcsDetailed=True)&#10;&#10;info_dict = eval(repr(i))&#10;strict = bool(expInfo['strict'] in [1, '1', True, 'True'])&#10;if info_dict['psychopyVersion'] &lt; '1.79':&#10; msg = 'using an old version of PsychoPy; please upgrade'&#10; logging.error(msg)&#10; if strict: raise RuntimeError(msg)&#10;&#10;if not info_dict['windowIsFullScr'] in [True, 'True']:&#10; msg = 'window should be full screen for best timing'&#10; logging.error(msg)&#10; if strict: raise RuntimeError(msg)&#10;&#10;if 'intel' in info_dict['openGLVendor'].lower():&#10; msg = &quot;PsychoPy discourages use Intel graphics cards / drivers (bad performance)&quot;&#10; logging.error(msg)&#10; if strict: raise RuntimeError(msg)&#10;&#10;if int(info_dict['systemMemFreeRAM']) &lt; 500:&#10; msg = &quot;available RAM is &lt; 500M&quot;&#10; logging.warning(msg)&#10; if strict: raise RuntimeError(msg)&#10;&#10;if int(info_dict['systemMemTotalRAM']) &lt; 1000:&#10; msg = &quot;system RAM is &lt; 1G (old hardware?)&quot;&#10; logging.warning(msg)&#10; if strict: raise RuntimeError(msg)&#10;&#10;if info_dict['systemUserProcFlagged']:&#10; logging.warning('Some concurrent processes can affect frame timing: %s' % info_dict['systemUserProcFlagged'])&#10;&#10;if not strict:&#10; logging.warning(&quot;Not strict, but proceeding anyway for debugging purposes.&quot;)&#10;" valType="extendedCode" updates="constant"/>
<Param name="End Routine" val="" valType="extendedCode" updates="constant"/>
<Param name="End Experiment" val="" valType="extendedCode" updates="constant"/>
</CodeComponent>
</Routine>
<Routine name="show_white">
<ImageComponent name="whiteRect">
<Param name="opacity" val="1" valType="code" updates="constant"/>
<Param name="flipVert" val="False" valType="bool" updates="constant"/>
<Param name="colorSpace" val="rgb" valType="str" updates="constant"/>
<Param name="name" val="whiteRect" valType="code" updates="constant"/>
<Param name="color" val="white" valType="str" updates="constant"/>
<Param name="stopVal" val="duration" valType="code" updates="constant"/>
<Param name="durationEstim" val="1" valType="code" updates="None"/>
<Param name="mask" val="None" valType="str" updates="constant"/>
<Param name="pos" val="[0, 0]" valType="code" updates="constant"/>
<Param name="interpolate" val="linear" valType="str" updates="constant"/>
<Param name="startEstim" val="" valType="code" updates="None"/>
<Param name="units" val="from exp settings" valType="str" updates="None"/>
<Param name="texture resolution" val="128" valType="code" updates="constant"/>
<Param name="startType" val="time (s)" valType="str" updates="None"/>
<Param name="ori" val="0" valType="code" updates="constant"/>
<Param name="stopType" val="duration (frames)" valType="str" updates="None"/>
<Param name="startVal" val="0.0" valType="code" updates="None"/>
<Param name="flipHoriz" val="False" valType="bool" updates="constant"/>
<Param name="image" val="None" valType="str" updates="constant"/>
<Param name="advancedParams"/>
<Param name="size" val="[0.5, 0.5]" valType="code" updates="constant"/>
</ImageComponent>
</Routine>
</Routines>
<Flow>
<Routine name="start"/>
<Routine name="check_system"/>
<LoopInitiator loopType="TrialHandler" name="trials">
<Param name="conditionsFile" val="trials.csv" valType="str" updates="None"/>
<Param name="name" val="trials" valType="code" updates="None"/>
<Param name="random seed" val="" valType="code" updates="None"/>
<Param name="loopType" val="sequential" valType="str" updates="None"/>
<Param name="nReps" val="32" valType="code" updates="None"/>
<Param name="endPoints" val="[0, 1]" valType="num" updates="None"/>
<Param name="conditions" val="[{'duration': 1}, {'duration': 3}, {'duration': 6}, {'duration': 12}, {'duration': 30}, {'duration': 60}]" valType="str" updates="None"/>
</LoopInitiator>
<Routine name="get_t0"/>
<Routine name="show_black"/>
<Routine name="get_t1"/>
<Routine name="show_white"/>
<Routine name="get_t2"/>
<LoopTerminator name="trials"/>
<Routine name="end"/>
</Flow>
</PsychoPy2experiment>
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
duration
1
3
6
12
30
60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment