Learning Python, my first steps

February 14th, 2009

In yesterday's post, I advertised PsychoPy as an interesting alternative for the PsychToolbox, which runs on Matlab. In my work as a PhD student, I program my experiments in C# and OpenGL, using libraries that were written by my supervisor and our technician. However, I can't share any of my work with the community, which is something I'm quite keen on. Furthermore, my experiments will only run on Windows. So I think PsychoPy is interesting because it is free and platform independent but to get the best from PsychoPy, you need to know a thing or two about the Python programming language. So yesterday, I stepped into the world of Python development.

First impressions; not bad. It took me some time to find a good IDE for the Mac and to find out how to get additional libraries (and got stuck in getting rpy running). In the end I got everything up and running; I'm using IDLE for now and I've installed SciPy, NumPy, wxPython, PyGame and PyOpenGL. At this point I should mention that Jon has done a great job in creating a custom IDE that is included in the PsychoPy package, or at least it is on the mac version, and you can easily code and run your experiments in this environment. Furthermore, all the packages you would need for experiments are included in the package. But... I'm stubborn and like to take the hard route; if you want to get a kickstart, use Jon's IDE.

The Python language seems - at a first glance - great. It seems elegant and I've had no trouble understanding code sniplets. It handles strings much much better than matlab, and it looks like whatever you can do with Matlab, you can do with Python too (using NumPy and SciPy). I'm now working my way through some Python books to get the hang of the basics - will keep you updated.

Psychophysics and PsychoPy

February 13th, 2009

Today I met Jon Peirce, who is responsible for much - if not all - of the code in PsychoPy, which is a nice open-source package for creating visual stimuli and running psychophysical (or should I say PychoPysical?) experiments in Python. There's a number of reasons as to why psychopy is interesting for neuroscientists:

  1. It's based on free libraries
  2. It is platform independent
  3. Python is a nice OO language
  4. Did I mention it's free?
  5. It works great with OpenGL

I believe that software should be freely available and psychopy is exactly that; that means that you will not have to pay for Matlab licenses to use the PsychToolbox. Although a wonderful piece of software in its own right, the PsychToolbox requires researchers to have a license for Matlab, which can make it quite expensive. Furthermore, coding (or should I say: scripting) an experiment in Matlab can be somewhat "ugly" in my opinion. As far as I can tell, it's early days for PsychoPy, Jon told me there are about a 100 users at the moment. Hopefully more researchers will find their way to PsychoPy and hopefully some of them will be able to help expand it!

(ofcourse there are a couple of down sides of using PsychoPy; (1) installation of Python is not always straightforward, but see the .dmg for the mac which features everything you need to run PsychoPy; and (2) if you don't know the language you would have to learn it)

New, improved staircase procedure in the making

October 18th, 2008

One of the reasons why people visit this website is my implementation of the Levitt 1971 adaptive staircase in Matlab. Apparently, there is a need for this kind of thing amongst researchers. That's why I've decided to reimplement the staircase procedure to include more functionality, such as:

  1. the ability to run multiple interleaved staircases
  2. more control of the stepsize

I'm still in the process of programming, debugging and testing the code at the moment, but here's a sneak peak of what is to come:

(click for larger image)

In the meantime, I've disabled the download for the old staircase procedure. If you want a copy, please drop me a line and I will send it to you asap.

Edit 06/02/2009: still in progress - please be patient

Reading files with headers into matlab

July 2nd, 2008

Here's a handy code sniplet that enables you to read a file with columns of data with headers into MATLAB:

  1. function importfile(filename)
  2.  
  3. % import the file
  4. newdata = importdata(filename);
  5.  
  6. % create new variables in the base workspace from these fields
  7. vars = fieldnames(newdata);
  8. for i=1:length(vars),
  9. assignin('base', vars{i}, newdata.(vars{i}));
  10. end

This will give you three variables in your workspace:

  • colheaders: a list of all the variable names, extracted from the header
  • data: a matrix with all your data in it
  • textdata: essentially the same thing as colheaders

JANE: Journal Author Name Estimator

January 31st, 2008

"Have you recently written a paper, but you're not sure to which journal you should submit it? Or are you an editor, and do you need to find reviewers for a particular paper? Jane can help!"

From: http://biosemantics.org/jane/