Holcombe:Programming: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:Holcombe}}
{{Template:Holcombe}}
To understand Dani's programs, there are two steps.  First, you must learn Spanish.


Mostly the lab uses [http://www.visionegg.org VisionEgg] (also see [http://www.freelists.org/archives/visionegg/ mailing list] and [http://www.psychopy.org PsychoPy] python libraries to help draw stuff.  
==Psychopy==
Mostly the lab uses [http://www.psychopy.org PsychoPy]. Some are still using VisionEgg. Both are libraries to help python code draw stuff.


Our [[Holcombe:Psychopy| psychopy notes]].
Some [http://sapir.psych.wisc.edu/wiki/index.php/Psych711 nice easy programming exercises] for Psychopy available from Gary Lupyan, developed for his postgrad psych class.
==Installing Visionegg and Psychopy==
Get your Psychopy programming questions answered at the [http://groups.google.com/group/psychopy-users mailing list].
*WINDOWS: Psychopy installation. It is easier to intall Enthought Python Distribution that contains all the necessary dependencies than to install at hand one by one the dependencies. Using Enthought, however, I found incompatibilities with Visionegg. Installing the dependencies at hand I did not have problems to run both programs in the same computer. 
*OSX confusingly has two places for Python, /System/Library/... and also /Library/... You want to use /Library version. Some [http://wiki.python.org/moin/MacPython/Leopard python installation instructions], [http://stackoverflow.com/questions/118813/how-do-i-uninstall-python-from-osx-leopard-so-that-i-can-use-the-macports-versi related issue]


Site packages (like visionegg) should reside in a directory given by, at python prompt:<code> from distutils.sysconfig import get_python_lib; print get_python_lib() </code>
If you're moving to Psychopy/Python from Matlab, SciPy has a good introduction to [http://www.scipy.org/NumPy_for_Matlab_Users/ Python for Matlab Users], with a big list of equivalent expressions in the two languages.
[http://www.python.org/doc/2.5.1/inst/standard-install.html Everything] I didn't want to know about installing python packages


==Python programming==
Our [[Holcombe:Psychopy| psychopy and visionegg installation notes]] .
Here is a file [[Media:Matlab-python-xref.pdf‎]] that gives equivalent code for doing array operations in MATLAB, Python, and R


<code>rehash toolbox</code> in MATLAB is <code>reload(modulename)</code> in python
To understand Dani's programs, there are two steps. First, you must learn Spanish.
 
<code>clear all</code> in MATLAB is <code>[vars().__delitem__(_k) for _k in vars().keys() if not _k.startswith('_')]</code> in python


Good syntax guide [http://codesyntax.netfirms.com/lang-python.htm here] ,  Explanation of how default assignment creates reference rather than new variable [http://www.gossamer-threads.com/lists/python/python/617333 here] says to use deepcopy()
==Python programming (outside of the Psychopy editor, as is required for VisionEgg)==
 
Here [[Media:AudioAndUSBnotesWithPython.oo3]] is the file with all my notes on different ways to play a sound in Python and the  associated latencies and standard deviations of the latencies--[[User:Alex O. Holcombe|Alex O. Holcombe]] 05:15, 25 June 2008 (UTC)


Running python interactively from the Terminal alone is frustrating because you can't use arrow keys for history, no auto-complete, etc. You will probably want to use some [[Holcombe:PythonIDEs| IDE]].
Running python interactively from the Terminal alone is frustrating because you can't use arrow keys for history, no auto-complete, etc. You will probably want to use some [[Holcombe:PythonIDEs| IDE]].
Line 34: Line 26:
  #### e.g. 'aBindingExpData_04_Aug_2008_22:46'
  #### e.g. 'aBindingExpData_04_Aug_2008_22:46'
</code>
</code>
Also don't lose track of what program generated the data, take advantage of sys.argv which gives the invoking program name and include code something like:
<code>
import sys
print >>logF, 'running script "',sys.argv[0],'"'


[http://pages.physics.cornell.edu/~myers/teaching/ComputationalMethods/python/arrays.html scipy array tip sheet]
==Data analysis==
==Data analysis==
===R data analysis===
[[Holcombe:ProgrammingInR| programming in R (data analysis)]]
[[Holcombe:ProgrammingInR| programming in R (data analysis)]]
===Python data analysis===
[[Holcombe:PythonDataAnalysis| Python programming for data analysis]]
Can be done in Python use SciPy which includes matplotlib ([http://matplotlib.sourcearchive.com/documentation/0.98.1/classmatplotlib_1_1text_1_1Text.html ref])
(Not necessary: after downloading SciPy I updated to the more recent version of matplotlib using matplotlib-0.98.5.2-py2.5-mpkg.zip for OSX, which installs in /Library/Python/2.5/site-packages/ and I needed to add that directory to my PYTHONPATH in my .profile file in my home directory)
 
See the [http://matplotlib.sourceforge.net/faq/howto_faq.html HowTo] and Cookbook,
[http://banyan.usc.edu/log/python/plot#plots-sharing-x-axis-or-overlapping-plots-with-two-different-scales double-axis plotting]
 
loadtxt seems to return recarray [http://www.meliza.org/itoaeky/graphics.php explanation]

Revision as of 17:20, 4 July 2012

Recent members

Alex Holcombe
• Ryo Nakayama



Technical

Skills Checklist
Python Programming
Psychopy/VisionEgg Installation Notes
R analysis,plot,stats
Statistics
Buttonbox
Buttonbox with photocell
Programming Cheat Sheets



Psychopy

Mostly the lab uses PsychoPy. Some are still using VisionEgg. Both are libraries to help python code draw stuff.

Some nice easy programming exercises for Psychopy available from Gary Lupyan, developed for his postgrad psych class. Get your Psychopy programming questions answered at the mailing list.

If you're moving to Psychopy/Python from Matlab, SciPy has a good introduction to Python for Matlab Users, with a big list of equivalent expressions in the two languages.

Our psychopy and visionegg installation notes .

To understand Dani's programs, there are two steps. First, you must learn Spanish.

Python programming (outside of the Psychopy editor, as is required for VisionEgg)

Running python interactively from the Terminal alone is frustrating because you can't use arrow keys for history, no auto-complete, etc. You will probably want to use some IDE.

never have your data file overwritten again! include the following lines in your python code:

from time import localtime,strftime
timeAndDateStr = strftime("%d_%b_%Y_%H:%M", localtime())
filename = 'aBindingExpData_'    #include here whatever you want
filename = filename + timeAndDateStr  #filename will now have date time and year tacked on the end,
outputFileStream = open(filename, 'a')
#### e.g. 'aBindingExpData_04_Aug_2008_22:46'

Also don't lose track of what program generated the data, take advantage of sys.argv which gives the invoking program name and include code something like: import sys print >>logF, 'running script "',sys.argv[0],'"'

scipy array tip sheet

Data analysis

programming in R (data analysis) Python programming for data analysis