see source:trunk/src/spikes.py

the SpikeTrain class

  • This class defines a spike train as a list of the events times. Event times are given in a list (sparse representation) in ISO units (seconds).
    • spike_times is a list/numpy array of spike times
    • If dtis specified, the time values should be ints, and will be multiplied by dt, otherwise time values should be floats.
    • If t_start and t_stop are not specified, they are inferred from the data.
    • the format adopted for the representation is relative=False, quantized=False
    >>> s1 = SpikeTrain([0.0, 0.1, 0.2, 0.5])
    >>> s2 = SpikeTrain(numpy.array([0, 1, 2, 5]), dt=0.1)
    >>> assert all(s1.spike_times == s2.spike_times)
    >>> print s1.format(relative=True)
    [ 0.   0.1  0.1  0.3]
    >>> s1.isi()
    array([ 0.1,  0.1,  0.3])
    >>> s1.mean_firing_rate()
    8.0
    >>> s1.cv_isi()
    0.565685424949

*# TODO in the definition, should a spike train be ordered?

the SpikeList class

  • A SpikeList object is a list of SpikeTrain objects.
    >>> sl = SpikeList(3, [(0, 0.1), (1, 0.1), (0, 0.2)])
    >>> type( sl.spiketrain_list[0] )
    <type SpikeTrain>
    >>> sl.spiketrain_list[0].spike_times
    array([ 0.1,  0.2])
    >>> sl.as_ids_times()
    (array([0,0,1]), array([0.1,0.2,0.1]))
    >>> sl.as_ids_times(relative=True)
    (array([0,1,0]), array([0.1,0.0,0.1]))
    >>> sl.as_ids_times(quantized=0.01)
    (array([0,0,1]), array([10,20,10]))
    >>> sl.as_list_id_time()
    [(0,0.1), (0,0.2), (1,0.1)]
    >>> sl.as_id_list_times()
    [(0, array([0.1, 0.2])), (1, array([0.1]))]
    >>> sl.as_time_list_ids()
    [(0.1, [0,1]), (0.2, [0])]
    >>> sl.as_2byN_array()
    >>> array([[0,0,1],[0.1,0.2,0.1]])

  • spikes is a list/tuple of (id,t) tuples (id in range(0,N))
  • N is the total number of units TODO should be possibly a tuple in accordance with the dimension of a pyNN.Population
  • dt, t_start and t_stop are shared for all SpikeTrains

available functions

  • as_list_id_time: Returns a list/tuple of (id,t) tuples (id in range(0,N)).
  • as_list_id_list_time: Returns (list of ids, list of times).
  • tmpfile2spikelist(filename, N, t_start=None, t_stop=None):
    • Returns a SpikeList object from the tmp file saved by PyNN-NEST.
    • The input is the filename where pyNN stored the spike list and the discretization step dt. it returns the spike list represented as a list of events. Events are tuples (relative time since last event, neuron_id); neuron_id and time are integers
    • The PyNN-NEST format (with compatible_output=True) is:
      • a line commented,
      • then one line per event: absolute time in ms, GID (see function printSpikes in nest.py)

real-life example

# === Run simulation ==========
pyNN.Timer.start() # start timer on construction
pyNN.run(params['simtime'])
simCPUTime = pyNN.Timer.elapsedTime()
out_ON.printSpikes(out_ON_filename)
out_OFF.printSpikes(out_OFF_filename)
out_ON_DATA = tmpfile2spikelist(out_ON_filename,N**2, t_start=0.0, t_stop=params['simtime'])
out_OFF_DATA = tmpfile2spikelist(out_OFF_filename,N**2, t_start=0.0, t_stop=params['simtime'])

TODOs