Software¶
We use python for everything in our color laboratory: for adjusting the tubes and calibrating our booth; presenting stimuli; doing all kinds of measurements, and to control our photometer. In order to have everything handy and easy to use we wrote a python package called achrolab. All you need to do in order to use this package is to install python and psychopy on your computer. You will find how to do this all over the web, but here is a quick guide nonetheless.
Python and Psychopy¶
Windows¶
This is a step by step Tutorial on how to install python and psychopy on a lab PC running with Windows:
Download and install python 2.7: http://www.python.org/getit/
Download and install
- numpy
- scipy
- matplotlib
- pyglet
- pygame
- pyOpenGL
- Python Imaging Library (PIL)
- wxPython
- lxml
- pywin32
from http://www.lfd.uci.edu/~gohlke/pythonlibs/. It is important to download the packages from that website, because some compiled binaries for windows from other sites might have wrong compiling options (e.g. PIL needs to have the option for freefonts)
Download and install setuptools: http://pypi.python.org/pypi/setuptools#windows
Download and install psychopy by doing this in the command line: easy_install -U psychopy
Linux¶
Installing python and psychopy under Linux is normally much easier than under Windows. Most Linux distributions have all the necessary packages in their software-database. For installing everything in Ubuntu Linux, e.g., just type the following in your terminal:
sudo apt-get install psychopy
This will normally install psychopy (python 2.7 should be installed by default) with all its dependencies. If a package is missing, just try one of these:
sudo apt-get install <packagename>, <python-packagename>, <pypackagename>
Git and Github¶
All our software is version controlled using git. The python package achrolab can be found on github and is freely available for everybody (see the package for information on license).
Git Start Up¶
Install git on your computer. You can download it from: http://git-scm.com/.
Websites:
http://schacon.github.com/git/git.html
http://wiki.ubuntuusers.de/Git
We will run git from the bash (console).
Configuration (do this first!)
First, make your name and e-mail address known to git:
git config --global user.name "Firstname Lastname" git config --global user.email "yourname@yourhost.com"
Create a new repository for a new project
Change working directory to folder, where project is created:
cd MYPROJECT/
In this folder run:
git init
If you want to create a bare repository (for backup or similar) run:
git init --bare
To clone from an existing git folder use:
git clone PATH/TO/EXISTING/FOLDER
Then, you can add some files (you also have to use git add, when you have changed files):
git add FILENAME
To make changes available in the repository you have to commit them:
git commit -m "DESCRIPTION"
To show differences between your working copy and the last commit you can use:
git status
To show differences between a modified file and the previous version of this file type:
git diff FILENAME
To show comments of previous commits use:
git log
To get help type:
git help
To see changes and old versions in a nice gui try:
git gui
Push and pull from a usb stick
If you want to have your changes saved on a usb stick, first create a repository on the usb stick:
cd /PATH/TO/USB/STICK mkdir REPOSITORY-NAME cd REPOSITORY-NAME git init
Then pull your changes from your hard drive:
git pull file://PATH/TO/REPOS/ON/HARD/DRIVE/
You can also pull the other way around :).
You can push in the same way:
git push file://PATH/TO/REPOS/ON/HARD/DRIVE/
In case you have problems with the remote while pushing or pulling do:
git remote rm origin git remote add origin PATH/TO/ORIGINAL/FOLDER
Colored Git
Make git output a bit more colored:
git config --global --add color.ui true
Merging
To see what happend during a merge enable merge summary:
git config --global --add merge.summary true
Github How-To¶
How to get started with github (social coding):
- First make sure git is installed on your computer and get yourself acquainted with its functionality (see above).
- Go to github.com and create an account.
- The start up site provides a few walkthroughs to get you started. Definitely do the first (Set Up Git) right now!
- Now go to https://github.com/derNarr/achrolabutils and read the README.
- Be aware that everything you push to github.com is (normally) public and everyone can access your files.
Vim¶
If you are using Vim, here are some useful snippets for the vimrc (see some remarks on work flow in Stuff for Staff (Restricted)).
Status line with useful information:
"status line with useful information
set laststatus=2
if has("statusline")
set statusline=%<%f\ %h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\\"}%k[\%{&ff}][\%Y]\ %-14.(%l,%c%V%)\ %P
endif
Make text file readable under bash:
"no joint spaces
set nojoinspaces
"set text width
set tw=75
"set encoding
set encoding=utf-8
Enable automatic white spacing with tab key and automatic indentation for Python files (taken from http://py.vaults.ca/~x/python_and_vim.html):
"useful settings when working with Python
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set expandtab
set autoindent
set smartindent
autocmd BufRead python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
The following lines take the python_header.txt file in the .vim directory and put it as the header of every new python file. Then the header is filled with the file name, the year of creation, and the creation date.
The last three lines set the “last mod” part in the file to today’s date and add a short signature (“KS”):
"automatic header for new python files
autocmd bufnewfile *.py so ~/.vim/python_header.txt
autocmd bufnewfile *.py exe "1," . 10 . "g/<file>/s//" . expand("%")
autocmd bufnewfile *.py exe "1," . 10 . "g/<year>/s//" . strftime("%Y")
autocmd bufnewfile *.py exe "1," . 10 . "g/created.*/s//created " .strftime("%Y-%m-%d")
"change last mod automatically
autocmd Bufwritepre,filewritepre *.py execute "normal ma"
autocmd Bufwritepre,filewritepre *.py exe "1," . 10 . "g/last mod.*/s/last mod.*/last mod " .strftime("%Y-%m-%d") . " KS"
autocmd bufwritepost,filewritepost *.py execute "normal `a"
And here is the python_header.txt template (the dot in the last line is important):
:insert
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# <file>
#
# (c) <year> Konstantin Sering, Nora Umbach, Dominik Wabersich
# <colorlab[at]psycho.uni-tuebingen.de>
# GPL 3.0+ or (cc) by-sa (http://creativecommons.org/licenses/by-sa/3.0/)
#
# created
# last mod
#
.
Links¶
http://www.viemu.com/a-why-vi-vim.html
Why, oh WHY, do those #?@! nutheads use vi?