File: examples-misc_stim2d.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (76 lines) | stat: -rw-r--r-- 2,360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
.. currentmodule:: brian

.. index::
   pair: example usage; subplot
   pair: example usage; run
   pair: example usage; show
   pair: example usage; raster_plot
   pair: example usage; imshow
   pair: example usage; PoissonGroup
   pair: example usage; SpikeMonitor
   pair: example usage; bar
   pair: example usage; axis

.. _example-misc_stim2d:

Example: stim2d (misc)
======================

Example of a 2D stimulus, see the
`complete description <http://neuralensemble.org/cookbook/wiki/Brian/StimulusArrayGroup>`__
at the Brian Cookbook.

::

    
    from brian import *
    import scipy.ndimage as im
    
    __all__ = ['bar', 'StimulusArrayGroup']
    
    def bar(width, height, thickness, angle):
        '''
        An array of given dimensions with a bar of given thickness and angle
        '''
        stimulus = zeros((width, height))
        stimulus[:, int(height / 2. - thickness / 2.):int(height / 2. + thickness / 2.)] = 1.
        stimulus = im.rotate(stimulus, angle, reshape=False)
        return stimulus
    
    
    class StimulusArrayGroup(PoissonGroup):
        '''
        A group of neurons which fire with a given stimulus at a given rate
        
        The argument ``stimulus`` should be a 2D array with values between 0 and 1.
        The point in the stimulus array at position (y,x) will correspond to the
        neuron with index i=y*width+x. This neuron will fire Poisson spikes at
        ``rate*stimulus[y,x]`` Hz. The stimulus will start at time ``onset``
        for ``duration``.
        '''
        def __init__(self, stimulus, rate, onset, duration):
            height, width = stimulus.shape
            stim = stimulus.ravel()*rate
            self.stimulus = stim
            def stimfunc(t):
                if onset < t < (onset + duration):
                    return stim
                else:
                    return 0. * Hz
            PoissonGroup.__init__(self, width * height, stimfunc)
    
    if __name__ == '__main__':
        import pylab
        subplot(121)
        stim = bar(100, 100, 10, 90) * 0.9 + 0.1
        pylab.imshow(stim, origin='lower')
        pylab.gray()
        G = StimulusArrayGroup(stim, 50 * Hz, 100 * ms, 100 * ms)
        M = SpikeMonitor(G)
        run(300 * ms)
        subplot(122)
        raster_plot(M)
        axis(xmin=0, xmax=300)
        show()