summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2015-06-12 14:55:07 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2015-06-12 14:55:07 +0200
commitd6462d271aeaf1be635cbc7c4317ae6a3b30b63f (patch)
tree2280fb876ae6082e608020af31c15e16ce67412b
parent2b957ac5d7c964b6fe0e99bb078a396732331869 (diff)
implement __getitem__ and __len__ for SpikeTrain
This allows to use SpikeTrain objects to be used in many applications as if they were arrays with spike times.
-rw-r--r--pyspike/SpikeTrain.py15
-rw-r--r--pyspike/spikes.py3
2 files changed, 17 insertions, 1 deletions
diff --git a/pyspike/SpikeTrain.py b/pyspike/SpikeTrain.py
index 9127b60..4b59a5d 100644
--- a/pyspike/SpikeTrain.py
+++ b/pyspike/SpikeTrain.py
@@ -32,6 +32,21 @@ class SpikeTrain(object):
self.t_start = 0.0
self.t_end = float(edges)
+ def __getitem__(self, index):
+ """ Returns the time of the spike given by index.
+
+ :param index: Index of the spike.
+ :return: spike time.
+ """
+ return self.spikes[index]
+
+ def __len__(self):
+ """ Returns the number of spikes.
+
+ :return: Number of spikes.
+ """
+ return len(self.spikes)
+
def sort(self):
""" Sorts the spike times of this spike train using `np.sort`
"""
diff --git a/pyspike/spikes.py b/pyspike/spikes.py
index 35d8533..b18d7eb 100644
--- a/pyspike/spikes.py
+++ b/pyspike/spikes.py
@@ -28,7 +28,8 @@ def spike_train_from_string(s, edges, sep=' ', is_sorted=False):
# load_spike_trains_txt
############################################################
def load_spike_trains_from_txt(file_name, edges,
- separator=' ', comment='#', is_sorted=False):
+ separator=' ', comment='#', is_sorted=False,
+ ignore_empty_lines=True):
""" Loads a number of spike trains from a text file. Each line of the text
file should contain one spike train as a sequence of spike times separated
by `separator`. Empty lines as well as lines starting with `comment` are