예제 #1
0
파일: Utils.py 프로젝트: vitay/ANNarchy
def raster_plot(spikes):
    """
    Transforms recorded spikes to display easily a raster plot for a spiking population.

    It returns a (N, 2) Numpy array where each spike (first index) is represented by the 
    corresponding time (first column) and the neuron index (second column).  
    It can be very easily plotted, for example with matplotlib::

        monitor = Monitor(pop, 'spike')
        simulate(1000.0)
        times, ranks = raster_plot(monitor.get('spike'))
        from matplotlib.pyplot import *
        plot(times, ranks, '.')
        show()

    *Parameters*:

    * **spikes**: the dictionary returned by the Monitor.get(...) method earlier.
    """
    ranks = []
    times = []

    if 'spike' in spikes.keys():
        data = spikes['spike']
    else:
        data = spikes

    # Compute raster
    for n in data.keys():
        for t in data[n]:
            times.append(t)
            ranks.append(n)

    return Global.dt()* np.array(times), np.array(ranks)
예제 #2
0
def raster_plot(spikes):
    """
    Transforms recorded spikes to display easily a raster plot for a spiking population.

    It returns a (N, 2) Numpy array where each spike (first index) is represented by the corresponding time (first column) and the neuron index (second column).  It can be very easily plotted, for example with matplotlib::

        >>> monitor = Monitor(Pop, 'spike')
        >>> times, ranks = raster_plot( monitor.get('spike')
        >>> from pylab import *
        >>> plot(times, ranks, 'o')
        >>> show()

    *Parameters*:

    * **spikes**: the dictionary returned by the Monitor.get(...) method earlier.
    """
    ranks = []
    times = []

    if 'spike' in spikes.keys():
        data = spikes['spike']
    else:
        data = spikes

    # Compute raster
    for n in data.keys():
        for t in data[n]:
            times.append(t)
            ranks.append(n)

    return Global.dt() * np.array(times), np.array(ranks)