diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2016-06-18 16:27:51 -0700 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2016-06-18 16:27:51 -0700 |
commit | 4691d0e77a024fbc73d1098ee557d65f8f2ddc89 (patch) | |
tree | 27340d0c5d921ab8389e078559e02e9303894209 /pyspike | |
parent | c17cc8602414cec883c412008a4300b2c7ac7f80 (diff) |
added function to import time series
new function import_spike_trains_from_time_series that loads spike trains
from time series.
Diffstat (limited to 'pyspike')
-rw-r--r-- | pyspike/__init__.py | 1 | ||||
-rw-r--r-- | pyspike/spikes.py | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/pyspike/__init__.py b/pyspike/__init__.py index 069090b..1e879c4 100644 --- a/pyspike/__init__.py +++ b/pyspike/__init__.py @@ -24,6 +24,7 @@ from .spike_sync import spike_sync_profile, spike_sync,\ from .psth import psth from .spikes import load_spike_trains_from_txt, spike_train_from_string, \ + import_spike_trains_from_time_series, \ merge_spike_trains, generate_poisson_spikes # define the __version__ following diff --git a/pyspike/spikes.py b/pyspike/spikes.py index b18d7eb..1bf474c 100644 --- a/pyspike/spikes.py +++ b/pyspike/spikes.py @@ -57,6 +57,31 @@ def load_spike_trains_from_txt(file_name, edges, return spike_trains +def import_spike_trains_from_time_series(file_name, start_time, time_bin, + separator=None, comment='#'): + """ Imports spike trains from time series consisting of 0 and 1 denoting + the absence or presence of a spike. Each line in the data file represents + one spike train. + + :param file_name: The name of the data file containing the time series. + :param edges: A pair (T_start, T_end) of values representing the + start and end time of the spike train measurement + or a single value representing the end time, the + T_start is then assuemd as 0. + :param separator: The character used to seprate the values in the text file + :param comment: Lines starting with this character are ignored. + + """ + data = np.loadtxt(file_name, comments=comment, delimiter=separator) + time_points = start_time + time_bin + np.arange(len(data[0, :]))*time_bin + spike_trains = [] + for time_series in data: + spike_trains.append(SpikeTrain(time_points[time_series > 0], + edges=[start_time, + time_points[-1]])) + return spike_trains + + ############################################################ # merge_spike_trains ############################################################ |