Difference between revisions of "Holcombe:Psychopy"

From OpenWetWare
Jump to: navigation, search
(VisionEgg Installation experience for ShihYu on MacBook OSX10.5)
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{Template:Holcombe}}
 
{{Template:Holcombe}}
  
*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. 
+
[[Holcombe:VisionEgg|VisionEgg installation notes]]
*OSX
 
  
Site packages (like visionegg and psychopy non-standalone version) should reside in a directory given by, at python prompt:
+
=Psychopy=
<code>
+
Most will want to simply download the .dmg of the executable from the psychopy website.
from distutils.sysconfig import *
 
print get_python_lib() </code>
 
OSX confusingly has three places for Python packages, /System/Library/... and /Library/Python/2.5/site-packages and also /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages You probably want to use /Library/Frameworks/... version. (why are silverTow, sarah's iMac, and Kuna laptop all set to /Library/Python and how do I change that? Kuna nevertheless finds packages in /Library/Frameworks)  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]
 
  
 +
==Developers==
 +
Developers can install a local version of the repository using github. See the instructions at the online psychopy documentation "for developers" section.
 +
Also see [http://groups.google.com/group/psychopy-dev/browse_thread/thread/a06b4a5e408d751f| these messages on the google group]
  
 +
This requires installation of the python library dependencies. On OSX, rather than installing all the dependencies one by one, you can download and run the installer for the Enthought Python Distribution. At the time of this writing (Feb 2012), it's available for free to academics.
 +
Once that is done, execute psychopy in the terminal with something like
  
[http://www.python.org/doc/2.5.1/inst/standard-install.html Everything] I didn't want to know about installing python packages
+
python /Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/psychopy/app/psychopyApp.py
  
If you want to grab code from the bleeding edge repository version, you better know what's in [[Holcombe:SubversionEtc|subversion etc notes]]
+
Rather than type that every time, create an alias, maybe called 'pp', by adding a line to your ~/.profile like this:
Also info there in [[Holcombe:SubversionEtc|subversion etc notes]] about accessing standalone PsychopyIDE libraries from a terminal session.
+
alias pp='python /Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/psychopy/app/psychopyApp.py'
 +
 +
Psychopy will only run if the location of the dependencies is in your PYTHONPATH. Most of these will have been added by the Enthought Python Distrubtion installer, but not psychopy itself. To your ~/.profile file, add the path of psychopy itself with a line like:
 +
PYTHONPATH="/Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/:$PYTHONPATH
  
==VisionEgg Installation experience for ShihYu  on MacBook OSX10.5==
+
z
easy_install VisionEgg
 
executes and puts the .egg in /sw/lib/python2.5/site-packages
 
But import VisionEgg still failed.  Adding the VisionEgg egg directories to the python path didn't help.
 
When Fahed moved the VisionEgg directory to the site-packages directory where other packages live, it worked!
 
 
 
However, "import pygame" does not work and said we have the wrong version of PyObjC. We downloaded pyobjc-1.4-py2.5-macosx10.4.mpkg.zip from where it was linked to at http://pygame.org/wiki/PyObjC
 
Then pygame worked.
 
 
 
==Installation experience of Fahed on Linux==
 
 
 
The following error:
 
<code>
 
  /usr/lib/python2.5/site-packages/scipy/sparse/linalg/dsolve/linsolve.py:20
 
      ' install scikits.umfpack instead', DeprecationWarning )
 
</code>
 
 
 
can be resolved by downloading this zip file [http://projects.scipy.org/scipy/changeset/5214?format=zip&new=5214 Scikits.umfpack] and placing the linsolve file within in the appropriate python directory.
 
 
 
(search scikits.umfpack in google and download the latest).
 
 
 
==installation experience with python2.5 on Intel laptop  --[[User:Alex O. Holcombe|Alex O. Holcombe]] 01:58, 23 March 2009 (EDT)==
 
demos/mouse_pygame.py doesn't work because the default window type is pyglet, as revealed by
 
<code>
 
myWin = visual.Window((600.0,600.0), allowGUI=True, fullscrn=0)
 
myWin.winType  #gives you pyglet
 
</code>
 
Pre-python 2.4, pygame is used for mouse functions, sounds, and other things. Could force use of pygame:
 
<code>
 
myWin = visual.Window((600.0,600.0), allowGUI=True, fullscrn=0, winType="pygame")
 
</code>
 
However still the way we draw things in our programs doesn't work, not sure why. Ah, apparently going to python2.5 is supposed to use pyglet for everything, which requires different functions for mouse polling (see demo: mouse.py) and maybe other minor changes, see next section:
 
=== adapting to pyglet ===
 
*The 'depth=-1' kwarg which I was using for fixation now makes it invisible. Just delete it, we don't seem to need it
 
*The functions for polling the mouse have different names. I handle that by giving the functions the same names:
 
<code>
 
if win.winType == 'pyglet':
 
  myMouse = event.Mouse(win=win)
 
  getRelMouseCoords = myMouse.getRel
 
  getMouseButtons = myMouse.getPressed
 
else:
 
  myMouse = event.mouse #pygame
 
  getRelMouseCoords = myMouse.get_rel
 
  getMouseButtons = myMouse.get_pressed
 
</code>
 
 
 
=== older ===
 
I think I didn't use that version (with pyglet extensions) with 2.5 yet. Will try to look into it.
 
 
 
I think it's to do with PsychoPy selecting the wrong openGL to draw to (PyOpenGL and pyglet.GL aren't compatible and require different argument types). I should be able to look into it, but could you let me know which version of Pyglet (if any) you've installed?
 
 
 
cheers, as ever, for the useful feedback,
 
Jon
 
 
 
Alex Holcombe wrote:
 
Hi Jon,
 
We have a new machine and decided to try using psychopy with python2.5.  We installed from source PsychoPy-0.93.4 and tried to install the dependencies correctly by going through the list in the dependenciesOSXuniversal package for python2.4, and finding the appropriate packages on the web for python2.5. Unfortunately upon running the psychopy demos we get an error triggered by the visual.Patchstim commands, for example upon running clockface.py we get the following output:
 
 
 
------------------
 
Traceback (most recent call last):
 
File "clockface.py", line 12, in <module>
 
  tex=None, mask=minHand,interpolate=False)
 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/psychopy/visual.py", line 1030, in __init__
 
  self._setTex(tex)
 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/psychopy/visual.py", line 1533, in _setTexNoShaders
 
  GL.glBindTexture(GL.GL_TEXTURE_1D, self.texID)#bind that name to the target
 
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong type
 
------------------
 
 
 
We can go back to using psychopy with python2.4 if necessary, but I thought I'd let you know about this as you mentioned on the webpage that you might provide Python2.5 installers if someone asked.  Incidentally, even other demo programs not dependent on visual seem to get errors, such as demo_sound.py, which gives the output at the bottom of this email.  Anyway no worries if you don't have time for this, thanks for all the code, we're happily using psychopy in conjunction with some visionEgg for all our experiments now.
 
 
 
cheers
 
Alex
 
 
 
------------------
 
Traceback (most recent call last):
 
File "demo_sound.py", line 4, in <module>
 
  sound.init(rate=22050, bits=16, stereo=True, buffer=1024)
 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/psychopy/sound.py", line 67, in init
 
  mixer.init(rate, bits, stereoChans, buffer) #defaults: 22050Hz, 16bit, stereo,
 
pygame.error: Failed to start CoreAudio: AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)
 
 
 
 
 
 
 
