Blog Archives

Some Python resources


Since I’ve switched to using PsychoPy for programming my behavioural and fMRI experiments (and if you spend time coding experiments, I strongly suggest you check it out too, it’s brilliant) I’ve been slowly getting up to speed with the Python programming language and syntax. Even though the PsychoPy GUI ‘Builder’ interface is very powerful and user-friendly, one inevitably needs to start learning to use a bit of code in order to get the best out of the system.

Before, when people occasionally asked me questions like “What programming language should I learn?” I used to give a somewhat vague answer, and say that it depended largely on what exactly they wanted to achieve. Nowadays, I’m happy to recommend that people learn Python, for practically any purpose. There are an incredible number of libraries available that enable you to do almost anything with it, and it’s flexible and powerful enough to fit a wide variety of use cases. Many people are now using it as a free alternative to Matlab, and even using it for ‘standard’ statistical analyses too. The syntax is incredibly straight-forward and sensible; even if an individual then goes on to use a different language, I think Python is a great place to start with programming for a novice. Python seems to have been rapidly adopted by scientists, and there are some terrific resources out there for learning Python in general, and its scientific applications in particular.

For those getting started there are a number of good introductory resources. This ‘Crash Course in Python for Scientists’ is a great and fairly brief introduction which starts from first principles and doesn’t assume any prior knowledge. ‘A Non-Programmers Tutorial for Python 2.6′ is similarly introductory, but covers a bit more material. ‘Learn Python the Hard Way’ is also a well-regarded introductory course which is free to view online, but has a paid option ($29.95) which gives you access to additional PDFs and video material. The ‘official’ Python documentation is also pretty useful, and very comprehensive, and starts off at a basic level. Yet another good option is Google’s Python Classes.

For those who prefer a more interactive experience, CodeAcademy has a fantastic set of interactive tutorials which guide you through from the complete beginning, up to fairly advanced topics. PythonMonk and also have similar systems, and all three are completely free to access – well worth checking out.

For Neuroimagers, there are some interesting Python tools out there, or currently under development. The NIPY (Neuroimaging in Python) community site is well worth a browse. Most interestingly (to me, anyway) is the nipype package, which is a tool that provides a standard interface and workflow for several fMRI analysis packages (FSL, SPM and FreeSurfer) and facilitates interaction between them – very cool. fMRI people might also be very interested in the PyMVPA project which has implemented various Multivariate Pattern Analysis algorithms.

People who want to do some 3D programming for game-like interfaces or experimental tasks will also want to check out VPython (“3D Programming for ordinary mortals”!).

Finally, those readers who are invested in the Apple ecosystem and own an iPhone/iPad will definitely want to check out Pythonista – a full featured development environment for iOS, with a lot of cool features, including exporting directly to XCode (thanks to @aechase for pointing this one out on Twitter). There looks to be a similar app called QPython for Android, though it’s probably not as full-featured; if you’re an Android user, you’re probably fairly used to dealing with that kind of disappointment though. ;o)

Anything I’ve missed? Let me know in the comments and I’ll update the post.


Free, interactive MRI courses from (plus lots of other medical/anatomy material too)

A very quick post to point you towards a really fantastic set of online, interactive courses on MRI from a website called – a very nice, very slick set of material. The MRI courses are all free, but you’ll need to register to see the animations. Lots of other medical/anatomy-related courses on the site too – some free, some ‘premium’, and some nice looking mobile apps too.

More useful links… Open Sesame, the psychology of email, Inkscape, and others.

Another quickie post (it’s been ages since I’ve written anything substantive I know, bear with me just a little while longer…) with some links-of-interest for you.

First up is Open Sesame – this is an experiment-builder application with a nice graphical front-end, which also supports scripting in Python – nice. Looks like a possible alternative to PsychoPy with a fair few similar features. Also, it’s cross-platform, open-source and free – my three favourite things!

Next up is Inkscape – this is a free vector graphics editor (or drawing package), with similar features to Adobe Illustrator or Corel Draw. I tend to use Adobe Illustrator for a few specialised tasks, such as making posters for conferences, and this looks like a potentially really good free alternative.

Neuroimaging Made Easy is a blog I found a while ago that I’ve been meaning to share; it’s mostly a collection of tips and downloadable scripts to accomplish fairly specific tasks. They’re all pretty much optimised for Mac users (using AppleScript) and people who use BrainVoyager or FSL for their neuroimaging – SPM users are likely to be disappointed here (but they’re pretty used to that anyway, right?! Heh…). Really worth digging through the previous posts if you fall in the right segments of that Venn diagram though – I’ve been using a couple of their scripts for a while now.

Penultimately, I thought this recent article on Mind Hacks was really terrific – titled: “Psychological self-defence for the age of email”. It covers several relevant psychological principles and shows how they can be used to better cope with the onslaught of e-mail that many of us are often buried under.

Lastly, I hope you’ll pardon a modicum of self-promotion, but I recently did an interview over Skype with the lovely Ben Thomas of Unfortunately the skype connection between London and Los Angeles was less than perfect which meant he couldn’t put it up as a podcast, but he heroically transcribed it instead – if you are so inclined, you can read it here.


The immediate and wide-ranging power of Twitter – discussion with Vaughn Bell and others on fMRI

