Brian/StimulusArrayGroup

2D stimulus array group

This code is for creating a group of neurons which fire with a given 2D stimulus at a given rate. You initialise it with arguments:

  • stimulus, which should be a 2D array with values between 0 and 1.
  • rate, which should be a firing rate in Hz.
  • onset, the time that the stimulus should become active.
  • duration, the length of time for which the stimulus should be active.

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.

Code snippet

The StimulusArrayGroup class is defined as follows:

class StimulusArrayGroup(PoissonGroup):
    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)

An example use, where the stimulus is a 100x100 image with a 10 pixel thick bar at 90 degrees to the vertical, firing at rate 50 Hz from 100ms to 200ms:

stim = bar(100,100,10,90)
G = StimulusArrayGroup(stim, 50*Hz, 100*ms, 100*ms)

The complete code is attached as file stim2d.py Download.

Technical details

The way it works is that the StimulusArrayGroup class is derived from PoissonGroup which fires with a given 1-dimensional array of rates, or in this case, a function of time that returns a 1-dimensional array of rates. The StimulusArrayGroup class just unravels the 2D stimulus array to a 1D array and initialises the PoissonGroup with a function that returns this array between onset and onset+duration.

Attachments