Differences between revisions 9 and 10
Revision 9 as of 2010-06-25 11:42:29
Size: 1888
Editor: 10
Comment:
Revision 10 as of 2010-06-25 11:52:30
Size: 4820
Editor: 10
Comment:
Deletions are marked like this. Additions are marked like this.
Line 36: Line 36:
== glueing using Traits ==

 * controller {{{
#!python

# HasTraits class that supplies the callable for the timer event.
class TimerController(HasTraits):
    def onTimer(self, *args):
        global hist
        im = get_webcam_data()
        corr, Vm = neuron(im)
        corr_data = self.corr_data.get_data('corr')
        corr_data = hstack((corr_data[1:], transpose([corr])))
        self.corr_data.set_data('corr', corr_data)

        Vm_data = self.Vm_data.get_data('Vm')
        Vm_data = hstack((Vm_data[1:], transpose([Vm])))
        self.Vm_data.set_data('Vm', Vm_data)

        self.webcam_plotdata.set_data('imagedata', im)
        self.corr_plot.request_redraw()
        return
}}}

 * plotting {{{
#!python

#============================================================================
# Create the Chaco plot.
#============================================================================

def _create_plot_component(obj):
    # corr plot
    times = linspace(0., 1, num=NUM_SAMPLES)
    obj.corr_data = ArrayPlotData(time=times)
    empty_corr = zeros(NUM_SAMPLES)
    obj.corr_data.set_data('corr', empty_corr)

    obj.corr_plot = Plot(obj.corr_data)
    obj.corr_plot.plot(("time", "corr"), name="corr", color="red")
    obj.corr_plot.padding = 50
    obj.corr_plot.title = "Linear Correlation"
    corr_range = obj.corr_plot.plots.values()[0][0].value_mapper.range
    corr_range.low = -1.0
    corr_range.high = 1.0
    obj.corr_plot.index_axis.title = 'Time (seconds)'
    obj.corr_plot.value_axis.title = 'Correlation'

    # Vm plot
    obj.Vm_data = ArrayPlotData(time=times)
    empty_Vm = zeros(NUM_SAMPLES)
    obj.Vm_data.set_data('Vm', empty_Vm)

    obj.Vm_plot = Plot(obj.Vm_data)
    obj.Vm_plot.plot(("time", "Vm"), name="Time", color="blue")
    obj.Vm_plot.padding = 50
    obj.Vm_plot.title = "Neuron's potential"
    obj.Vm_plot.index_axis.title = 'Time (seconds)'
    obj.Vm_plot.value_axis.title = 'Amplitude'
    Vm_range = obj.Vm_plot.plots.values()[0][0].value_mapper.range
    Vm_range.low = 0.
    Vm_range.high = 1.

    # Webcam
    webcam_data = zeros((N_X, N_Y))
    obj.webcam_plotdata = ArrayPlotData()
    obj.webcam_plotdata.set_data('imagedata', webcam_data)
    webcam_plot = Plot(obj.webcam_plotdata)
    webcam_x = linspace(0.0, 1, num=N_X+1)
    webcam_y = linspace(0.0, 1, num=N_Y+1)
    webcam_plot.img_plot('imagedata',
                              name='webcam',
                              colormap=jet,
                              )
    range_obj = webcam_plot.plots['webcam'][0].value_mapper.range
    range_obj.high = 1.0
    range_obj.low = 0.0
    webcam_plot.title = 'webcam'
    obj.webcam_plot = webcam_plot

    container = HPlotContainer()
    container.add(obj.webcam_plot)
    container.add(obj.corr_plot)
    container.add(obj.Vm_plot)

    return container
 }}}

Putting the things together...

the "eye"

http://code.astraw.com/projects/motmot/_images/homepage.png

http://code.astraw.com/projects/motmot/_images/plugin-flytrax-linux-639x437.png

  • but it's good to install required libraries from motmot:

    sudo easy_install motmot.utils motmot.wxvalidatedtext  motmot.FlyMovieFormat  motmot.wxglvideo  motmot.wxvideo 

    so that you can run fview to test your isight (check Camera... Initialize camera).

http://code.astraw.com/projects/motmot/_images/ctrax-screenshot-tiny.jpg