On 26/02/2008, at 4:50 AM, Jon Peirce wrote:
 
 
 
Hi Alex,
 
two options. This is the code I used just to get thigns going, and tested against a parallel port on winXP. Pyglet sounds can be used alongside pygame for windowing etc... so that you don't need to change too much other code. One thing you should be aware of is the need to dispatch_events() for pyglet.media
 
 
 
Alternatively, the pyglet backend for PsychoPy is nearly there. The only things missing are a set.gamma function for the window (do you need gamma correction?) and controls for the mouse. I'll try and have a new OS X build for you to play with in the next 1/2 hr. Obviously, going this route will need a bit more testing at your end to make sure it
 
 
 
chrs, Jon
 
 
 
 
 
#############
 
#test the speed of a keypress detection
 
import ctypes, numpy
 
from psychopy import event, visual, core, _parallel
 
import pyglet.media, pyglet.media.procedural
 
 
 
class ArraySnd(pyglet.media.procedural.ProceduralSource):
 
"""
 
Create a pyglet.StaticSource from a numpy array.
 
"""
 
def __init__(self, data, sample_rate=44800, sample_size=16):
 
    """Array data should be float (-+1.0)
 
    sample_size (16 or 8) determines the number of bits used for subsequent storage"""
 
    duration = len(data)/float(sample_rate) #determine duration from data
 
    super(ArraySnd, self).__init__(duration,sample_rate, sample_size)
 
    self.sample_rate = sample_rate
 
          if sample_size==8:          #ubyte
 
        self.allData = (data*127+127).astype(numpy.uint8)
 
    elif sample_size==16:      #signed int16
 
        self.allData = (data*32767).astype(numpy.int16)
 
      def _generate_data(self, bytes, offset):
 
    if self._bytes_per_sample == 1:#ubyte
 
        start = offset
 
        samples = bytes
 
    else:                        #signed int16
 
        start = offset >> 1
 
        samples = bytes >> 1
 
    return (self.allData[start:(start+samples)]).tostring()
 
