From 4691d0e77a024fbc73d1098ee557d65f8f2ddc89 Mon Sep 17 00:00:00 2001 From: Mario Mulansky Date: Sat, 18 Jun 2016 16:27:51 -0700 Subject: added function to import time series new function import_spike_trains_from_time_series that loads spike trains from time series. --- pyspike/__init__.py | 1 + pyspike/spikes.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'pyspike') 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 ############################################################ -- cgit v1.2.3