the loudspeaker

  • for the demo script, you will need the pyaudio module:

    svn co https://www.portaudio.com/repos/portaudio/trunk portaudio
    cd portaudio/
    ./configure
    make
    sudo make install
    sudo /usr/bin/install -c -m 644 -m 644 ./include/pa_mac_core.h /usr/local/include/pa_mac_core.h
    sudo easy_install pyaudio

glueing using Traits

  • controller

       1 # HasTraits class that supplies the callable for the timer event.
       2 class TimerController(HasTraits):
       3     def onTimer(self, *args):
       4         global hist
       5         im = get_webcam_data()
       6         corr, Vm = neuron(im)
       7         corr_data = self.corr_data.get_data('corr')
       8         corr_data = hstack((corr_data[1:], transpose([corr])))
       9         self.corr_data.set_data('corr', corr_data)
      10 
      11         Vm_data = self.Vm_data.get_data('Vm')
      12         Vm_data = hstack((Vm_data[1:], transpose([Vm])))
      13         self.Vm_data.set_data('Vm', Vm_data)
      14 
      15         self.webcam_plotdata.set_data('imagedata', im)
      16         self.corr_plot.request_redraw()
      17         return
    
  • plotting

       1 #============================================================================
       2 # Create the Chaco plot.
       3 #============================================================================
       4 
       5 def _create_plot_component(obj):
       6     # corr plot
       7     times = linspace(0., 1, num=NUM_SAMPLES)
       8     obj.corr_data = ArrayPlotData(time=times)
       9     empty_corr = zeros(NUM_SAMPLES)
      10     obj.corr_data.set_data('corr', empty_corr)
      11 
      12     obj.corr_plot = Plot(obj.corr_data)
      13     obj.corr_plot.plot(("time", "corr"), name="corr", color="red")
      14     obj.corr_plot.padding = 50
      15     obj.corr_plot.title = "Linear Correlation"
      16     corr_range = obj.corr_plot.plots.values()[0][0].value_mapper.range
      17     corr_range.low = -1.0
      18     corr_range.high = 1.0
      19     obj.corr_plot.index_axis.title = 'Time (seconds)'
      20     obj.corr_plot.value_axis.title = 'Correlation'
      21 
      22     # Vm plot
      23     obj.Vm_data = ArrayPlotData(time=times)
      24     empty_Vm = zeros(NUM_SAMPLES)
      25     obj.Vm_data.set_data('Vm', empty_Vm)
      26 
      27     obj.Vm_plot = Plot(obj.Vm_data)
      28     obj.Vm_plot.plot(("time", "Vm"), name="Time", color="blue")
      29     obj.Vm_plot.padding = 50
      30     obj.Vm_plot.title = "Neuron's potential"
      31     obj.Vm_plot.index_axis.title = 'Time (seconds)'
      32     obj.Vm_plot.value_axis.title = 'Amplitude'
      33     Vm_range = obj.Vm_plot.plots.values()[0][0].value_mapper.range
      34     Vm_range.low = 0.
      35     Vm_range.high = 1.
      36 
      37     # Webcam
      38     webcam_data = zeros((N_X, N_Y))
      39     obj.webcam_plotdata = ArrayPlotData()
      40     obj.webcam_plotdata.set_data('imagedata', webcam_data)
      41     webcam_plot = Plot(obj.webcam_plotdata)
      42     webcam_x = linspace(0.0, 1, num=N_X+1)
      43     webcam_y = linspace(0.0, 1, num=N_Y+1)
      44     webcam_plot.img_plot('imagedata',
      45                               name='webcam',
      46                               colormap=jet,
      47                               )
      48     range_obj = webcam_plot.plots['webcam'][0].value_mapper.range
      49     range_obj.high = 1.0
      50     range_obj.low = 0.0
      51     webcam_plot.title = 'webcam'
      52     obj.webcam_plot = webcam_plot
      53 
      54     container = HPlotContainer()
      55     container.add(obj.webcam_plot)
      56     container.add(obj.corr_plot)
      57     container.add(obj.Vm_plot)
      58 
      59     return container
    

welcome: please sign in