I’ve only started using Twitter reasonably recently, but I’m finding that it’s very quickly become a near-essential part of my daily online routine, and I’d urge anyone who has a modicum of curiosity to give it a serious try. The ability to connect nigh-instantly to people around the world who share similar interests and occupations is incredible, and the 140-character limit is rarely too limiting once you get used to it. In fact, I’m constantly amazed at the high level of discussion which can be conducted within such a constraint.

As an example, this weekend there was an article in the Observer on fMRI by Vaughan Bell of Mindhacks fame. As i blearily groped my way through my regular Sunday morning routine of a cup of tea followed by several espressos, I was also engaged in an interesting debate about the article with the author (@vaughnbell), Chris Chambers (@chrisdc77), Tom Hartley (@tom_hartley), David Dobbs (@David_Dobbs) and a few others. The discussion was very kindly storify-ed for posterity by @creiner, and you can read it here.

I can’t think of any other way in which this discussion could have happened. I’ve never met Vaughn, or any of the other participants for that matter, and would have no direct way of contacting him/them otherwise. The great power of twitter (for me, anyway) is enabling groups of specialists like this to discuss in a public forum where anyone can chip in. If you’ve been on the fence about Twitter for a while, I urge you to give it a try – the more people who are active users, the richer the discussions will be!


PS. More additional thoughts on the original article can also be found on this blogpost.

PPS. Tom Hartley has also just posted up a fantastic discussion related to the same issues on his blog too.

A recreation of the world’s first neuroimaging experiment – LIVE!

A break from normal service today, as I thought I’d post up a little video of me being silly on stage on the occasion of Science Showoff  a few weeks ago. Science Showoff is a fantastic open-mic night for science communication, organised by the inimitable Steve Cross of UCL. People get up on stage in the back room of a pub in Clerkenwell, and do science-y things for the amusement (and occasionally even for the education) of the crowd.

For their May event, I thought I’d have a go at re-creating the world’s first brain-imaging experiment, live, on-stage, using nothing more than a table, a rolling-pin, and a kitchen scale. How was such a feat accomplished (I hear you gasp, dear reader, in tones hushed with reverential awe)? I shall explain.

Angelo Mosso – 19th Century Italian physiologist and ‘world’s first neuroimager’.

What’s often called ‘the world’s first neuroimaging experiment’ was conducted by a gentleman by the name of Angelo Mosso in the late 19th Century; a professor of physiology at the University of Turin. He’s generally credited with the notion that blood flow in the brain is related to mental activity; he arrived at this conclusion by studying patients with open head wounds – the pulsations of their dura would increase in frequency when the patients became agitated or engaged in some demanding mental task.

He also (apparently) designed an experiment in order to see the effect of increased blood flow during mental activity in ‘normal’, uninjured people. This was the first time an external apparatus had been used to visualise the internal processes of the brain – hence ‘world’s first neuroimaging experiment’. I say ‘apparently’ because the only write-up we have about the experiment is from William James’ journal of 1890:

“The subject to be observed lay on a delicately balanced table which could tip downwards either at the head or the foot if the weight of either end were increased. The moment emotional or intellectual activity began in the subject, down went the balance at the head-end, in consequence of the redistribution of blood in his system…”

Now, most people who’ve written about this experiment since, have generally cast doubt on the idea that this could ever actually work. But, being on occasion an incautious type, and thinking that even if it didn’t work it could at least be amusing, I figured I’d just give it a try. I used a couple of modern-day modifications – I got a cheap digital scale off Amazon, which could distinguish increments of 0.1g, and used a webcam pointed at the scale’s readout to display it to the crowd via a projector. I rested the head-end of the balance-board on the scale, and figured that any increase in blood-flow to the brain should result in an increase in weight on the scale. The able and moderately-willing volunteer for the experiment was my good friend Thom Scott-Phillips of Edinburgh (and Durham) University and the video was shot by Rita Santos. Unfortunately it’s impossible to make out the scale readout on the video, but it definitely worked. Oh yes. Absolutely. *Ahem*. I’m also slightly embarrassed to admit that it contains quite a few of the naughty swears, but, y’know, it’s just that kind of event. If it’s alright for Ben Goldacre, then it’s alright for me, dammit.

Without further ado then – the video (watch it on YouTube for glorious 720p):

Enjoy! TTFN.

SPM vs. FSL by Chris Rorden, and some miscellaneous fMRI tips

I’ve noticed that my previous postings (here and here) about the differences between popular bits of neuroimaging software have been pretty popular in terms of traffic, so I thought I’d just point you towards a similar powerpoint presentation I’ve just found authored by Chris Rorden. It’s fairly brief, but does contain a lot of good information about the key differences between FSL and SPM, particularly in terms of their different approaches to spatial normalisation and  You can download the .ppt file here.

For those who might already be a bit more advanced in their practice of the dark art of fMRI analysis, Chris also has an great set of scripts for SPM8 here, plus of course, his MRICron software is outstandingly useful.

Finally, for FSL users (see – something for everyone at this blog!) I have this little tip, from the mysteriously-named “neuroimager”, which is a fantastic and beautiful method of displaying functional results on a 3D-rendered brain image, using freesurfer.