Psychopy

From Neural Wiki

Jump to: navigation, search

A really cool new python addition that I just recently found out about is called PsychoPy (Psychophysics Python). This open source platform allows you to develop psychophysics experiments using your favorite programming language (Python 2.5!). The documentation is decent on the website, but I am working on putting together a bit more information about the different commands. Let me know if there is something wrong or missing (mike(at)neuralwiki.org). I am using a Mac G5 with the Intel chipset and a MacBook Pro with the Dual Core Intel chip to run the program. The best way to install the program on an intel mac running OS X is to use Macports ("sudo port install PsychoPy"). Installing on a PowerPC is a bit harder and is detailed below. Luckily, PsychoPy also works on Windows or Linux. Much thanks to the Psychopy team for setting this up.

Contents

[edit] Commands

A list of features and commands can be found here

[edit] Movie Player

Some test code I came up with for playing a movie in PsychoPy. In the PsychoPy demo folder which you get when you download PsychoPy, there is a sample called MovieStim.py which you can look at for more information. I dont know if the following method is the best, but it will work.

from psychopy import core, visual, event
from numpy import ceil   
myWin=visual.Window((1000,1000), allowGUI=False)                   #set up a window for your movie
mov=visual.MovieStim(myWin, 'stimulus_movie.mp4', flipVert=False)  #insert your movie name in the quotes
fps=60                                                             #insert your frames per second of your movie
total_frames=ceil(fps*mov.duration)                                #total frames to present
print mov.duration                                                 #movie duration in seconds  
print mov.format.width, mov.format.height                          #the width and height
t=0                                                                #initialize counter
mov.draw()                                                         #draw the first movie frame
while t < total_frames:                                            #play through all frames
   myWin.flip()                                                    #go to the next frame
   mov.draw()                                                      #draw the next frame
   t=t+1                                                           #update counter

[edit] Installing PsychoPy on a Power PC Mac

For my current work, we have two Macs running Psychophysics experiments. Both are running OS X 10.5.8, one is a quad core PPC and the other is a quad core Intel Mac. On the Intel Mac Macports works just fine for installing Psychopy. If you have Macports installed, just type in 'sudo port install py25-psychopy' and sit back while Macports does its thing. However, on the Power PC Mac, this did not work. I ran into some strange install errors. I kept getting the following error for several different python packages from scipy to python image library.

 f951: error: unrecognized command line option "-arch"

After giving up on Macports, I finally found a way that works. First upgrade the Python 2.5 that comes with your machine to Active Python 2.5. I got the Python 2.5.4.4 dmg. Works nicely, and installs easily. In fact, with the exception of Psychopy, OpenGL and setuptools, you want to find as many dmg files as you can. Note that many Tiger (OS X 10.4) dmg's will work on Leopard (OS X 10.5).

First you need setuptools. After downloading, use your console and cd into the directory where you downloaded it, and type

 sh setuptools-0.6c9-py2.4.egg

Then download pyglet.dmg. Double click on it and follow the install directions.

Next is pygame.dmg. Double click on it and follow the install directions.

Then OpenGL. After downloading and unzipping, go into the OpenGL folder where setup.py lives, then type in:

 python setup.py install

From this page download and install numpy, matplotlib, python image library (PIL) and wxpython. If you've got it, give this guy a donation, his page will save you lots of time and frustration, particularly with PIL...ask me how I know.

You can also add winioport so that you can use the parallel port. NOTE: I havent tried this with the parallel port. I ended up installing pyserial and using a serial port as my method of triggering equipment. More about that in Mac OS X Serial Port.

Finally, download the psychopy.zip, unzip it and rename it PyschoPy-1.50.01-py2.5.egg, then transfer this folder into your /Library/Python/2.5/site-packages/ folder. I dont know if this is necessary, but I renamed the Psychopy.egg-info folder inside the main Psychopy-xx-.egg folder to EGG-info (it works, that's all I know).

Next open up your easy-install.pth file using a text editor and add the following line somewhere in the middle and it should work.

 ./PsychoPy-1.50.01-py2.5.egg

My easy-install.pth looks like this.

import sys; sys.__plen = len(sys.path)
./setuptools-0.6c9-py2.5.egg
./numpy-1.0.5.dev4722-py2.5-macosx-10.3-ppc.egg
./matplotlib-0.98pre-py2.5-macosx-10.5-ppc.egg
./scipy-0.7.0.dev3812-py2.5-macosx-10.3-ppc.egg
./PyMC-2.0-py2.5-macosx-10.3-ppc.egg
./PsychoPy-1.50.01-py2.5.egg
./ipython-0.10-py2.5.egg
./SQLObject-0.11.0-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =  p+len(new)


To test it open the command prompt and type in python, then when python opens type from psychopy import * If you dont get any errors, then you have a working version of PsychoPy!

[edit] Psychopy and external triggering

To see how I used a Mac to trigger my equipment using PySerial, see Mac OS X Serial Port.

Personal tools