Welcome to the introductory series to using Python in vision research brought to you by the GestaltReVision group (KU Leuven, Belgium).
The series consist of seven IPython notebooks meant as a three-day crash course for vision researchers in programming with Python, building experiments with PsychoPy and psychopy_ext, learning the fMRI multi-voxel pattern analysis with PyMVPA, and understading image processing in Python.
There are more extensive resources for vision scientists on our GestaltReVision wiki.
Please report any bugs or share ideas on our GitHub repo.
Authors: Maarten Demeyer, Jonas Kubilius
Year: 2014
Copyright: Public Domain as in CC0 (except where noted otherwise). Feel free to reuse these materials for your teaching or any other purposes.
Unfortunately, getting Python and all necessary packages is one of the major difficulties for beginners. So please be patient and try to get everything in order because once you get it running, magic can start.
All materials, including this notebook, are available here.
The easiest method is to install our own Python distribution that has all necessary packages included.
Linux user? Awesome! Go to the NeuroDebian website, follow the instructions on how to add their repositories, and just sit back and relax while your system installs packages through sudo apt-get install <package_name>
and sudo pip install <package_name>
, as listed below:
sudo apt-get install python-pip python-numpy python-scipy python-imaging python-matplotlib
sudo apt-get install psychopy spyder ipython-notebook
sudo apt-get install python-pandas python-docutils python-nibabel python-mvpa2 python-h5py
sudo pip install pillow
sudo pip install seaborn svgwrite
sudo pip install psychopy_ext
Unfortunately, we have a very limited in-house Mac experience. We do offer instructions how to install most packages but you may (or are quite likely to) run into problems and we will probably not know how to help you.
If you are having troubles installing Python and its packages, or you just don't want to change anything in your current setup, an excellent alternative is to install the NeuroDebian Virtual Machine. This will create a Linux desktop environment within your operating system, allowing you to follow the much simpler Linux installation procedures instead. Moreover, this Linux environment will be entirely separate from any other Python installation you may have on your machine, so you won't mess anything up by trying. Detailed instructions can be found here.
Alternatively, if you are only interested in Scietific Python and or PsychoPy (sessions 1-4 and 7), the Standalone PsychoPy installation will largely suffice. You will not have IPython installed, but all examples should be working otherwise.
For even more options, check our wiki.
Run the following cell (by pressing the ▶ button above or Ctrl+Enter) to check whether your computer contains all needed packages. This will generate a txt output file which you can e-mail to us, should a problem arise. Press a key when asked to, and close the new IPython Notebook window that will be opened. If the cell keeps running for up to 10 seconds after closing the notebook, just wait; this is normal.
import os
os.system('python check_install.py')
try:
f = open('workshop_req_check.txt','r')
for line in f.readlines():
print line,
f.close()
except IOError:
print 'The script could not be executed!'
Start button > Type cmd > Enter
)Navigate to the folder where the IPython notebook is using the cd
command
e.g. cd C:\Users\u000001\Documents\python_for_visres
.
Tip: if you need to switch partitions, first type partition letter (no cd
) and hit enter, e.g., D:
Terminal.app
or xterm
, or similar)cd
command, e.g. cd ~/python_for_visres
.ipython notebook
and hit enter. A new tab on your default browser should open with notebook choices listed. Doesn't work properly? Make sure you're not using an outdated or ridiculous browser (like some old Internet Explorer).Python scripts are just text files. If you want, you can open them using any text editor, even Notepad. However, it is best to use specialized text editors for the task because they help you to code. Although in this tutorial we rely exclusively on IPython to write and run our scripts, in real life people usually use other text editors or integrated developments environments (IDEs) to create and run their scripts. Here is a list of some of our favorites: