diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-12 18:49:37 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-12 18:49:37 +0200 |
commit | adc1e91c89aeecf3ee1743d3595b282061a22573 (patch) | |
tree | 0283d15e9e06ffbba19ceb63b0fa0650bcd57194 /pyspike/spikes.py | |
parent | 94408401e31830e7db7902afdeef714cb981bce2 (diff) |
added sort to load function, renamed test data file
Diffstat (limited to 'pyspike/spikes.py')
-rw-r--r-- | pyspike/spikes.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/pyspike/spikes.py b/pyspike/spikes.py index 9375e30..6ea94de 100644 --- a/pyspike/spikes.py +++ b/pyspike/spikes.py @@ -46,22 +46,26 @@ def add_auxiliary_spikes(spike_train, time_interval): ############################################################ # spike_train_from_string ############################################################ -def spike_train_from_string(s, sep=' '): +def spike_train_from_string(s, sep=' ', sort=True): """ Converts a string of times into an array of spike times. Args: - s: the string with (ordered) spike times - - sep: The separator between the time numbers. + - sep: The separator between the time numbers, default=' '. + - sort: If True, the spike times are order via `np.sort`, default=True. Returns: - array of spike times """ - return np.fromstring(s, sep=sep) + if sort: + return np.sort(np.fromstring(s, sep=sep)) + else: + return np.fromstring(s, sep=sep) ############################################################ # load_spike_trains_txt ############################################################ def load_spike_trains_from_txt(file_name, time_interval=None, - separator=' ', comment='#'): + separator=' ', comment='#', sort=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 @@ -78,13 +82,14 @@ def load_spike_trains_from_txt(file_name, time_interval=None, added to the spike train at the beginning and end of this interval. - separator: The character used to seprate the values in the text file. - comment: Lines starting with this character are ignored. + - sort: If true, the spike times are order via `np.sort`, default=True. """ spike_trains = [] spike_file = open(file_name, 'r') for line in spike_file: if len(line) > 1 and not line.startswith(comment): # use only the lines with actual data and not commented - spike_train = spike_train_from_string(line) + spike_train = spike_train_from_string(line, separator, sort) if not time_interval == None: # add auxiliary spikes if times given spike_train = add_auxiliary_spikes(spike_train, time_interval) spike_trains.append(spike_train) |