def makeSine(duration, frequency=440, sample_rate=44800, sample_size=16):      step = frequency * (numpy.pi * 2) / sample_rate
 
samples = sample_rate*duration
 
snd = ArraySnd(numpy.sin(step*(numpy.arange(samples))), sample_rate, sample_size)
 
 
 
return snd
 
            win = visual.Window([200,200],winType='pygame')
 
 
 
A = makeSine(1, 220, sample_size=16)
 
#A = pyglet.media.procedural.Sine(1,220)
 
core.wait(0.1)
 
 
 
LPT1 = 0x378#address for parallel port on many machines
 
pinNumber = 2#choose a pin to write to (2-9).
 
A.play()
 
_parallel.out(LPT1, 2**(pinNumber-2))#sets just this pin to be high (pin2 represent databit 0, pin3=bit1...)
 
 
 
clock = core.Clock()
 
while clock.getTime()<5.0:
 
pyglet.media.dispatch_events()#have to call this or pyglet sound manager doesn't update its buffer
 
if len(event.getKeys())>0:
 
    break
 
core.wait(0.01)
 
_parallel.out(LPT1, 0)#sets all pins low
 

Latest revision as of 16:58, 24 February 2012

Members

Alex Holcombe
Polly Barr
• Charlie Ludowici
• Kim Ransley
• Ingrid Van Tongeren
William Ngiam
Fahed Jbarah
• Patrick Goodbourn
Alumni



Technical

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



VisionEgg installation notes

Psychopy

Most will want to simply download the .dmg of the executable from the psychopy website.

Developers

Developers can install a local version of the repository using github. See the instructions at the online psychopy documentation "for developers" section. Also see these messages on the google group

This requires installation of the python library dependencies. On OSX, rather than installing all the dependencies one by one, you can download and run the installer for the Enthought Python Distribution. At the time of this writing (Feb 2012), it's available for free to academics. Once that is done, execute psychopy in the terminal with something like

python /Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/psychopy/app/psychopyApp.py

Rather than type that every time, create an alias, maybe called 'pp', by adding a line to your ~/.profile like this:

alias pp='python /Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/psychopy/app/psychopyApp.py'

Psychopy will only run if the location of the dependencies is in your PYTHONPATH. Most of these will have been added by the Enthought Python Distrubtion installer, but not psychopy itself. To your ~/.profile file, add the path of psychopy itself with a line like:

PYTHONPATH="/Users/alex/Documents/softwareStatsEquipment/programming_psychophysics/psychopy/:$PYTHONPATH
z