diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2016-06-18 16:32:39 -0700 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2016-06-18 16:32:39 -0700 |
commit | a63839708d6574567bcd518a822a9f10629ed80b (patch) | |
tree | 02c28e0856b62c08fd4d3622ee68d145d8eee6eb /pyspike/spikes.py | |
parent | d9e2125dcc76693056ab04264add29227f398f4f (diff) | |
parent | 4691d0e77a024fbc73d1098ee557d65f8f2ddc89 (diff) |
Merge branch 'import_time_series' into develop
Conflicts:
pyspike/__init__.py
resolved
Diffstat (limited to 'pyspike/spikes.py')
-rw-r--r-- | pyspike/spikes.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pyspike/spikes.py b/pyspike/spikes.py index ab6d4c4..486a4a0 100644 --- a/pyspike/spikes.py +++ b/pyspike/spikes.py @@ -62,6 +62,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 + + ############################################################ # save_spike_trains_to_txt ############################################################ |