in Neuroimaging, Python, Tools

Prespy – Presentation in python

Prespy – Presentation in python

Presentation®

Presentation is a Windows-based program for stimulus delivery and interfacing with hardware tailored for Neuroscientists and Psychologists. It is script based, basically abstracting away the low-level communication with display and sound card drivers, input devices and more to allow researchers to quickly implement experiments for their research.

Whilst it does its job well at making life easier for researchers to create powerful and fast experiments, because of its target market I find myself as a programmer constantly at odds with some of the design decisions.

prespy 0.3

This is where my tool comes in, prespy is a start at a tool that will make working with the Presentation® log files it creates much easier from within python. This currently enables me to easily load in data for analysis, as well as recreating the Neurobehavioural Systems tool SCLA (Sound Card Latency Analyser).

The tool is packaged on PyPI and is installable via pip install prespy. The main use case is to load in a Presentation® log file and use it to look at the data.

Presentation® log files

There are some idiosyncrasies with Presentation® log files that make it difficult to be loaded as a csv or via pandas, which justify the creation of this package. The main part of the log file is a list of tab-separated events as recorded from the experiment, however, there is header information, there is also often a duplicate column name and possible additional reports after the main data.

prespy log file interaction takes a log file as input and returns a Record object, with an extracted subject identifier and a list of Event objects. An Event object exposes some commonly used columns such as event type and code, as well as returning timing information in milliseconds.

Using prespy

from prespy.logfile import load
from statistics import mean, stdev

gavindata = load('gavinlogfile.log')
sounds = [event for event in gavindata.events if event.etype == 'Sound']
timediffs = [sound.time - sounds[s].time for s, sound in enumerate(sounds[1:])]
print('Mean: {} & SD: {} time difference between sounds'.format(mean(timediffs), stdev(timediffs)))

Other additions

prespy as it currently exists actually contains a couple of other scripts. One is extremely undeveloped and involves writing MATLAB compatible m-files for reading into SPM to use in magnetic resonance imaging analysis.

The other script is a sound card latency analyser, which after running a sample experiment from Presentation® will match up recorded sound files and events from the log files to determine the delay introduced in timing by the sound card.

Leave a Reply