Python for psychology experiments - looking for advice

149 views
Skip to first unread message

ian hussey

unread,
Sep 14, 2012, 1:13:53 PM9/14/12
to python...@googlegroups.com
Hi everyone,

I'm a psychology PhD student at NUI Maynooth, and I've just started looking at Python. I have a little VB6 experience, and am working my way through Learn Python the Hard Way at the moment. I'll ramble for on a bit about where I'm coming from and if anyone makes it to the end and has any advice, that'd be great!

I have a pretty specific goal in mind, I'm looking to work my way up to programming a psychology experiment that presents participants with pairs of word or picture stimuli and record their key-press response times. We have a VB6 app that we use for this already (you can download a copy of it at IRAP 2012 Program update if you were interested for some reason) but the code is a mess. It needs to be redone from the ground up and in something that we can a) deploy one multiple operating systems, and b) distribute as a single executable with no or minimal dependancies so that other researchers can pick it up and use it with little setup time. I asked around and was pointed towards Python. I've looked at packages like PsychoPy to make my job easier, but they don't give adequate control over randomisation, looping, or data output. I'm now considering using wxpython or Python Card (I was initially a little stumped as to how to create a GUI - shows my lack of knowledge!).

So, my questions are as follows: 
1. Am I making any obvious errors in thinking that Python + wxpython are a relatively easy way to do this, or am I looking to do something with Python that would be better done with another language or with another set of tools?
2. One colleague suggested I use a proprietary language called LiveCode, but others have suggested this would be a bad call as I'd be locked in to their system (and paying money I didn't have to). Thoughts? 

Thanks for reading!

Best,
Ian

Alan Kennedy

unread,
Sep 18, 2012, 12:26:50 AM9/18/12
to python...@googlegroups.com
Hi Ian,

It appears to me that you want to develop something that requires fine
control over user interface and interactivity, perhaps akin to a game?

Python has several libraries devoted to developing games, which would
give you a large headstart on GUI development, keypress and joystick
control, etc, because they are custom designed for such purposes. (As
opposed to starting completely from scratch, as you would have to
with, say, wxpython).

I haven't used it myself, but people speak highly of PyGame, which
seems very well documented, with oodles of tutorials, documentation
and examples.

http://www.pygame.org/

In particular, this site seems to be a thorough tutorial for learning
both python and pygame at the same time, and would be a very good
introduction to the language and writing interactive games in the
language.

http://programarcadegames.com/

Several other sites linked from the "Tutorials" page seem to be
targeted at teaching the language as well as game programming
technique.

http://www.pygame.org/wiki/tutorials

A cursory overview of the documentation shows that there are
mechanisms for packaging developed games into standalone applications
(although this one refers only to windows, but there I'd be very
surprised if there are not multi-platform equivalents).

http://www.pygame.org/wiki/Pygame2exe?parent=CookBook

Alan.
> --
>
>

Harry van Haaren

unread,
Sep 18, 2012, 11:54:22 AM9/18/12
to python...@googlegroups.com
Hi Ian,

I have a little experience in this area, and while Python indeed does fit the bill for cross-platform it does have its own set of drawbacks:

-Time: You mentioned that you're recording response time by key presses: If you're doing a PhD you'll likely need very accurate information, which you most likely won't get from Python. There are various timing issues and inconsistencies in the language (google "Python GIL" or "garbage collection" for various specifics). Although you probably *can* make it work, and do lots of tests to prove that your collected data is accurate and verifyable, perhaps its not the easy route.

There are various domain specific languages set up for this kind of thing, you mentioned LiveCode : I'm not sure it has the timing critical elements that you'll find are most likely necessary for your project.

I would advise you to look at languages / enviroments that are designed for writing psychology experiments:
I'm an open source guy, so will advise starting here :)  http://pebl.sourceforge.net

Perhaps the best "next step" is to get some details on how timing-accurate your data will need to be, and how you can best collect that data based on that?

HTH, -Harry

PS: I'm doing low-latency real-time audio programming, which is extremely timing dependent, and hence I just can't use Python for the audio processing - its too slow. That said, python is very powerful to use for writing glue code / code that isn't timing critical : like a menu that allows you choose which test / experiment to run, etc etc..
Reply all
Reply to author
Forward
0 new messages