diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2015-04-27 18:16:12 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2015-04-27 18:16:12 +0200 |
commit | 2336f1fcf28efeb23e8450f407a008b8032edd5e (patch) | |
tree | b1ee74ef8dab17806715da799b220e44aa6dcb62 /pyspike | |
parent | ecc7898a0b6cd5bc353fd246f3ad549934c82229 (diff) |
adjusted PSTH, added to doc index
Diffstat (limited to 'pyspike')
-rw-r--r-- | pyspike/psth.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/pyspike/psth.py b/pyspike/psth.py index 8516460..4027215 100644 --- a/pyspike/psth.py +++ b/pyspike/psth.py @@ -1,27 +1,34 @@ -""" - -Module containing functions to compute the PSTH profile - -Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net> - -Distributed under the BSD License -""" +# Module containing functions to compute the PSTH profile +# Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net> +# Distributed under the BSD License import numpy as np from pyspike import PieceWiseConstFunc -# Computes the Peristimulus time histogram of a set of spike trains +# Computes the peri-stimulus time histogram of a set of spike trains def psth(spike_trains, bin_size): - - bins = int((spike_trains[0][-1] - spike_trains[0][0]) / bin_size) - - N = len(spike_trains) - combined_spike_train = spike_trains[0][1:-1] + """ Computes the peri-stimulus time histogram of a set of + :class:`.SpikeTrain`. The PSTH is simply the histogram of merged spike + events. The :code:`bin_size` defines the width of the histogram bins. + + :param spike_trains: list of :class:`.SpikeTrain` + :param bin_size: width of the histogram bins. + :return: The PSTH as a :class:`.PieceWiseConstFunc` + """ + + bin_count = int((spike_trains[0].t_end - spike_trains[0].t_start) / + bin_size) + bins = np.linspace(spike_trains[0].t_start, spike_trains[0].t_end, + bin_count+1) + + # N = len(spike_trains) + combined_spike_train = spike_trains[0].spikes for i in xrange(1, len(spike_trains)): combined_spike_train = np.append(combined_spike_train, - spike_trains[i][1:-1]) + spike_trains[i].spikes) vals, edges = np.histogram(combined_spike_train, bins, density=False) + bin_size = edges[1]-edges[0] - return PieceWiseConstFunc(edges, vals/(N*bin_size)) + return PieceWiseConstFunc(edges, vals) # /(N*bin_size)) |