diff options
Diffstat (limited to 'pyspike/SpikeTrain.py')
-rw-r--r-- | pyspike/SpikeTrain.py | 50 |
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]) |