From 2336f1fcf28efeb23e8450f407a008b8032edd5e Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Mon, 27 Apr 2015 18:16:12 +0200 Subject: adjusted PSTH, added to doc index --- doc/pyspike.rst | 8 ++++++++ examples/spike_sync.py | 2 +- pyspike/psth.py | 39 +++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/doc/pyspike.rst b/doc/pyspike.rst index a6dc1a0..74ab439 100644 --- a/doc/pyspike.rst +++ b/doc/pyspike.rst @@ -57,6 +57,14 @@ SPIKE-synchronization :undoc-members: :show-inheritance: +PSTH +........................................ +.. automodule:: pyspike.psth + :members: + :undoc-members: + :show-inheritance: + + Helper functions ........................................ .. automodule:: pyspike.spikes diff --git a/examples/spike_sync.py b/examples/spike_sync.py index 9e81536..37dbff4 100644 --- a/examples/spike_sync.py +++ b/examples/spike_sync.py @@ -40,7 +40,7 @@ plt.plot(x1, y1, '-k', lw=2.5, label="averaged SPIKE-Sync profile") plt.subplot(212) -f_psth = spk.psth(spike_trains, bin_size=5.0) +f_psth = spk.psth(spike_trains, bin_size=50.0) x, y = f_psth.get_plottable_data() plt.plot(x, y, '-k', alpha=1.0, label="PSTH") 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 - -Distributed under the BSD License -""" +# Module containing functions to compute the PSTH profile +# Copyright 2015, Mario Mulansky +# 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)) -- cgit v1.2.3