Debian Codegraph @

pyspike/psth.py

raw symbols SCIP
1 # Module containing functions to compute the PSTH profile
2 # Copyright 2015, Mario Mulansky <[email protected]>
3 # Distributed under the BSD License
4
5 import numpy as np
6 from pyspike import PieceWiseConstFunc
7
8
9 # Computes the peri-stimulus time histogram of a set of spike trains
10 def psth(spike_trains, bin_size):
11 """ Computes the peri-stimulus time histogram of a set of
12 :class:`.SpikeTrain`. The PSTH is simply the histogram of merged spike
13 events. The :code:`bin_size` defines the width of the histogram bins.
14
15 :param spike_trains: list of :class:`.SpikeTrain`
16 :param bin_size: width of the histogram bins.
17 :return: The PSTH as a :class:`.PieceWiseConstFunc`
18 """
19
20 bin_count = int((spike_trains[0].t_end - spike_trains[0].t_start) /
21 bin_size)
22 bins = np.linspace(spike_trains[0].t_start, spike_trains[0].t_end,
23 bin_count+1)
24
25 # N = len(spike_trains)
26 combined_spike_train = spike_trains[0].spikes
27 for i in range(1, len(spike_trains)):
28 combined_spike_train = np.append(combined_spike_train,
29 spike_trains[i].spikes)
30
31 vals, edges = np.histogram(combined_spike_train, bins, density=False)
32
33 bin_size = edges[1]-edges[0]
34 return PieceWiseConstFunc(edges, vals) # /(N*bin_size))