summaryrefslogtreecommitdiff
path: root/pyspike/SpikeTrain.py
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2015-04-30 14:23:14 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2015-04-30 14:23:14 +0200
commit88c18727290d81ce6f6ff66862cea6da241c7c34 (patch)
tree47d1922a621becc87a4573fca9feb4acef821432 /pyspike/SpikeTrain.py
parent1b9f4ec0aee1281464cfcab02bb4c7c302dbbb00 (diff)
parent26d4dd11f80b1c0b4ab19e7cb74c77b61eaad90c (diff)
Merge pull request #4 from mariomulansky/develop0.2.0
merge develop
Diffstat (limited to 'pyspike/SpikeTrain.py')
-rw-r--r--pyspike/SpikeTrain.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/pyspike/SpikeTrain.py b/pyspike/SpikeTrain.py
new file mode 100644
index 0000000..a02b7ab
--- /dev/null
+++ b/pyspike/SpikeTrain.py
@@ -0,0 +1,50 @@
+# Module containing the class representing spike trains for PySpike.
+# Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net>
+# Distributed under the BSD License
+
+import numpy as np
+
+
+class SpikeTrain(object):
+ """ Class representing spike trains for the PySpike Module."""
+
+ def __init__(self, spike_times, edges, is_sorted=True):
+ """ Constructs the SpikeTrain.
+
+ :param spike_times: ordered array of spike times.
+ :param edges: The edges of the spike train. Given as a pair of floats
+ (T0, T1) or a single float T1, where then T0=0 is
+ assumed.
+ :param is_sorted: If `False`, the spike times will sorted by `np.sort`.
+
+ """
+
+ # TODO: sanity checks
+ if is_sorted:
+ self.spikes = np.array(spike_times, dtype=float)
+ else:
+ self.spikes = np.sort(np.array(spike_times, dtype=float))
+
+ try:
+ self.t_start = float(edges[0])
+ self.t_end = float(edges[1])
+ except:
+ self.t_start = 0.0
+ self.t_end = float(edges)
+
+ def sort(self):
+ """ Sorts the spike times of this spike train using `np.sort`
+ """
+ self.spikes = np.sort(self.spikes)
+
+ def copy(self):
+ """ Returns a copy of this spike train.
+ Use this function if you want to create a real (deep) copy of this
+ spike train. Simple assignment `t2 = t1` does not create a copy of the
+ spike train data, but a reference as `numpy.array` is used for storing
+ the data.
+
+ :return: :class:`.SpikeTrain` copy of this spike train.
+
+ """
+ return SpikeTrain(self.spikes.copy(), [self.t_start, self.t_end])