From 71059e8ec71133a2ab50b484d23ed033a497843c Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Mon, 27 Mar 2017 17:28:23 +0200 Subject: [PATCH 01/10] The function :func:`efel.io.load_neo_file()` reads data from any of the file formats supported by Neo and formats it for use in eFEL. --- docs/source/neoIO_example.rst | 39 ++++++++++++++++ docs/source/python_examples.rst | 1 + efel/io.py | 101 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 docs/source/neoIO_example.rst diff --git a/docs/source/neoIO_example.rst b/docs/source/neoIO_example.rst new file mode 100644 index 0000000..2b2809c --- /dev/null +++ b/docs/source/neoIO_example.rst @@ -0,0 +1,39 @@ +Reading different file formats +============================== + +Neo is a Python package which provides support for reading a wide range of neurophysiology file +formats, including Spike2, NeuroExplorer, AlphaOmega, Axon, Blackrock, Plexon and Tdt. + +The function :func:`efel.io.load_neo_file()` reads data from any of the file formats supported by +Neo and formats it for use in eFEL. + +As an example, suppose we have an .abf file containing a single trace. Since eFEL requires +information about the start and end times of the current injection stimulus, we provide these +times as well as the filename:: + + import efel + + data = efel.io.load_neo_file("path/first_file.abf", stim_start=200, stim_end=700) + +Since some file formats can contain multiple recording episodes (e.g. trials) and multiple +signals per episode, the function returns traces in a list of lists, like this:: + + data : [Segment_1, Segment_2, ..., Segment_n] + with Segment_1 = [Trace_1, Trace_2, ..., Trace_n] + +Since our file contains only a single recording episode, our list of traces is:: + + traces = data[0] + +which we pass to eFEL as follows:: + + features = efel.getFeatureValues(traces, ['AP_amplitude', 'voltage_base']) + +Stimulus information within the file +------------------------------------ + +Some file formats can store information about the current injection stimulus. In this second +example, the file contains an :class:`Epoch` object named "stimulation", so we don't need to +explicitly specify `stim_start` and `stim_end`:: + + data2 = efel.io.load_neo_file("path/second_file.h5") \ No newline at end of file diff --git a/docs/source/python_examples.rst b/docs/source/python_examples.rst index 43e084c..444adde 100644 --- a/docs/source/python_examples.rst +++ b/docs/source/python_examples.rst @@ -5,4 +5,5 @@ Python python_example1 deap_optimisation + neoIO_example diff --git a/efel/io.py b/efel/io.py index b822e95..40ba6d5 100644 --- a/efel/io.py +++ b/efel/io.py @@ -80,3 +80,104 @@ def load_fragment(fragment_url, mime_type=None): return fragment_content else: raise TypeError('load_fragment: unknown mime type %s' % mime_type) + + +def load_neo_file (file_name, stim_start=None, stim_end=None): + """ + This function uses the Neo module to load a data file and convert the data structure to be readable by eFEL. + + Parameters + ========== + file_name : string + path to the location of a Dependency file + stim_start : numerical value (ms) + Optional if there is an Epoch or two Events in the file + stim_end : numerical value (ms) + Optional if there is an Epoch or two Events in the file + + Epoch.name should be one of "stim", "stimulus", "stimulation", "current_injection" + First Event.name should be "stim_start", "stimulus_start", "stimulation_start", "current_injection_start" + Second Event.name should be one of "stim_end", "stimulus_end", "stimulation_end", "current_injection_end" + + The returned object is presented like this : + returned object : [Segments_1, Segments_2, ..., Segments_n] + Segments_1 = [Traces_1, Traces_2, ..., Traces_n] + """ + import numpy as np + import neo + import quantities as pq + + reader = neo.io.get_io(file_name) + blocks = reader.read() + + #this part of the code aim to find informations about stimulations, if stimulation time has not been specified in arguments. + if stim_start is None and stim_end is None : + for bl in blocks : + for seg in bl.segments : + for epoch in seg.epochs : + if epoch.name in ("stim", "stimulus", "stimulation", "current_injection"): + if stim_start is None : + epoch = epoch.rescale('ms').magnitude + stim_start = epoch[0] + stim_end = epoch[-1] + else : + raise ValueError('It seems that there are two epochs related to stimulation, the program does not know which one to chose') + + event_start = False + event_end = False + for event in seg.events : + if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : + if stim_start is None : + if event_start == False : + event = event.rescale('ms').magnitude + stim_start = event[0] + else : + raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' + +' The program does not know which one to chose') + + else : + raise ValueError('It seems that stimulation start time is defined in epochs and an event.' + +' The program does not know which one to chose') + + if event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : + if stim_end is None : + if event_end == False : + event = event.rescale('ms').magnitude + stim_end = event[-1] + + else : + raise ValueError('It seems that there are two events, or an epoch and an event, related to stimulation end.' + +' The program does not know which one to chose') + + else : + raise ValueError('It seems that stimulation end time is defined in epochs and an event.' + +' The program does not know which one to chose') + + if stim_start is None or stim_end is None : + raise ValueError('No stim_start or stim_end has been found inside epochs or events. You can directly specify their value as argument "stim_start" and "stim_end"') + + #this part of the code transform the data format. + efel_blocks = [] + for bl in blocks : + efel_segments = [] + for seg in bl.segments : + + traces = [] + count_traces = 0 + analogsignals = seg.analogsignals + + for sig in analogsignals : + traces.append({}) + + traces[count_traces]['T'] = sig.times.rescale('ms').magnitude + traces[count_traces]['V'] = sig.rescale('mV').magnitude + + traces[count_traces]['stim_start'] = [stim_start] + traces[count_traces]['stim_end'] = [stim_end] + + count_traces += 1 + + efel_segments.append(traces) + efel_blocks.append(efel_segments) + + return efel_blocks \ No newline at end of file From d725212db006abbe19f2a4e47c80194861b3a420 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Tue, 28 Mar 2017 09:04:52 +0200 Subject: [PATCH 02/10] Making small change in doc to hopefully trigger ci --- docs/source/neoIO_example.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/neoIO_example.rst b/docs/source/neoIO_example.rst index 2b2809c..cb6d59a 100644 --- a/docs/source/neoIO_example.rst +++ b/docs/source/neoIO_example.rst @@ -12,7 +12,6 @@ information about the start and end times of the current injection stimulus, we times as well as the filename:: import efel - data = efel.io.load_neo_file("path/first_file.abf", stim_start=200, stim_end=700) Since some file formats can contain multiple recording episodes (e.g. trials) and multiple @@ -36,4 +35,4 @@ Some file formats can store information about the current injection stimulus. In example, the file contains an :class:`Epoch` object named "stimulation", so we don't need to explicitly specify `stim_start` and `stim_end`:: - data2 = efel.io.load_neo_file("path/second_file.h5") \ No newline at end of file + data2 = efel.io.load_neo_file("path/second_file.h5") From 09ebee5fbacb48572beafa5f6ddbf47664947d70 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Tue, 28 Mar 2017 09:11:48 +0200 Subject: [PATCH 03/10] Reverting last commit --- docs/source/neoIO_example.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/neoIO_example.rst b/docs/source/neoIO_example.rst index cb6d59a..b2b29be 100644 --- a/docs/source/neoIO_example.rst +++ b/docs/source/neoIO_example.rst @@ -12,6 +12,7 @@ information about the start and end times of the current injection stimulus, we times as well as the filename:: import efel + data = efel.io.load_neo_file("path/first_file.abf", stim_start=200, stim_end=700) Since some file formats can contain multiple recording episodes (e.g. trials) and multiple From 0d0b761433f0abefa7104969ca74080351de0906 Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Thu, 30 Mar 2017 11:28:41 +0200 Subject: [PATCH 04/10] tests for load_neo_file + modification Added tests for load_neo_file with file test and a script to generate the files test Also corrected an error in the function --- efel/io.py | 58 +- efel/tests/neo_test_files/create_neo_files_test.py | 56 ++ .../neo_test_file_epoch_times.pickle | 539 ++++++++++++++++++ .../neo_test_file_events_time.pickle | 601 +++++++++++++++++++++ .../neo_test_file_events_time_incomplete.pickle | 531 ++++++++++++++++++ .../neo_test_files/neo_test_file_no_times.pickle | 428 +++++++++++++++ efel/tests/test_io.py | 48 ++ 7 files changed, 2236 insertions(+), 25 deletions(-) create mode 100644 efel/tests/neo_test_files/create_neo_files_test.py create mode 100644 efel/tests/neo_test_files/neo_test_file_epoch_times.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_events_time.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_no_times.pickle diff --git a/efel/io.py b/efel/io.py index 40ba6d5..79bbd7d 100644 --- a/efel/io.py +++ b/efel/io.py @@ -103,6 +103,7 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): returned object : [Segments_1, Segments_2, ..., Segments_n] Segments_1 = [Traces_1, Traces_2, ..., Traces_n] """ + import numpy as np import neo import quantities as pq @@ -126,33 +127,35 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): event_start = False event_end = False for event in seg.events : - if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : - if stim_start is None : - if event_start == False : - event = event.rescale('ms').magnitude - stim_start = event[0] + rescaled = False + if rescaled is False : + if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : + if stim_start is None : + if event_start == False : + event = event.rescale('ms').magnitude + stim_start = event[0] + rescaled = True + else : + raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' + +' The program does not know which one to chose') else : - raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' - +' The program does not know which one to chose') - - else : - raise ValueError('It seems that stimulation start time is defined in epochs and an event.' - +' The program does not know which one to chose') - - if event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : - if stim_end is None : - if event_end == False : - event = event.rescale('ms').magnitude - stim_end = event[-1] - + raise ValueError('It seems that stimulation start time is defined in epochs and an event.' + +' The program does not know which one to chose') + + if rescaled is False : + if event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : + if stim_end is None : + if event_end == False : + event = event.rescale('ms').magnitude + stim_end = event[-1] + + else : + raise ValueError('It seems that there are two events, or an epoch and an event, related to stimulation end.' + +' The program does not know which one to chose') else : - raise ValueError('It seems that there are two events, or an epoch and an event, related to stimulation end.' - +' The program does not know which one to chose') + raise ValueError('It seems that stimulation end time is defined in epochs and an event.' + +' The program does not know which one to chose') - else : - raise ValueError('It seems that stimulation end time is defined in epochs and an event.' - +' The program does not know which one to chose') - if stim_start is None or stim_end is None : raise ValueError('No stim_start or stim_end has been found inside epochs or events. You can directly specify their value as argument "stim_start" and "stim_end"') @@ -169,8 +172,13 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): for sig in analogsignals : traces.append({}) + # print (sig) + # print (sig.rescale('mV').magnitude) + traces[count_traces]['T'] = sig.times.rescale('ms').magnitude - traces[count_traces]['V'] = sig.rescale('mV').magnitude + # print (traces[count_traces]['T']) + traces[count_traces]['V'] = sig.rescale('mV').magnitude + # print (traces[count_traces]['V']) traces[count_traces]['stim_start'] = [stim_start] traces[count_traces]['stim_end'] = [stim_end] diff --git a/efel/tests/neo_test_files/create_neo_files_test.py b/efel/tests/neo_test_files/create_neo_files_test.py new file mode 100644 index 0000000..ddef229 --- /dev/null +++ b/efel/tests/neo_test_files/create_neo_files_test.py @@ -0,0 +1,56 @@ + +import neo +import efel +import quantities as pq + + +#first file +file_name = "neo_test_file_no_times.pickle" +bl = neo.core.Block() +seg = neo.core.Segment() +data = range(10) +rate = 1000*pq.Hz +signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") +seg.analogsignals.append(signal) +bl.segments.append(seg) +neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) + +#second with times in epoch +file_name = "neo_test_file_epoch_times.pickle" +bl = neo.core.Block() +seg = neo.core.Segment() +data = range(10) +rate = 1000*pq.Hz +signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") +seg.analogsignals.append(signal) +seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) +bl.segments.append(seg) +neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) + +#events complete +file_name = "neo_test_file_events_time.pickle" +bl = neo.core.Block() +seg = neo.core.Segment() +data = range(10) +rate = 1000*pq.Hz +signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") +seg.analogsignals.append(signal) +seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) +seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_end" )) +bl.segments.append(seg) +neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) + +#events incomplete +file_name = "neo_test_file_events_time_incomplete.pickle" +bl = neo.core.Block() +seg = neo.core.Segment() +data = range(10) +rate = 1000*pq.Hz +signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") +seg.analogsignals.append(signal) +seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms , name="stim_start" )) +bl.segments.append(seg) +neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) + + + diff --git a/efel/tests/neo_test_files/neo_test_file_epoch_times.pickle b/efel/tests/neo_test_files/neo_test_file_epoch_times.pickle new file mode 100644 index 0000000..a241f6e --- /dev/null +++ b/efel/tests/neo_test_files/neo_test_file_epoch_times.pickle @@ -0,0 +1,539 @@ +ccopy_reg +_reconstructor +p1 +(cneo.core.block +Block +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'index' +p6 +NsS'description' +p7 +NsS'file_datetime' +p8 +NsS'segments' +p9 +(lp10 +g1 +(cneo.core.segment +Segment +p11 +g3 +NtRp12 +(dp13 +g6 +NsS'analogsignals' +p14 +(lp15 +cneo.core.analogsignal +_new_AnalogSignalArray +p16 +(cneo.core.analogsignal +AnalogSignal +p17 +cnumpy.core.multiarray +_reconstruct +p18 +(cnumpy +ndarray +p19 +(I0 +tS'b' +tRp20 +(I1 +(I10 +I1 +tcnumpy +dtype +p21 +(S'i8' +I0 +I1 +tRp22 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' +tbcquantities.quantity +_reconstruct_quantity +p23 +(cquantities.quantity +Quantity +p24 +g19 +(I0 +tp25 +S'b' +tRp26 +(I1 +(tg21 +(S'f8' +I0 +I1 +tRp27 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(cquantities.dimensionality +Dimensionality +p28 +c__builtin__ +dict +p29 +(dp30 +cquantities.unitquantity +UnitQuantity +p31 +(S'millivolt' +p32 +g23 +(g24 +g19 +g25 +S'b' +tRp33 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp34 +g31 +(S'volt' +p35 +g23 +(g24 +g19 +g25 +S'b' +tRp36 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp37 +g31 +(S'coulomb' +p38 +g23 +(g24 +g19 +g25 +S'b' +tRp39 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp40 +cquantities.unitquantity +UnitCurrent +p41 +(S'ampere' +p42 +NS'A' +N(lp43 +S'amp' +p44 +aS'amps' +p45 +aS'amperes' +p46 +aNtRp47 +(I1 +(I4 +I96 +tp48 +tbI1 +scquantities.unitquantity +UnitTime +p49 +(S'second' +p50 +NS's' +N(lp51 +S'sec' +p52 +aS'seconds' +p53 +aNtRp54 +(I1 +(I3 +I0 +tp55 +tbI1 +stRp56 +tbS'C' +N(lp57 +NtRp58 +(I1 +(I90 +I99 +tp59 +tbI-1 +sg31 +(S'joule' +p60 +g23 +(g24 +g19 +g25 +S'b' +tRp61 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp62 +g31 +(S'newton' +p63 +g23 +(g24 +g19 +g25 +S'b' +tRp64 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp65 +cquantities.unitquantity +UnitLength +p66 +(S'meter' +p67 +NS'm' +N(lp68 +S'meters' +p69 +aS'metre' +p70 +aS'metres' +p71 +aNtRp72 +(I1 +(I2 +I2 +tp73 +tbI1 +scquantities.unitquantity +UnitMass +p74 +(S'kilogram' +p75 +NS'kg' +p76 +N(lp77 +S'kilograms' +p78 +aNtRp79 +(I1 +(I1 +I63 +tp80 +tbI1 +sg54 +I-2 +stRp81 +tbS'N' +N(lp82 +S'newtons' +p83 +aNtRp84 +(I1 +(I90 +I66 +tp85 +tbI1 +sg72 +I1 +stRp86 +tbS'J' +N(lp87 +S'joules' +p88 +aNtRp89 +(I1 +(I90 +I76 +tp90 +tbI1 +stRp91 +tbS'V' +N(lp92 +S'volts' +p93 +aNtRp94 +(I1 +(I90 +I100 +tp95 +tbI1 +stRp96 +tbS'mV' +p97 +N(lp98 +S'millivolts' +p99 +aNtRp100 +(I1 +(I90 +I102 +tp101 +tbI1 +stRp102 +tbg22 +I01 +g23 +(g24 +g19 +g25 +S'b' +tRp103 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp104 +g54 +I1 +stRp105 +tbg23 +(g24 +g19 +g25 +S'b' +tRp106 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00@\x8f@' +g1 +(g28 +g29 +(dp107 +g31 +(S'hertz' +p108 +g23 +(g24 +g19 +g25 +S'b' +tRp109 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp110 +g54 +I-1 +stRp111 +tbS'Hz' +p112 +Ng57 +NtRp113 +(I1 +(I90 +I142 +tp114 +tbI1 +stRp115 +tbg23 +(g24 +g19 +g25 +S'b' +tRp116 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp117 +g113 +I-1 +stRp118 +tbNNN(dp119 +tRp120 +asS'spiketrains' +p121 +(lp122 +sg7 +Nsg8 +NsS'file_origin' +p123 +NsS'events' +p124 +(lp125 +sS'epochs' +p126 +(lp127 +cneo.core.epoch +_new_epoch +p128 +(cneo.core.epoch +Epoch +p129 +g23 +(g24 +g19 +g25 +S'b' +tRp130 +(I1 +(I2 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x004@' +g1 +(g28 +g29 +(dp131 +g49 +(S'millisecond' +p132 +g23 +(g24 +g19 +g25 +S'b' +tRp133 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp134 +g54 +I1 +stRp135 +tbS'ms' +p136 +N(lp137 +S'milliseconds' +p138 +aNtRp139 +(I1 +(I3 +I1 +tp140 +tbI1 +stRp141 +tbg23 +(g24 +g19 +g25 +S'b' +tRp142 +(I1 +(I0 +tg27 +I00 +S'' +g1 +(g28 +g29 +(dp143 +g54 +I1 +stRp144 +tbg18 +(g19 +(I0 +tS'b' +tRp145 +(I1 +(I0 +tg21 +(S'S1' +I0 +I1 +tRp146 +(I3 +S'|' +NNNI1 +I1 +I0 +tbI00 +S'' +tbg23 +(g24 +g19 +g25 +S'b' +tRp147 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp148 +g139 +I1 +stRp149 +tbS'stim' +p150 +NN(dp151 +tRp152 +asS'rec_datetime' +p153 +NsS'irregularlysampledsignals' +p154 +(lp155 +sS'annotations' +p156 +(dp157 +sS'block' +p158 +NsS'name' +p159 +Nsbasg123 +NsS'channel_indexes' +p160 +(lp161 +sg156 +(dp162 +sg153 +Nsg159 +Nsb. \ No newline at end of file diff --git a/efel/tests/neo_test_files/neo_test_file_events_time.pickle b/efel/tests/neo_test_files/neo_test_file_events_time.pickle new file mode 100644 index 0000000..f18d4fb --- /dev/null +++ b/efel/tests/neo_test_files/neo_test_file_events_time.pickle @@ -0,0 +1,601 @@ +ccopy_reg +_reconstructor +p1 +(cneo.core.block +Block +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'index' +p6 +NsS'description' +p7 +NsS'file_datetime' +p8 +NsS'segments' +p9 +(lp10 +g1 +(cneo.core.segment +Segment +p11 +g3 +NtRp12 +(dp13 +g6 +NsS'analogsignals' +p14 +(lp15 +cneo.core.analogsignal +_new_AnalogSignalArray +p16 +(cneo.core.analogsignal +AnalogSignal +p17 +cnumpy.core.multiarray +_reconstruct +p18 +(cnumpy +ndarray +p19 +(I0 +tS'b' +tRp20 +(I1 +(I10 +I1 +tcnumpy +dtype +p21 +(S'i8' +I0 +I1 +tRp22 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' +tbcquantities.quantity +_reconstruct_quantity +p23 +(cquantities.quantity +Quantity +p24 +g19 +(I0 +tp25 +S'b' +tRp26 +(I1 +(tg21 +(S'f8' +I0 +I1 +tRp27 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(cquantities.dimensionality +Dimensionality +p28 +c__builtin__ +dict +p29 +(dp30 +cquantities.unitquantity +UnitQuantity +p31 +(S'millivolt' +p32 +g23 +(g24 +g19 +g25 +S'b' +tRp33 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp34 +g31 +(S'volt' +p35 +g23 +(g24 +g19 +g25 +S'b' +tRp36 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp37 +g31 +(S'coulomb' +p38 +g23 +(g24 +g19 +g25 +S'b' +tRp39 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp40 +cquantities.unitquantity +UnitCurrent +p41 +(S'ampere' +p42 +NS'A' +N(lp43 +S'amp' +p44 +aS'amps' +p45 +aS'amperes' +p46 +aNtRp47 +(I1 +(I4 +I96 +tp48 +tbI1 +scquantities.unitquantity +UnitTime +p49 +(S'second' +p50 +NS's' +N(lp51 +S'sec' +p52 +aS'seconds' +p53 +aNtRp54 +(I1 +(I3 +I0 +tp55 +tbI1 +stRp56 +tbS'C' +N(lp57 +NtRp58 +(I1 +(I90 +I99 +tp59 +tbI-1 +sg31 +(S'joule' +p60 +g23 +(g24 +g19 +g25 +S'b' +tRp61 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp62 +g31 +(S'newton' +p63 +g23 +(g24 +g19 +g25 +S'b' +tRp64 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp65 +cquantities.unitquantity +UnitLength +p66 +(S'meter' +p67 +NS'm' +N(lp68 +S'meters' +p69 +aS'metre' +p70 +aS'metres' +p71 +aNtRp72 +(I1 +(I2 +I2 +tp73 +tbI1 +scquantities.unitquantity +UnitMass +p74 +(S'kilogram' +p75 +NS'kg' +p76 +N(lp77 +S'kilograms' +p78 +aNtRp79 +(I1 +(I1 +I63 +tp80 +tbI1 +sg54 +I-2 +stRp81 +tbS'N' +N(lp82 +S'newtons' +p83 +aNtRp84 +(I1 +(I90 +I66 +tp85 +tbI1 +sg72 +I1 +stRp86 +tbS'J' +N(lp87 +S'joules' +p88 +aNtRp89 +(I1 +(I90 +I76 +tp90 +tbI1 +stRp91 +tbS'V' +N(lp92 +S'volts' +p93 +aNtRp94 +(I1 +(I90 +I100 +tp95 +tbI1 +stRp96 +tbS'mV' +p97 +N(lp98 +S'millivolts' +p99 +aNtRp100 +(I1 +(I90 +I102 +tp101 +tbI1 +stRp102 +tbg22 +I01 +g23 +(g24 +g19 +g25 +S'b' +tRp103 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp104 +g54 +I1 +stRp105 +tbg23 +(g24 +g19 +g25 +S'b' +tRp106 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00@\x8f@' +g1 +(g28 +g29 +(dp107 +g31 +(S'hertz' +p108 +g23 +(g24 +g19 +g25 +S'b' +tRp109 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp110 +g54 +I-1 +stRp111 +tbS'Hz' +p112 +Ng57 +NtRp113 +(I1 +(I90 +I142 +tp114 +tbI1 +stRp115 +tbg23 +(g24 +g19 +g25 +S'b' +tRp116 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp117 +g113 +I-1 +stRp118 +tbNNN(dp119 +tRp120 +asS'spiketrains' +p121 +(lp122 +sg7 +Nsg8 +NsS'file_origin' +p123 +NsS'events' +p124 +(lp125 +cneo.core.event +_new_event +p126 +(cneo.core.event +Event +p127 +g23 +(g24 +g19 +g25 +S'b' +tRp128 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp129 +g49 +(S'millisecond' +p130 +g23 +(g24 +g19 +g25 +S'b' +tRp131 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp132 +g54 +I1 +stRp133 +tbS'ms' +p134 +N(lp135 +S'milliseconds' +p136 +aNtRp137 +(I1 +(I3 +I1 +tp138 +tbI1 +stRp139 +tbg18 +(g19 +(I0 +tS'b' +tRp140 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +tbg18 +(g19 +(I0 +tS'b' +tRp141 +(I1 +(I0 +tg21 +(S'S1' +I0 +I1 +tRp142 +(I3 +S'|' +NNNI1 +I1 +I0 +tbI00 +S'' +tbg23 +(g24 +g19 +g25 +S'b' +tRp143 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp144 +g137 +I1 +stRp145 +tbS'stim_start' +p146 +NN(dp147 +tRp148 +ag126 +(g127 +g23 +(g24 +g19 +g25 +S'b' +tRp149 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x004@' +g1 +(g28 +g29 +(dp150 +g137 +I1 +stRp151 +tbg18 +(g19 +(I0 +tS'b' +tRp152 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x004@' +tbg18 +(g19 +(I0 +tS'b' +tRp153 +(I1 +(I0 +tg21 +(S'S1' +I0 +I1 +tRp154 +(I3 +S'|' +NNNI1 +I1 +I0 +tbI00 +S'' +tbg23 +(g24 +g19 +g25 +S'b' +tRp155 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp156 +g137 +I1 +stRp157 +tbS'stim_end' +p158 +NN(dp159 +tRp160 +asS'epochs' +p161 +(lp162 +sS'rec_datetime' +p163 +NsS'irregularlysampledsignals' +p164 +(lp165 +sS'annotations' +p166 +(dp167 +sS'block' +p168 +NsS'name' +p169 +Nsbasg123 +NsS'channel_indexes' +p170 +(lp171 +sg166 +(dp172 +sg163 +Nsg169 +Nsb. \ No newline at end of file diff --git a/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle b/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle new file mode 100644 index 0000000..9cc89a5 --- /dev/null +++ b/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle @@ -0,0 +1,531 @@ +ccopy_reg +_reconstructor +p1 +(cneo.core.block +Block +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'index' +p6 +NsS'description' +p7 +NsS'file_datetime' +p8 +NsS'segments' +p9 +(lp10 +g1 +(cneo.core.segment +Segment +p11 +g3 +NtRp12 +(dp13 +g6 +NsS'analogsignals' +p14 +(lp15 +cneo.core.analogsignal +_new_AnalogSignalArray +p16 +(cneo.core.analogsignal +AnalogSignal +p17 +cnumpy.core.multiarray +_reconstruct +p18 +(cnumpy +ndarray +p19 +(I0 +tS'b' +tRp20 +(I1 +(I10 +I1 +tcnumpy +dtype +p21 +(S'i8' +I0 +I1 +tRp22 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' +tbcquantities.quantity +_reconstruct_quantity +p23 +(cquantities.quantity +Quantity +p24 +g19 +(I0 +tp25 +S'b' +tRp26 +(I1 +(tg21 +(S'f8' +I0 +I1 +tRp27 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(cquantities.dimensionality +Dimensionality +p28 +c__builtin__ +dict +p29 +(dp30 +cquantities.unitquantity +UnitQuantity +p31 +(S'millivolt' +p32 +g23 +(g24 +g19 +g25 +S'b' +tRp33 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp34 +g31 +(S'volt' +p35 +g23 +(g24 +g19 +g25 +S'b' +tRp36 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp37 +g31 +(S'coulomb' +p38 +g23 +(g24 +g19 +g25 +S'b' +tRp39 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp40 +cquantities.unitquantity +UnitCurrent +p41 +(S'ampere' +p42 +NS'A' +N(lp43 +S'amp' +p44 +aS'amps' +p45 +aS'amperes' +p46 +aNtRp47 +(I1 +(I4 +I96 +tp48 +tbI1 +scquantities.unitquantity +UnitTime +p49 +(S'second' +p50 +NS's' +N(lp51 +S'sec' +p52 +aS'seconds' +p53 +aNtRp54 +(I1 +(I3 +I0 +tp55 +tbI1 +stRp56 +tbS'C' +N(lp57 +NtRp58 +(I1 +(I90 +I99 +tp59 +tbI-1 +sg31 +(S'joule' +p60 +g23 +(g24 +g19 +g25 +S'b' +tRp61 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp62 +g31 +(S'newton' +p63 +g23 +(g24 +g19 +g25 +S'b' +tRp64 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp65 +cquantities.unitquantity +UnitLength +p66 +(S'meter' +p67 +NS'm' +N(lp68 +S'meters' +p69 +aS'metre' +p70 +aS'metres' +p71 +aNtRp72 +(I1 +(I2 +I2 +tp73 +tbI1 +scquantities.unitquantity +UnitMass +p74 +(S'kilogram' +p75 +NS'kg' +p76 +N(lp77 +S'kilograms' +p78 +aNtRp79 +(I1 +(I1 +I63 +tp80 +tbI1 +sg54 +I-2 +stRp81 +tbS'N' +N(lp82 +S'newtons' +p83 +aNtRp84 +(I1 +(I90 +I66 +tp85 +tbI1 +sg72 +I1 +stRp86 +tbS'J' +N(lp87 +S'joules' +p88 +aNtRp89 +(I1 +(I90 +I76 +tp90 +tbI1 +stRp91 +tbS'V' +N(lp92 +S'volts' +p93 +aNtRp94 +(I1 +(I90 +I100 +tp95 +tbI1 +stRp96 +tbS'mV' +p97 +N(lp98 +S'millivolts' +p99 +aNtRp100 +(I1 +(I90 +I102 +tp101 +tbI1 +stRp102 +tbg22 +I01 +g23 +(g24 +g19 +g25 +S'b' +tRp103 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp104 +g54 +I1 +stRp105 +tbg23 +(g24 +g19 +g25 +S'b' +tRp106 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00@\x8f@' +g1 +(g28 +g29 +(dp107 +g31 +(S'hertz' +p108 +g23 +(g24 +g19 +g25 +S'b' +tRp109 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp110 +g54 +I-1 +stRp111 +tbS'Hz' +p112 +Ng57 +NtRp113 +(I1 +(I90 +I142 +tp114 +tbI1 +stRp115 +tbg23 +(g24 +g19 +g25 +S'b' +tRp116 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp117 +g113 +I-1 +stRp118 +tbNNN(dp119 +tRp120 +asS'spiketrains' +p121 +(lp122 +sg7 +Nsg8 +NsS'file_origin' +p123 +NsS'events' +p124 +(lp125 +cneo.core.event +_new_event +p126 +(cneo.core.event +Event +p127 +g23 +(g24 +g19 +g25 +S'b' +tRp128 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp129 +g49 +(S'millisecond' +p130 +g23 +(g24 +g19 +g25 +S'b' +tRp131 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp132 +g54 +I1 +stRp133 +tbS'ms' +p134 +N(lp135 +S'milliseconds' +p136 +aNtRp137 +(I1 +(I3 +I1 +tp138 +tbI1 +stRp139 +tbg18 +(g19 +(I0 +tS'b' +tRp140 +(I1 +(I1 +tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +tbg18 +(g19 +(I0 +tS'b' +tRp141 +(I1 +(I0 +tg21 +(S'S1' +I0 +I1 +tRp142 +(I3 +S'|' +NNNI1 +I1 +I0 +tbI00 +S'' +tbg23 +(g24 +g19 +g25 +S'b' +tRp143 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp144 +g137 +I1 +stRp145 +tbS'stim_start' +p146 +NN(dp147 +tRp148 +asS'epochs' +p149 +(lp150 +sS'rec_datetime' +p151 +NsS'irregularlysampledsignals' +p152 +(lp153 +sS'annotations' +p154 +(dp155 +sS'block' +p156 +NsS'name' +p157 +Nsbasg123 +NsS'channel_indexes' +p158 +(lp159 +sg154 +(dp160 +sg151 +Nsg157 +Nsb. \ No newline at end of file diff --git a/efel/tests/neo_test_files/neo_test_file_no_times.pickle b/efel/tests/neo_test_files/neo_test_file_no_times.pickle new file mode 100644 index 0000000..f64ff6e --- /dev/null +++ b/efel/tests/neo_test_files/neo_test_file_no_times.pickle @@ -0,0 +1,428 @@ +ccopy_reg +_reconstructor +p1 +(cneo.core.block +Block +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'index' +p6 +NsS'description' +p7 +NsS'file_datetime' +p8 +NsS'segments' +p9 +(lp10 +g1 +(cneo.core.segment +Segment +p11 +g3 +NtRp12 +(dp13 +g6 +NsS'analogsignals' +p14 +(lp15 +cneo.core.analogsignal +_new_AnalogSignalArray +p16 +(cneo.core.analogsignal +AnalogSignal +p17 +cnumpy.core.multiarray +_reconstruct +p18 +(cnumpy +ndarray +p19 +(I0 +tS'b' +tRp20 +(I1 +(I10 +I1 +tcnumpy +dtype +p21 +(S'i8' +I0 +I1 +tRp22 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' +tbcquantities.quantity +_reconstruct_quantity +p23 +(cquantities.quantity +Quantity +p24 +g19 +(I0 +tp25 +S'b' +tRp26 +(I1 +(tg21 +(S'f8' +I0 +I1 +tRp27 +(I3 +S'<' +NNNI-1 +I-1 +I0 +tbI00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(cquantities.dimensionality +Dimensionality +p28 +c__builtin__ +dict +p29 +(dp30 +cquantities.unitquantity +UnitQuantity +p31 +(S'millivolt' +p32 +g23 +(g24 +g19 +g25 +S'b' +tRp33 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp34 +g31 +(S'volt' +p35 +g23 +(g24 +g19 +g25 +S'b' +tRp36 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp37 +g31 +(S'coulomb' +p38 +g23 +(g24 +g19 +g25 +S'b' +tRp39 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp40 +cquantities.unitquantity +UnitCurrent +p41 +(S'ampere' +p42 +NS'A' +N(lp43 +S'amp' +p44 +aS'amps' +p45 +aS'amperes' +p46 +aNtRp47 +(I1 +(I4 +I96 +tp48 +tbI1 +scquantities.unitquantity +UnitTime +p49 +(S'second' +p50 +NS's' +N(lp51 +S'sec' +p52 +aS'seconds' +p53 +aNtRp54 +(I1 +(I3 +I0 +tp55 +tbI1 +stRp56 +tbS'C' +N(lp57 +NtRp58 +(I1 +(I90 +I99 +tp59 +tbI-1 +sg31 +(S'joule' +p60 +g23 +(g24 +g19 +g25 +S'b' +tRp61 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp62 +g31 +(S'newton' +p63 +g23 +(g24 +g19 +g25 +S'b' +tRp64 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp65 +cquantities.unitquantity +UnitLength +p66 +(S'meter' +p67 +NS'm' +N(lp68 +S'meters' +p69 +aS'metre' +p70 +aS'metres' +p71 +aNtRp72 +(I1 +(I2 +I2 +tp73 +tbI1 +scquantities.unitquantity +UnitMass +p74 +(S'kilogram' +p75 +NS'kg' +p76 +N(lp77 +S'kilograms' +p78 +aNtRp79 +(I1 +(I1 +I63 +tp80 +tbI1 +sg54 +I-2 +stRp81 +tbS'N' +N(lp82 +S'newtons' +p83 +aNtRp84 +(I1 +(I90 +I66 +tp85 +tbI1 +sg72 +I1 +stRp86 +tbS'J' +N(lp87 +S'joules' +p88 +aNtRp89 +(I1 +(I90 +I76 +tp90 +tbI1 +stRp91 +tbS'V' +N(lp92 +S'volts' +p93 +aNtRp94 +(I1 +(I90 +I100 +tp95 +tbI1 +stRp96 +tbS'mV' +p97 +N(lp98 +S'millivolts' +p99 +aNtRp100 +(I1 +(I90 +I102 +tp101 +tbI1 +stRp102 +tbg22 +I01 +g23 +(g24 +g19 +g25 +S'b' +tRp103 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\x00\x00' +g1 +(g28 +g29 +(dp104 +g54 +I1 +stRp105 +tbg23 +(g24 +g19 +g25 +S'b' +tRp106 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00@\x8f@' +g1 +(g28 +g29 +(dp107 +g31 +(S'hertz' +p108 +g23 +(g24 +g19 +g25 +S'b' +tRp109 +(I1 +(tg27 +I00 +S'\x00\x00\x00\x00\x00\x00\xf0?' +g1 +(g28 +g29 +(dp110 +g54 +I-1 +stRp111 +tbS'Hz' +p112 +Ng57 +NtRp113 +(I1 +(I90 +I142 +tp114 +tbI1 +stRp115 +tbg23 +(g24 +g19 +g25 +S'b' +tRp116 +(I1 +(tg27 +I00 +S'\xfc\xa9\xf1\xd2MbP?' +g1 +(g28 +g29 +(dp117 +g113 +I-1 +stRp118 +tbNNN(dp119 +tRp120 +asS'spiketrains' +p121 +(lp122 +sg7 +Nsg8 +NsS'file_origin' +p123 +NsS'events' +p124 +(lp125 +sS'epochs' +p126 +(lp127 +sS'rec_datetime' +p128 +NsS'irregularlysampledsignals' +p129 +(lp130 +sS'annotations' +p131 +(dp132 +sS'block' +p133 +NsS'name' +p134 +Nsbasg123 +NsS'channel_indexes' +p135 +(lp136 +sg131 +(dp137 +sg128 +Nsg134 +Nsb. \ No newline at end of file diff --git a/efel/tests/test_io.py b/efel/tests/test_io.py index 7002750..45e333d 100644 --- a/efel/tests/test_io.py +++ b/efel/tests/test_io.py @@ -10,6 +10,11 @@ os.path.abspath(__file__)), 'testdata') +neo_test_files_dir = os.path.join( + os.path.dirname( + os.path.abspath(__file__)), + 'neo_test_files') + meanfrequency1_filename = os.path.join(testdata_dir, 'basic', 'mean_frequency_1.txt') @@ -118,3 +123,46 @@ def test_load_fragment_allcolumns(): time_numpy = numpy.loadtxt(meanfrequency1_filename) numpy.testing.assert_array_equal(time_io, time_numpy) + + +def test_load_neo_file_stim_time_arg (): + import neo + import efel + file_name = os.path.join(neo_test_files_dir, "neo_test_file_no_times.pickle") + + #test load_neo_file without stim time + nt.assert_raises(ValueError, efel.io.load_neo_file,file_name) + #test load_neo_file with stim time arguments + result = efel.io.load_neo_file(file_name, stim_start=0, stim_end=20) + #test load_neo_file with stim time incomplete arguments + nt.assert_raises(ValueError, efel.io.load_neo_file, file_name, stim_start=0) + nt.assert_equal(True, all(result[0][0][0]['T'] == [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])) + nt.assert_equal(True, all(result[0][0][0]['V'] == [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]])) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) + +def test_load_neo_file_stim_time_epoch (): + import neo + import efel + file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.pickle") + + result = efel.io.load_neo_file(file_name) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) + + +def test_load_neo_file_stim_time_events (): + import neo + import efel + file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time.pickle") + + result = efel.io.load_neo_file(file_name) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) + +def test_load_neo_file_stim_time_events_incomplete (): + import neo + import efel + file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time_incomplete.pickle") + + nt.assert_raises(ValueError, efel.io.load_neo_file, file_name) From a7f469689cd53371c62256088269c06643b0ff6e Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Fri, 31 Mar 2017 10:05:15 +0200 Subject: [PATCH 05/10] added neo in setup 'install_requires' and commented epoch test until the next release of Neo --- efel/tests/test_io.py | 16 ++++++++-------- setup.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/efel/tests/test_io.py b/efel/tests/test_io.py index 45e333d..a427a6b 100644 --- a/efel/tests/test_io.py +++ b/efel/tests/test_io.py @@ -141,14 +141,14 @@ def test_load_neo_file_stim_time_arg (): nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) -def test_load_neo_file_stim_time_epoch (): - import neo - import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.pickle") - - result = efel.io.load_neo_file(file_name) - nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) - nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) +# def test_load_neo_file_stim_time_epoch (): +# import neo +# import efel +# file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.pickle") + +# result = efel.io.load_neo_file(file_name) +# nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) +# nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) def test_load_neo_file_stim_time_events (): diff --git a/setup.py b/setup.py index 069f76d..3249036 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ name="efel", version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - install_requires=['numpy>=1.6', 'six'], + install_requires=['numpy>=1.6', 'six', 'neo>=0.5.0'], packages=['efel'], author="BlueBrain Project, EPFL", maintainer="Werner Van Geit", From 62a250c6d1e8e232cda8dbd8139983d8d6837efa Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Fri, 31 Mar 2017 13:29:01 +0200 Subject: [PATCH 06/10] Tests are now using .mat files. Also a litle iprovement in load_neo_file --- efel/io.py | 16 +- efel/tests/neo_test_files/create_neo_files_test.py | 26 +- .../neo_test_files/neo_test_file_epoch_times.mat | Bin 0 -> 1720 bytes .../neo_test_file_epoch_times.pickle | 539 ------------------ .../neo_test_files/neo_test_file_events_time.mat | Bin 0 -> 1920 bytes .../neo_test_file_events_time.pickle | 601 --------------------- .../neo_test_file_events_time_incomplete.mat | Bin 0 -> 1568 bytes .../neo_test_file_events_time_incomplete.pickle | 531 ------------------ .../neo_test_files/neo_test_file_no_times.mat | Bin 0 -> 1216 bytes .../neo_test_files/neo_test_file_no_times.pickle | 428 --------------- efel/tests/test_io.py | 20 +- 11 files changed, 36 insertions(+), 2125 deletions(-) create mode 100644 efel/tests/neo_test_files/neo_test_file_epoch_times.mat delete mode 100644 efel/tests/neo_test_files/neo_test_file_epoch_times.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_events_time.mat delete mode 100644 efel/tests/neo_test_files/neo_test_file_events_time.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_events_time_incomplete.mat delete mode 100644 efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle create mode 100644 efel/tests/neo_test_files/neo_test_file_no_times.mat delete mode 100644 efel/tests/neo_test_files/neo_test_file_no_times.pickle diff --git a/efel/io.py b/efel/io.py index 79bbd7d..5428436 100644 --- a/efel/io.py +++ b/efel/io.py @@ -133,7 +133,10 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): if stim_start is None : if event_start == False : event = event.rescale('ms').magnitude - stim_start = event[0] + if type(event) is list : + stim_start = event[0] + else : + stim_start = event rescaled = True else : raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' @@ -147,8 +150,10 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): if stim_end is None : if event_end == False : event = event.rescale('ms').magnitude - stim_end = event[-1] - + if type(event) is list : + stim_end = event[-1] + else : + stim_end = event else : raise ValueError('It seems that there are two events, or an epoch and an event, related to stimulation end.' +' The program does not know which one to chose') @@ -172,13 +177,8 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): for sig in analogsignals : traces.append({}) - # print (sig) - # print (sig.rescale('mV').magnitude) - traces[count_traces]['T'] = sig.times.rescale('ms').magnitude - # print (traces[count_traces]['T']) traces[count_traces]['V'] = sig.rescale('mV').magnitude - # print (traces[count_traces]['V']) traces[count_traces]['stim_start'] = [stim_start] traces[count_traces]['stim_end'] = [stim_end] diff --git a/efel/tests/neo_test_files/create_neo_files_test.py b/efel/tests/neo_test_files/create_neo_files_test.py index ddef229..63f3dca 100644 --- a/efel/tests/neo_test_files/create_neo_files_test.py +++ b/efel/tests/neo_test_files/create_neo_files_test.py @@ -5,7 +5,8 @@ #first file -file_name = "neo_test_file_no_times.pickle" +file_name = "neo_test_file_no_times.mat" + bl = neo.core.Block() seg = neo.core.Segment() data = range(10) @@ -13,10 +14,12 @@ signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) bl.segments.append(seg) -neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) +neo.io.NeoMatlabIO(filename=file_name).write_block(bl) + #second with times in epoch -file_name = "neo_test_file_epoch_times.pickle" +file_name = "neo_test_file_epoch_times.mat" + bl = neo.core.Block() seg = neo.core.Segment() data = range(10) @@ -25,10 +28,16 @@ seg.analogsignals.append(signal) seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) bl.segments.append(seg) -neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) +neo.io.NeoMatlabIO(filename=file_name).write_block(bl) + + + + + #events complete -file_name = "neo_test_file_events_time.pickle" +file_name = "neo_test_file_events_time.mat" + bl = neo.core.Block() seg = neo.core.Segment() data = range(10) @@ -38,10 +47,11 @@ seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_end" )) bl.segments.append(seg) -neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) +neo.io.NeoMatlabIO(filename=file_name).write_block(bl) #events incomplete -file_name = "neo_test_file_events_time_incomplete.pickle" +file_name = "neo_test_file_events_time_incomplete.mat" + bl = neo.core.Block() seg = neo.core.Segment() data = range(10) @@ -50,7 +60,7 @@ seg.analogsignals.append(signal) seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms , name="stim_start" )) bl.segments.append(seg) -neo.io.PickleIO(filename=file_name, mode="rw").write_block(bl) +neo.io.NeoMatlabIO(filename=file_name).write_block(bl) diff --git a/efel/tests/neo_test_files/neo_test_file_epoch_times.mat b/efel/tests/neo_test_files/neo_test_file_epoch_times.mat new file mode 100644 index 0000000000000000000000000000000000000000..6ad8e04e513c19f73ee80316980f3e704eb88189 GIT binary patch literal 1720 zcmbVM%}yIJ5H=7fMF{242k@~6in0U*%_%8T1yUn%KwN_%CRprGv^FT}sc%poqmR@_ z>5=(%JsYz?Su%=cdpzHKpU0CO4$giIzRCTajvNlozFeDF%hOo7>nu-ta++B)+m=VU zR!)y)miFZL+{mHIWjB&hw-JZ0TgUMX=7A5cCu4G?smuRli@NnFoBA zadve}^QvfxkNym^)ssZ0&eF0lBSSu-vozTb6iVU5>v;4 z7sh<$ZjM8*!0NcV&N6C_Lk(fT^=a_^>U_`_-Vc0?rKPvM{#*RW!vml;?eGl1JrDu& zb3ORJjA1|GFM@bzgS{4yzWzk#z|Uw{l}uxkPDa!g+P`tx*K`<|8(F7v7jzc&TIma- zC|~iPcoO!M!$&u%PgrO4(ecl+KEEgj*9UoEeBTXPbB*BNq;ZOcH?AAkX~p}){(y_$ z{ewTpw+q&^zgPqFh3|{+3F~Jb)?degkGa9WNZpe261OmK|M#T E02QH|)+#W0Mq)j-?>(gNTb5kY#b9hkYjOpThxrr##!B}JUF9P2y)*ONcLN&zH?!}PJO$S z199iHoQ|`|Ceu+)lQ6nYEKyz6M~^~^kt=jwc#G=6>x31>E4f)PTg>6DQK#gm;q}Z9 z@Szs2zeTs>Ull*Mq-TB*2f}{u=?owC+oAK277Oc{r%nGL^Fzh`dgtFU!w}i0Rrn>2 z79qlv059f>@pB%=&pwP3`8YQnOaE1Q>%7H3UYWOd*Q@udjvLq@5;yMfdn7UGIE0Plz^@nH^Q zin+>(|U+E8?AWzNV;(yxd{Q>+)dTIaw literal 0 HcmV?d00001 diff --git a/efel/tests/neo_test_files/neo_test_file_events_time.pickle b/efel/tests/neo_test_files/neo_test_file_events_time.pickle deleted file mode 100644 index f18d4fb..0000000 --- a/efel/tests/neo_test_files/neo_test_file_events_time.pickle +++ /dev/null @@ -1,601 +0,0 @@ -ccopy_reg -_reconstructor -p1 -(cneo.core.block -Block -p2 -c__builtin__ -object -p3 -NtRp4 -(dp5 -S'index' -p6 -NsS'description' -p7 -NsS'file_datetime' -p8 -NsS'segments' -p9 -(lp10 -g1 -(cneo.core.segment -Segment -p11 -g3 -NtRp12 -(dp13 -g6 -NsS'analogsignals' -p14 -(lp15 -cneo.core.analogsignal -_new_AnalogSignalArray -p16 -(cneo.core.analogsignal -AnalogSignal -p17 -cnumpy.core.multiarray -_reconstruct -p18 -(cnumpy -ndarray -p19 -(I0 -tS'b' -tRp20 -(I1 -(I10 -I1 -tcnumpy -dtype -p21 -(S'i8' -I0 -I1 -tRp22 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' -tbcquantities.quantity -_reconstruct_quantity -p23 -(cquantities.quantity -Quantity -p24 -g19 -(I0 -tp25 -S'b' -tRp26 -(I1 -(tg21 -(S'f8' -I0 -I1 -tRp27 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(cquantities.dimensionality -Dimensionality -p28 -c__builtin__ -dict -p29 -(dp30 -cquantities.unitquantity -UnitQuantity -p31 -(S'millivolt' -p32 -g23 -(g24 -g19 -g25 -S'b' -tRp33 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp34 -g31 -(S'volt' -p35 -g23 -(g24 -g19 -g25 -S'b' -tRp36 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp37 -g31 -(S'coulomb' -p38 -g23 -(g24 -g19 -g25 -S'b' -tRp39 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp40 -cquantities.unitquantity -UnitCurrent -p41 -(S'ampere' -p42 -NS'A' -N(lp43 -S'amp' -p44 -aS'amps' -p45 -aS'amperes' -p46 -aNtRp47 -(I1 -(I4 -I96 -tp48 -tbI1 -scquantities.unitquantity -UnitTime -p49 -(S'second' -p50 -NS's' -N(lp51 -S'sec' -p52 -aS'seconds' -p53 -aNtRp54 -(I1 -(I3 -I0 -tp55 -tbI1 -stRp56 -tbS'C' -N(lp57 -NtRp58 -(I1 -(I90 -I99 -tp59 -tbI-1 -sg31 -(S'joule' -p60 -g23 -(g24 -g19 -g25 -S'b' -tRp61 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp62 -g31 -(S'newton' -p63 -g23 -(g24 -g19 -g25 -S'b' -tRp64 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp65 -cquantities.unitquantity -UnitLength -p66 -(S'meter' -p67 -NS'm' -N(lp68 -S'meters' -p69 -aS'metre' -p70 -aS'metres' -p71 -aNtRp72 -(I1 -(I2 -I2 -tp73 -tbI1 -scquantities.unitquantity -UnitMass -p74 -(S'kilogram' -p75 -NS'kg' -p76 -N(lp77 -S'kilograms' -p78 -aNtRp79 -(I1 -(I1 -I63 -tp80 -tbI1 -sg54 -I-2 -stRp81 -tbS'N' -N(lp82 -S'newtons' -p83 -aNtRp84 -(I1 -(I90 -I66 -tp85 -tbI1 -sg72 -I1 -stRp86 -tbS'J' -N(lp87 -S'joules' -p88 -aNtRp89 -(I1 -(I90 -I76 -tp90 -tbI1 -stRp91 -tbS'V' -N(lp92 -S'volts' -p93 -aNtRp94 -(I1 -(I90 -I100 -tp95 -tbI1 -stRp96 -tbS'mV' -p97 -N(lp98 -S'millivolts' -p99 -aNtRp100 -(I1 -(I90 -I102 -tp101 -tbI1 -stRp102 -tbg22 -I01 -g23 -(g24 -g19 -g25 -S'b' -tRp103 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -g1 -(g28 -g29 -(dp104 -g54 -I1 -stRp105 -tbg23 -(g24 -g19 -g25 -S'b' -tRp106 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00@\x8f@' -g1 -(g28 -g29 -(dp107 -g31 -(S'hertz' -p108 -g23 -(g24 -g19 -g25 -S'b' -tRp109 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp110 -g54 -I-1 -stRp111 -tbS'Hz' -p112 -Ng57 -NtRp113 -(I1 -(I90 -I142 -tp114 -tbI1 -stRp115 -tbg23 -(g24 -g19 -g25 -S'b' -tRp116 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp117 -g113 -I-1 -stRp118 -tbNNN(dp119 -tRp120 -asS'spiketrains' -p121 -(lp122 -sg7 -Nsg8 -NsS'file_origin' -p123 -NsS'events' -p124 -(lp125 -cneo.core.event -_new_event -p126 -(cneo.core.event -Event -p127 -g23 -(g24 -g19 -g25 -S'b' -tRp128 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -g1 -(g28 -g29 -(dp129 -g49 -(S'millisecond' -p130 -g23 -(g24 -g19 -g25 -S'b' -tRp131 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp132 -g54 -I1 -stRp133 -tbS'ms' -p134 -N(lp135 -S'milliseconds' -p136 -aNtRp137 -(I1 -(I3 -I1 -tp138 -tbI1 -stRp139 -tbg18 -(g19 -(I0 -tS'b' -tRp140 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -tbg18 -(g19 -(I0 -tS'b' -tRp141 -(I1 -(I0 -tg21 -(S'S1' -I0 -I1 -tRp142 -(I3 -S'|' -NNNI1 -I1 -I0 -tbI00 -S'' -tbg23 -(g24 -g19 -g25 -S'b' -tRp143 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp144 -g137 -I1 -stRp145 -tbS'stim_start' -p146 -NN(dp147 -tRp148 -ag126 -(g127 -g23 -(g24 -g19 -g25 -S'b' -tRp149 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x004@' -g1 -(g28 -g29 -(dp150 -g137 -I1 -stRp151 -tbg18 -(g19 -(I0 -tS'b' -tRp152 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x004@' -tbg18 -(g19 -(I0 -tS'b' -tRp153 -(I1 -(I0 -tg21 -(S'S1' -I0 -I1 -tRp154 -(I3 -S'|' -NNNI1 -I1 -I0 -tbI00 -S'' -tbg23 -(g24 -g19 -g25 -S'b' -tRp155 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp156 -g137 -I1 -stRp157 -tbS'stim_end' -p158 -NN(dp159 -tRp160 -asS'epochs' -p161 -(lp162 -sS'rec_datetime' -p163 -NsS'irregularlysampledsignals' -p164 -(lp165 -sS'annotations' -p166 -(dp167 -sS'block' -p168 -NsS'name' -p169 -Nsbasg123 -NsS'channel_indexes' -p170 -(lp171 -sg166 -(dp172 -sg163 -Nsg169 -Nsb. \ No newline at end of file diff --git a/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.mat b/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.mat new file mode 100644 index 0000000000000000000000000000000000000000..a1a56cda489bfe346e963111ef762912aa2439e1 GIT binary patch literal 1568 zcmbtT+e!m55Z!9MBGLyxARnO8^@7@`RzVb8=!5v$rkd8!y_C%=#V7y3KKi-N+0970 zwzlX%$Ye4z=gedhwC?X(m*VuWE`rwmL0^YTv_qNolQe3GQDXFXUtFb1X6i{KaYJ0E zS_Co`$G-578~#PZKM_ZD|IGV?RBnS^3j191ymi_)X|32aWXjJK+Ihj&3zNqo?Q34u z+p>4qjT%HM&J3x!AaB#jiyV+yd0~ft&GG+@2mFDL800;trAEo)^EbMTWta?%9?)() zGtxtqrBcUmP_Jd4b+U5(*dffbI2Ab1Q7Z)46C%lR%hcC({FkY3k1&vTOv}h<6zX`; zNof)~FR`Xp7xmGlBU#5}GR>?{U-{nywMwk-t#auCe z#$o;(!#sh<*rew1i*U<*iyr=o+x%#j->b|U+#oJ*oDnx6BiGCK^Xi3v*YW3fn&*%I ziZ@1H^d-}gGIsnz*;DjQbBSf73eEc1L%A+@4$ybx{n1a#xhRgYxZawB*Cd_$F$<4p T7$Jzm*-&A{7lien?@94r^Mz)l literal 0 HcmV?d00001 diff --git a/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle b/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle deleted file mode 100644 index 9cc89a5..0000000 --- a/efel/tests/neo_test_files/neo_test_file_events_time_incomplete.pickle +++ /dev/null @@ -1,531 +0,0 @@ -ccopy_reg -_reconstructor -p1 -(cneo.core.block -Block -p2 -c__builtin__ -object -p3 -NtRp4 -(dp5 -S'index' -p6 -NsS'description' -p7 -NsS'file_datetime' -p8 -NsS'segments' -p9 -(lp10 -g1 -(cneo.core.segment -Segment -p11 -g3 -NtRp12 -(dp13 -g6 -NsS'analogsignals' -p14 -(lp15 -cneo.core.analogsignal -_new_AnalogSignalArray -p16 -(cneo.core.analogsignal -AnalogSignal -p17 -cnumpy.core.multiarray -_reconstruct -p18 -(cnumpy -ndarray -p19 -(I0 -tS'b' -tRp20 -(I1 -(I10 -I1 -tcnumpy -dtype -p21 -(S'i8' -I0 -I1 -tRp22 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' -tbcquantities.quantity -_reconstruct_quantity -p23 -(cquantities.quantity -Quantity -p24 -g19 -(I0 -tp25 -S'b' -tRp26 -(I1 -(tg21 -(S'f8' -I0 -I1 -tRp27 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(cquantities.dimensionality -Dimensionality -p28 -c__builtin__ -dict -p29 -(dp30 -cquantities.unitquantity -UnitQuantity -p31 -(S'millivolt' -p32 -g23 -(g24 -g19 -g25 -S'b' -tRp33 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp34 -g31 -(S'volt' -p35 -g23 -(g24 -g19 -g25 -S'b' -tRp36 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp37 -g31 -(S'coulomb' -p38 -g23 -(g24 -g19 -g25 -S'b' -tRp39 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp40 -cquantities.unitquantity -UnitCurrent -p41 -(S'ampere' -p42 -NS'A' -N(lp43 -S'amp' -p44 -aS'amps' -p45 -aS'amperes' -p46 -aNtRp47 -(I1 -(I4 -I96 -tp48 -tbI1 -scquantities.unitquantity -UnitTime -p49 -(S'second' -p50 -NS's' -N(lp51 -S'sec' -p52 -aS'seconds' -p53 -aNtRp54 -(I1 -(I3 -I0 -tp55 -tbI1 -stRp56 -tbS'C' -N(lp57 -NtRp58 -(I1 -(I90 -I99 -tp59 -tbI-1 -sg31 -(S'joule' -p60 -g23 -(g24 -g19 -g25 -S'b' -tRp61 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp62 -g31 -(S'newton' -p63 -g23 -(g24 -g19 -g25 -S'b' -tRp64 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp65 -cquantities.unitquantity -UnitLength -p66 -(S'meter' -p67 -NS'm' -N(lp68 -S'meters' -p69 -aS'metre' -p70 -aS'metres' -p71 -aNtRp72 -(I1 -(I2 -I2 -tp73 -tbI1 -scquantities.unitquantity -UnitMass -p74 -(S'kilogram' -p75 -NS'kg' -p76 -N(lp77 -S'kilograms' -p78 -aNtRp79 -(I1 -(I1 -I63 -tp80 -tbI1 -sg54 -I-2 -stRp81 -tbS'N' -N(lp82 -S'newtons' -p83 -aNtRp84 -(I1 -(I90 -I66 -tp85 -tbI1 -sg72 -I1 -stRp86 -tbS'J' -N(lp87 -S'joules' -p88 -aNtRp89 -(I1 -(I90 -I76 -tp90 -tbI1 -stRp91 -tbS'V' -N(lp92 -S'volts' -p93 -aNtRp94 -(I1 -(I90 -I100 -tp95 -tbI1 -stRp96 -tbS'mV' -p97 -N(lp98 -S'millivolts' -p99 -aNtRp100 -(I1 -(I90 -I102 -tp101 -tbI1 -stRp102 -tbg22 -I01 -g23 -(g24 -g19 -g25 -S'b' -tRp103 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -g1 -(g28 -g29 -(dp104 -g54 -I1 -stRp105 -tbg23 -(g24 -g19 -g25 -S'b' -tRp106 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00@\x8f@' -g1 -(g28 -g29 -(dp107 -g31 -(S'hertz' -p108 -g23 -(g24 -g19 -g25 -S'b' -tRp109 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp110 -g54 -I-1 -stRp111 -tbS'Hz' -p112 -Ng57 -NtRp113 -(I1 -(I90 -I142 -tp114 -tbI1 -stRp115 -tbg23 -(g24 -g19 -g25 -S'b' -tRp116 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp117 -g113 -I-1 -stRp118 -tbNNN(dp119 -tRp120 -asS'spiketrains' -p121 -(lp122 -sg7 -Nsg8 -NsS'file_origin' -p123 -NsS'events' -p124 -(lp125 -cneo.core.event -_new_event -p126 -(cneo.core.event -Event -p127 -g23 -(g24 -g19 -g25 -S'b' -tRp128 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -g1 -(g28 -g29 -(dp129 -g49 -(S'millisecond' -p130 -g23 -(g24 -g19 -g25 -S'b' -tRp131 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp132 -g54 -I1 -stRp133 -tbS'ms' -p134 -N(lp135 -S'milliseconds' -p136 -aNtRp137 -(I1 -(I3 -I1 -tp138 -tbI1 -stRp139 -tbg18 -(g19 -(I0 -tS'b' -tRp140 -(I1 -(I1 -tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -tbg18 -(g19 -(I0 -tS'b' -tRp141 -(I1 -(I0 -tg21 -(S'S1' -I0 -I1 -tRp142 -(I3 -S'|' -NNNI1 -I1 -I0 -tbI00 -S'' -tbg23 -(g24 -g19 -g25 -S'b' -tRp143 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp144 -g137 -I1 -stRp145 -tbS'stim_start' -p146 -NN(dp147 -tRp148 -asS'epochs' -p149 -(lp150 -sS'rec_datetime' -p151 -NsS'irregularlysampledsignals' -p152 -(lp153 -sS'annotations' -p154 -(dp155 -sS'block' -p156 -NsS'name' -p157 -Nsbasg123 -NsS'channel_indexes' -p158 -(lp159 -sg154 -(dp160 -sg151 -Nsg157 -Nsb. \ No newline at end of file diff --git a/efel/tests/neo_test_files/neo_test_file_no_times.mat b/efel/tests/neo_test_files/neo_test_file_no_times.mat new file mode 100644 index 0000000000000000000000000000000000000000..f0a1a05848865bd1163f07c93f10a5c8cc422bcf GIT binary patch literal 1216 zcmbtT+e*Vg5KXo9hDaa$fc*fK#wyl4wF;tOpby2@y4G!6nj6_D#V7wjKgCb-Q=F4z zbX!DAJ+RE|>|D-FCVp>l-8&P<2QA_E2K!?jD$x&RK2Ea86KP`fbWfaTO6KZbB(Wzh zGA(?WiMA`;w&$LD?vXfbxhKvNs9pIx6xOLb&Kk)LIxAJ0Ms=@|S>;5i>%x~B)~k&TUiG>dIeDXjYx9bBK_T3{)_atOEr*pO2^134Rst0 zGunjVW2|Y^Wq3&*lx=vT>iaKvYry literal 0 HcmV?d00001 diff --git a/efel/tests/neo_test_files/neo_test_file_no_times.pickle b/efel/tests/neo_test_files/neo_test_file_no_times.pickle deleted file mode 100644 index f64ff6e..0000000 --- a/efel/tests/neo_test_files/neo_test_file_no_times.pickle +++ /dev/null @@ -1,428 +0,0 @@ -ccopy_reg -_reconstructor -p1 -(cneo.core.block -Block -p2 -c__builtin__ -object -p3 -NtRp4 -(dp5 -S'index' -p6 -NsS'description' -p7 -NsS'file_datetime' -p8 -NsS'segments' -p9 -(lp10 -g1 -(cneo.core.segment -Segment -p11 -g3 -NtRp12 -(dp13 -g6 -NsS'analogsignals' -p14 -(lp15 -cneo.core.analogsignal -_new_AnalogSignalArray -p16 -(cneo.core.analogsignal -AnalogSignal -p17 -cnumpy.core.multiarray -_reconstruct -p18 -(cnumpy -ndarray -p19 -(I0 -tS'b' -tRp20 -(I1 -(I10 -I1 -tcnumpy -dtype -p21 -(S'i8' -I0 -I1 -tRp22 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00' -tbcquantities.quantity -_reconstruct_quantity -p23 -(cquantities.quantity -Quantity -p24 -g19 -(I0 -tp25 -S'b' -tRp26 -(I1 -(tg21 -(S'f8' -I0 -I1 -tRp27 -(I3 -S'<' -NNNI-1 -I-1 -I0 -tbI00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(cquantities.dimensionality -Dimensionality -p28 -c__builtin__ -dict -p29 -(dp30 -cquantities.unitquantity -UnitQuantity -p31 -(S'millivolt' -p32 -g23 -(g24 -g19 -g25 -S'b' -tRp33 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp34 -g31 -(S'volt' -p35 -g23 -(g24 -g19 -g25 -S'b' -tRp36 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp37 -g31 -(S'coulomb' -p38 -g23 -(g24 -g19 -g25 -S'b' -tRp39 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp40 -cquantities.unitquantity -UnitCurrent -p41 -(S'ampere' -p42 -NS'A' -N(lp43 -S'amp' -p44 -aS'amps' -p45 -aS'amperes' -p46 -aNtRp47 -(I1 -(I4 -I96 -tp48 -tbI1 -scquantities.unitquantity -UnitTime -p49 -(S'second' -p50 -NS's' -N(lp51 -S'sec' -p52 -aS'seconds' -p53 -aNtRp54 -(I1 -(I3 -I0 -tp55 -tbI1 -stRp56 -tbS'C' -N(lp57 -NtRp58 -(I1 -(I90 -I99 -tp59 -tbI-1 -sg31 -(S'joule' -p60 -g23 -(g24 -g19 -g25 -S'b' -tRp61 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp62 -g31 -(S'newton' -p63 -g23 -(g24 -g19 -g25 -S'b' -tRp64 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp65 -cquantities.unitquantity -UnitLength -p66 -(S'meter' -p67 -NS'm' -N(lp68 -S'meters' -p69 -aS'metre' -p70 -aS'metres' -p71 -aNtRp72 -(I1 -(I2 -I2 -tp73 -tbI1 -scquantities.unitquantity -UnitMass -p74 -(S'kilogram' -p75 -NS'kg' -p76 -N(lp77 -S'kilograms' -p78 -aNtRp79 -(I1 -(I1 -I63 -tp80 -tbI1 -sg54 -I-2 -stRp81 -tbS'N' -N(lp82 -S'newtons' -p83 -aNtRp84 -(I1 -(I90 -I66 -tp85 -tbI1 -sg72 -I1 -stRp86 -tbS'J' -N(lp87 -S'joules' -p88 -aNtRp89 -(I1 -(I90 -I76 -tp90 -tbI1 -stRp91 -tbS'V' -N(lp92 -S'volts' -p93 -aNtRp94 -(I1 -(I90 -I100 -tp95 -tbI1 -stRp96 -tbS'mV' -p97 -N(lp98 -S'millivolts' -p99 -aNtRp100 -(I1 -(I90 -I102 -tp101 -tbI1 -stRp102 -tbg22 -I01 -g23 -(g24 -g19 -g25 -S'b' -tRp103 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\x00\x00' -g1 -(g28 -g29 -(dp104 -g54 -I1 -stRp105 -tbg23 -(g24 -g19 -g25 -S'b' -tRp106 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00@\x8f@' -g1 -(g28 -g29 -(dp107 -g31 -(S'hertz' -p108 -g23 -(g24 -g19 -g25 -S'b' -tRp109 -(I1 -(tg27 -I00 -S'\x00\x00\x00\x00\x00\x00\xf0?' -g1 -(g28 -g29 -(dp110 -g54 -I-1 -stRp111 -tbS'Hz' -p112 -Ng57 -NtRp113 -(I1 -(I90 -I142 -tp114 -tbI1 -stRp115 -tbg23 -(g24 -g19 -g25 -S'b' -tRp116 -(I1 -(tg27 -I00 -S'\xfc\xa9\xf1\xd2MbP?' -g1 -(g28 -g29 -(dp117 -g113 -I-1 -stRp118 -tbNNN(dp119 -tRp120 -asS'spiketrains' -p121 -(lp122 -sg7 -Nsg8 -NsS'file_origin' -p123 -NsS'events' -p124 -(lp125 -sS'epochs' -p126 -(lp127 -sS'rec_datetime' -p128 -NsS'irregularlysampledsignals' -p129 -(lp130 -sS'annotations' -p131 -(dp132 -sS'block' -p133 -NsS'name' -p134 -Nsbasg123 -NsS'channel_indexes' -p135 -(lp136 -sg131 -(dp137 -sg128 -Nsg134 -Nsb. \ No newline at end of file diff --git a/efel/tests/test_io.py b/efel/tests/test_io.py index a427a6b..846828c 100644 --- a/efel/tests/test_io.py +++ b/efel/tests/test_io.py @@ -128,7 +128,7 @@ def test_load_fragment_allcolumns(): def test_load_neo_file_stim_time_arg (): import neo import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_no_times.pickle") + file_name = os.path.join(neo_test_files_dir, "neo_test_file_no_times.mat") #test load_neo_file without stim time nt.assert_raises(ValueError, efel.io.load_neo_file,file_name) @@ -141,20 +141,20 @@ def test_load_neo_file_stim_time_arg (): nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) -# def test_load_neo_file_stim_time_epoch (): -# import neo -# import efel -# file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.pickle") +def test_load_neo_file_stim_time_epoch (): + import neo + import efel + file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.mat") -# result = efel.io.load_neo_file(file_name) -# nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) -# nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) + result = efel.io.load_neo_file(file_name) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) def test_load_neo_file_stim_time_events (): import neo import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time.pickle") + file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time.mat") result = efel.io.load_neo_file(file_name) nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) @@ -163,6 +163,6 @@ def test_load_neo_file_stim_time_events (): def test_load_neo_file_stim_time_events_incomplete (): import neo import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time_incomplete.pickle") + file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time_incomplete.mat") nt.assert_raises(ValueError, efel.io.load_neo_file, file_name) From 204138caf23d5f69377769b75e4e9fa58888ad2f Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Fri, 31 Mar 2017 16:01:25 +0200 Subject: [PATCH 07/10] Split load_neo_file into : load_neo_file + extract_stim_times_from_neo_data --- efel/io.py | 97 +++++++++++++--------- ...reate_neo_files_test.py => create_neo_files.py} | 0 2 files changed, 57 insertions(+), 40 deletions(-) rename efel/tests/neo_test_files/{create_neo_files_test.py => create_neo_files.py} (100%) diff --git a/efel/io.py b/efel/io.py index 5428436..4ccfaf9 100644 --- a/efel/io.py +++ b/efel/io.py @@ -82,36 +82,27 @@ def load_fragment(fragment_url, mime_type=None): raise TypeError('load_fragment: unknown mime type %s' % mime_type) -def load_neo_file (file_name, stim_start=None, stim_end=None): +def extract_stim_times_from_neo_data (blocks, stim_start, stim_end): """ - This function uses the Neo module to load a data file and convert the data structure to be readable by eFEL. + This function seeks for the stim_start and stim_end parameters inside the Neo data and return it. Parameters ========== - file_name : string - path to the location of a Dependency file - stim_start : numerical value (ms) - Optional if there is an Epoch or two Events in the file - stim_end : numerical value (ms) - Optional if there is an Epoch or two Events in the file + blocks : Neo object blocks + stim_start : numerical value (ms) or None + stim_end : numerical value (ms) or None Epoch.name should be one of "stim", "stimulus", "stimulation", "current_injection" First Event.name should be "stim_start", "stimulus_start", "stimulation_start", "current_injection_start" Second Event.name should be one of "stim_end", "stimulus_end", "stimulation_end", "current_injection_end" - The returned object is presented like this : - returned object : [Segments_1, Segments_2, ..., Segments_n] - Segments_1 = [Traces_1, Traces_2, ..., Traces_n] + Returned objects + ==================== + stim_start : numerical value (ms) or None + stim_end : numerical value (ms) or None + """ - - import numpy as np - import neo - import quantities as pq - - reader = neo.io.get_io(file_name) - blocks = reader.read() - - #this part of the code aim to find informations about stimulations, if stimulation time has not been specified in arguments. + #this part code aims to find informations about stimulations, if stimulation time are None. if stim_start is None and stim_end is None : for bl in blocks : for seg in bl.segments : @@ -128,24 +119,23 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): event_end = False for event in seg.events : rescaled = False - if rescaled is False : - if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : - if stim_start is None : - if event_start == False : - event = event.rescale('ms').magnitude - if type(event) is list : - stim_start = event[0] - else : - stim_start = event - rescaled = True + if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : + if stim_start is None : + if event_start == False : + event = event.rescale('ms').magnitude + if type(event) is list : + stim_start = event[0] else : - raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' - +' The program does not know which one to chose') + stim_start = event + rescaled = True else : - raise ValueError('It seems that stimulation start time is defined in epochs and an event.' - +' The program does not know which one to chose') + raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' + +' The program does not know which one to chose') + else : + raise ValueError('It seems that stimulation start time is defined in epochs and an event.' + +' The program does not know which one to chose') - if rescaled is False : + if not rescaled : if event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : if stim_end is None : if event_end == False : @@ -160,29 +150,56 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): else : raise ValueError('It seems that stimulation end time is defined in epochs and an event.' +' The program does not know which one to chose') + return stim_start, stim_end + +def load_neo_file (file_name, stim_start=None, stim_end=None): + """ + This function uses the Neo module to load a data file and convert the data structure to be readable by eFEL. + Parameters + ========== + file_name : string + path to the location of a Dependency file + stim_start : numerical value (ms) + Optional if there is an Epoch or two Events in the file + stim_end : numerical value (ms) + Optional if there is an Epoch or two Events in the file + + Epoch.name should be one of "stim", "stimulus", "stimulation", "current_injection" + First Event.name should be "stim_start", "stimulus_start", "stimulation_start", "current_injection_start" + Second Event.name should be one of "stim_end", "stimulus_end", "stimulation_end", "current_injection_end" + + The returned object is presented like this : + returned object : [Segments_1, Segments_2, ..., Segments_n] + Segments_1 = [Traces_1, Traces_2, ..., Traces_n] + """ + + #import numpy as np + import neo + #import quantities as pq + + reader = neo.io.get_io(file_name) + blocks = reader.read() + + stim_start, stim_end = extract_stim_times_from_neo_data(blocks, stim_start, stim_end) if stim_start is None or stim_end is None : raise ValueError('No stim_start or stim_end has been found inside epochs or events. You can directly specify their value as argument "stim_start" and "stim_end"') - #this part of the code transform the data format. + #this part of the code transforms the data format. efel_blocks = [] for bl in blocks : efel_segments = [] for seg in bl.segments : - traces = [] count_traces = 0 analogsignals = seg.analogsignals for sig in analogsignals : traces.append({}) - traces[count_traces]['T'] = sig.times.rescale('ms').magnitude traces[count_traces]['V'] = sig.rescale('mV').magnitude - traces[count_traces]['stim_start'] = [stim_start] traces[count_traces]['stim_end'] = [stim_end] - count_traces += 1 efel_segments.append(traces) diff --git a/efel/tests/neo_test_files/create_neo_files_test.py b/efel/tests/neo_test_files/create_neo_files.py similarity index 100% rename from efel/tests/neo_test_files/create_neo_files_test.py rename to efel/tests/neo_test_files/create_neo_files.py From 467dd165fe541ad2a5e44a102b1a2d3f370986a6 Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Tue, 4 Apr 2017 15:16:55 +0200 Subject: [PATCH 08/10] added scipy in install_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3249036..0444bba 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ name="efel", version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - install_requires=['numpy>=1.6', 'six', 'neo>=0.5.0'], + install_requires=['numpy>=1.6', 'six', 'neo>=0.5.0', 'scipy'], packages=['efel'], author="BlueBrain Project, EPFL", maintainer="Werner Van Geit", From 560b31591a8bc5d398dd9fdafe0a3783e8969d9e Mon Sep 17 00:00:00 2001 From: Joffrey Gonin Date: Wed, 5 Apr 2017 17:07:56 +0200 Subject: [PATCH 09/10] refactor extract_stim_times_from_neo_data and add additional tests --- efel/io.py | 73 +++++++++++++++++++-------------- efel/tests/test_io.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 153 insertions(+), 32 deletions(-) diff --git a/efel/io.py b/efel/io.py index 4ccfaf9..93364d5 100644 --- a/efel/io.py +++ b/efel/io.py @@ -102,54 +102,65 @@ def extract_stim_times_from_neo_data (blocks, stim_start, stim_end): stim_end : numerical value (ms) or None """ + import numpy #this part code aims to find informations about stimulations, if stimulation time are None. if stim_start is None and stim_end is None : for bl in blocks : for seg in bl.segments : + event_start_rescaled = False + event_end_rescaled = False + epoch_rescaled = False for epoch in seg.epochs : if epoch.name in ("stim", "stimulus", "stimulation", "current_injection"): if stim_start is None : epoch = epoch.rescale('ms').magnitude stim_start = epoch[0] stim_end = epoch[-1] + epoch_rescaled = True else : raise ValueError('It seems that there are two epochs related to stimulation, the program does not know which one to chose') - event_start = False - event_end = False for event in seg.events : - rescaled = False - if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : - if stim_start is None : - if event_start == False : - event = event.rescale('ms').magnitude - if type(event) is list : - stim_start = event[0] - else : - stim_start = event - rescaled = True - else : - raise ValueError('It seems that there are two events (or an epoch and an event), related to stimulation start.' + #Test event stim_start + if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : + #tests if not already found once + if event_start_rescaled : + raise ValueError('It seems that stimulation start time is defined more than one event.' + +' The program does not know which one to chose') + if epoch_rescaled : + raise ValueError('It seems that stim_start is defined in both epoch and an event.' +' The program does not know which one to chose') - else : - raise ValueError('It seems that stimulation start time is defined in epochs and an event.' + + if stim_start is None : + event = event.rescale('ms').magnitude + + try : + stim_start = event[0] + except : + stim_start = event + + event_start_rescaled = True + + #Test event stim_end + elif event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : + #tests if not already found once + if event_end_rescaled : + raise ValueError('It seems that stimulation end time is defined more than one event.' + +' The program does not know which one to chose') + if epoch_rescaled : + raise ValueError('It seems that stim_end is defined in both epoch and an event.' +' The program does not know which one to chose') + + if stim_end is None : + event = event.rescale('ms').magnitude + + try : + stim_end = event[-1] + except : + stim_end = event + + event_end_rescaled = True - if not rescaled : - if event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : - if stim_end is None : - if event_end == False : - event = event.rescale('ms').magnitude - if type(event) is list : - stim_end = event[-1] - else : - stim_end = event - else : - raise ValueError('It seems that there are two events, or an epoch and an event, related to stimulation end.' - +' The program does not know which one to chose') - else : - raise ValueError('It seems that stimulation end time is defined in epochs and an event.' - +' The program does not know which one to chose') return stim_start, stim_end def load_neo_file (file_name, stim_start=None, stim_end=None): diff --git a/efel/tests/test_io.py b/efel/tests/test_io.py index 846828c..64ea66c 100644 --- a/efel/tests/test_io.py +++ b/efel/tests/test_io.py @@ -141,6 +141,116 @@ def test_load_neo_file_stim_time_arg (): nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) +def test_extract_stim_times_from_neo_data_two_epochs (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) + seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) + bl.segments.append(seg) + + nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + +def test_extract_stim_times_from_neo_data_two_events_start (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) + seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_start" )) + bl.segments.append(seg) + + nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + +def test_extract_stim_times_from_neo_data_two_events_end (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_end" )) + seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_end" )) + bl.segments.append(seg) + + nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + +def test_extract_stim_times_from_neo_data_start_in_epoch_event (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) + seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) + bl.segments.append(seg) + + nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + + +def test_extract_stim_times_from_neo_data_end_in_epoch_event (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) + seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_end" )) + bl.segments.append(seg) + + nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + +def test_extract_stim_times_from_neo_data_event_time_list (): + import neo + import efel + import quantities as pq + + bl = neo.core.Block() + seg = neo.core.Segment() + data = range(10) + rate = 1000*pq.Hz + signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") + seg.analogsignals.append(signal) + seg.events.append(neo.core.Event(times=[0.0, 1.0]*pq.ms, units=pq.ms, name="stim_start" )) + seg.events.append(neo.core.Event(times=[10.0, 20.0]*pq.ms, units=pq.ms, name="stim_end" )) + bl.segments.append(seg) + + nt.assert_equal((0.0,20.0), efel.io.extract_stim_times_from_neo_data([bl], None, None) ) + + + + + + + + def test_load_neo_file_stim_time_epoch (): import neo import efel diff --git a/setup.py b/setup.py index 0444bba..4af12aa 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ name="efel", version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - install_requires=['numpy>=1.6', 'six', 'neo>=0.5.0', 'scipy'], + install_requires=['numpy>=1.6', 'six', 'neo==0.5.0', 'scipy', 'quantities'], packages=['efel'], author="BlueBrain Project, EPFL", maintainer="Werner Van Geit", From fbe1eefb3e4761780a0b5a7d835db90714f86894 Mon Sep 17 00:00:00 2001 From: Werner Van Geit Date: Thu, 6 Apr 2017 10:36:21 +0200 Subject: [PATCH 10/10] Cleaned coding style Now test requirements in Makefile --- Makefile | 14 ++-- efel/io.py | 170 ++++++++++++++++++++++---------------- efel/tests/test_io.py | 222 +++++++++++++++++++++++++++++++++++--------------- setup.py | 3 +- 4 files changed, 265 insertions(+), 144 deletions(-) diff --git a/Makefile b/Makefile index c988ba6..69d9c68 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,9 @@ +TEST_REQUIREMENTS=nose coverage + all: install install: clean python setup.py sdist pip install dist/*.tar.gz --upgrade -install3: clean - python3 setup.py sdist - pip3 install dist/*.tar.gz --upgrade doc_efeatures: rm -rf docs/build_efeatures && \ mkdir docs/build_efeatures && \ @@ -23,20 +22,17 @@ doc_upload: doc git commit -m "Updating docs" && \ git push "git@github.com:BlueBrain/eFEL.git" master:gh-pages --force && \ rm -rf .git +install_test_requirements: + pip install -q $(TEST_REQUIREMENTS) --upgrade update_version: cd efel && \ python -c 'import version; version._get_version_number()' && \ git add GITHASH.txt && \ git add VERSION.txt && \ git commit -m 'Updated version number' -test: install - pip install nose coverage --upgrade +test: install install_test_requirements cd efel/tests; nosetests -s -v -x --with-coverage --cover-xml \ --cover-package efel -test3: install3 - pip3 install nose coverage --upgrade - cd efel/tests; nosetests-3.4 -s -v -x --with-coverage --cover-xml \ - --cover-package efel pypi: test pip install twine --upgrade rm -rf dist diff --git a/efel/io.py b/efel/io.py index 93364d5..7e1d182 100644 --- a/efel/io.py +++ b/efel/io.py @@ -82,9 +82,9 @@ def load_fragment(fragment_url, mime_type=None): raise TypeError('load_fragment: unknown mime type %s' % mime_type) -def extract_stim_times_from_neo_data (blocks, stim_start, stim_end): +def extract_stim_times_from_neo_data(blocks, stim_start, stim_end): """ - This function seeks for the stim_start and stim_end parameters inside the Neo data and return it. + Seeks for the stim_start and stim_end parameters inside the Neo data. Parameters ========== @@ -92,80 +92,109 @@ def extract_stim_times_from_neo_data (blocks, stim_start, stim_end): stim_start : numerical value (ms) or None stim_end : numerical value (ms) or None - Epoch.name should be one of "stim", "stimulus", "stimulation", "current_injection" - First Event.name should be "stim_start", "stimulus_start", "stimulation_start", "current_injection_start" - Second Event.name should be one of "stim_end", "stimulus_end", "stimulation_end", "current_injection_end" + Epoch.name should be one of "stim", "stimulus", "stimulation", + "current_injection" + First Event.name should be "stim_start", "stimulus_start", + "stimulation_start", "current_injection_start" + Second Event.name should be one of "stim_end", + "stimulus_end", "stimulation_end", "current_injection_end" - Returned objects + Returned objects ==================== stim_start : numerical value (ms) or None stim_end : numerical value (ms) or None - + """ - import numpy - #this part code aims to find informations about stimulations, if stimulation time are None. - if stim_start is None and stim_end is None : - for bl in blocks : - for seg in bl.segments : + # this part code aims to find informations about stimulations, if + # stimulation time are None. + if stim_start is None and stim_end is None: + for bl in blocks: + for seg in bl.segments: event_start_rescaled = False - event_end_rescaled = False + event_end_rescaled = False epoch_rescaled = False - for epoch in seg.epochs : - if epoch.name in ("stim", "stimulus", "stimulation", "current_injection"): - if stim_start is None : + for epoch in seg.epochs: + if epoch.name in ( + "stim", + "stimulus", + "stimulation", + "current_injection"): + if stim_start is None: epoch = epoch.rescale('ms').magnitude stim_start = epoch[0] stim_end = epoch[-1] epoch_rescaled = True - else : - raise ValueError('It seems that there are two epochs related to stimulation, the program does not know which one to chose') - - for event in seg.events : - #Test event stim_start - if event.name in ("stim_start", "stimulus_start", "stimulation_start", "current_injection_start") : - #tests if not already found once - if event_start_rescaled : - raise ValueError('It seems that stimulation start time is defined more than one event.' - +' The program does not know which one to chose') - if epoch_rescaled : - raise ValueError('It seems that stim_start is defined in both epoch and an event.' - +' The program does not know which one to chose') - - if stim_start is None : + else: + raise ValueError( + 'It seems that there are two epochs related ' + 'to stimulation, the program does not know ' + 'which one to chose') + + for event in seg.events: + # Test event stim_start + if event.name in ( + "stim_start", + "stimulus_start", + "stimulation_start", + "current_injection_start"): + # tests if not already found once + if event_start_rescaled: + raise ValueError( + 'It seems that stimulation start time is ' + 'defined more than one event.' + ' The program does not know which one ' + 'to choose') + if epoch_rescaled: + raise ValueError( + 'It seems that stim_start is defined in both ' + 'epoch and an event.' + + ' The program does not know which one ' + 'to choose') + + if stim_start is None: event = event.rescale('ms').magnitude - try : + try: stim_start = event[0] - except : + except: stim_start = event event_start_rescaled = True - #Test event stim_end - elif event.name in ("stim_end", "stimulus_end", "stimulation_end", "current_injection_end") : - #tests if not already found once - if event_end_rescaled : - raise ValueError('It seems that stimulation end time is defined more than one event.' - +' The program does not know which one to chose') - if epoch_rescaled : - raise ValueError('It seems that stim_end is defined in both epoch and an event.' - +' The program does not know which one to chose') - - if stim_end is None : - event = event.rescale('ms').magnitude - - try : + # Test event stim_end + elif event.name in ("stim_end", "stimulus_end", + "stimulation_end", + "current_injection_end"): + # tests if not already found once + if event_end_rescaled: + raise ValueError( + 'It seems that stimulation end time is ' + 'defined more than one event.' + ' The program does not know which one ' + 'to choose') + if epoch_rescaled: + raise ValueError( + 'It seems that stim_end is defined in ' + 'both epoch and an event.' + ' The program does not know which one ' + 'to choose') + + if stim_end is None: + event = event.rescale('ms').magnitude + + try: stim_end = event[-1] - except : + except: stim_end = event event_end_rescaled = True return stim_start, stim_end -def load_neo_file (file_name, stim_start=None, stim_end=None): + +def load_neo_file(file_name, stim_start=None, stim_end=None): """ - This function uses the Neo module to load a data file and convert the data structure to be readable by eFEL. + Use neo to load a data file and convert it to be readable by eFEL. Parameters ========== @@ -176,44 +205,49 @@ def load_neo_file (file_name, stim_start=None, stim_end=None): stim_end : numerical value (ms) Optional if there is an Epoch or two Events in the file - Epoch.name should be one of "stim", "stimulus", "stimulation", "current_injection" - First Event.name should be "stim_start", "stimulus_start", "stimulation_start", "current_injection_start" - Second Event.name should be one of "stim_end", "stimulus_end", "stimulation_end", "current_injection_end" + Epoch.name should be one of "stim", "stimulus", "stimulation", + "current_injection" + First Event.name should be "stim_start", "stimulus_start", + "stimulation_start", "current_injection_start" + Second Event.name should be one of "stim_end", "stimulus_end", + "stimulation_end", "current_injection_end" The returned object is presented like this : - returned object : [Segments_1, Segments_2, ..., Segments_n] - Segments_1 = [Traces_1, Traces_2, ..., Traces_n] + returned object : [Segments_1, Segments_2, ..., Segments_n] + Segments_1 = [Traces_1, Traces_2, ..., Traces_n] """ - #import numpy as np import neo - #import quantities as pq reader = neo.io.get_io(file_name) blocks = reader.read() - stim_start, stim_end = extract_stim_times_from_neo_data(blocks, stim_start, stim_end) - if stim_start is None or stim_end is None : - raise ValueError('No stim_start or stim_end has been found inside epochs or events. You can directly specify their value as argument "stim_start" and "stim_end"') + stim_start, stim_end = extract_stim_times_from_neo_data( + blocks, stim_start, stim_end) + if stim_start is None or stim_end is None: + raise ValueError( + 'No stim_start or stim_end has been found inside epochs or events.' + ' You can directly specify their value as argument "stim_start"' + ' and "stim_end"') - #this part of the code transforms the data format. + # this part of the code transforms the data format. efel_blocks = [] - for bl in blocks : + for bl in blocks: efel_segments = [] - for seg in bl.segments : + for seg in bl.segments: traces = [] count_traces = 0 analogsignals = seg.analogsignals - for sig in analogsignals : + for sig in analogsignals: traces.append({}) traces[count_traces]['T'] = sig.times.rescale('ms').magnitude - traces[count_traces]['V'] = sig.rescale('mV').magnitude + traces[count_traces]['V'] = sig.rescale('mV').magnitude traces[count_traces]['stim_start'] = [stim_start] - traces[count_traces]['stim_end'] = [stim_end] + traces[count_traces]['stim_end'] = [stim_end] count_traces += 1 - + efel_segments.append(traces) efel_blocks.append(efel_segments) - return efel_blocks \ No newline at end of file + return efel_blocks diff --git a/efel/tests/test_io.py b/efel/tests/test_io.py index 64ea66c..513df95 100644 --- a/efel/tests/test_io.py +++ b/efel/tests/test_io.py @@ -14,7 +14,7 @@ os.path.dirname( os.path.abspath(__file__)), 'neo_test_files') - + meanfrequency1_filename = os.path.join(testdata_dir, 'basic', 'mean_frequency_1.txt') @@ -125,23 +125,33 @@ def test_load_fragment_allcolumns(): numpy.testing.assert_array_equal(time_io, time_numpy) -def test_load_neo_file_stim_time_arg (): - import neo +def test_load_neo_file_stim_time_arg(): import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_no_times.mat") - - #test load_neo_file without stim time - nt.assert_raises(ValueError, efel.io.load_neo_file,file_name) - #test load_neo_file with stim time arguments - result = efel.io.load_neo_file(file_name, stim_start=0, stim_end=20) - #test load_neo_file with stim time incomplete arguments - nt.assert_raises(ValueError, efel.io.load_neo_file, file_name, stim_start=0) - nt.assert_equal(True, all(result[0][0][0]['T'] == [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])) - nt.assert_equal(True, all(result[0][0][0]['V'] == [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]])) - nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) - nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) - -def test_extract_stim_times_from_neo_data_two_epochs (): + file_name = os.path.join(neo_test_files_dir, "neo_test_file_no_times.mat") + + # test load_neo_file without stim time + nt.assert_raises(ValueError, efel.io.load_neo_file, file_name) + # test load_neo_file with stim time arguments + result = efel.io.load_neo_file(file_name, stim_start=0, stim_end=20) + # test load_neo_file with stim time incomplete arguments + nt.assert_raises( + ValueError, + efel.io.load_neo_file, + file_name, + stim_start=0) + nt.assert_equal( + True, all( + result[0][0][0]['T'] == [ + 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])) + nt.assert_equal( + True, all( + result[0][0][0]['V'] == [ + [0], [1], [2], [3], [4], [5], [6], [7], [8], [9]])) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0]) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0]) + + +def test_extract_stim_times_from_neo_data_two_epochs(): import neo import efel import quantities as pq @@ -149,16 +159,30 @@ def test_extract_stim_times_from_neo_data_two_epochs (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) - seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) + seg.epochs.append( + neo.core.Epoch( + times=pq.Quantity([0.0, 20.0], + units=pq.ms), + name="stim")) + seg.epochs.append( + neo.core.Epoch( + times=pq.Quantity([0.0, 20.0], + units=pq.ms), + name="stim")) bl.segments.append(seg) - nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + nt.assert_raises( + ValueError, + efel.io.extract_stim_times_from_neo_data, + [bl], + None, + None) + -def test_extract_stim_times_from_neo_data_two_events_start (): +def test_extract_stim_times_from_neo_data_two_events_start(): import neo import efel import quantities as pq @@ -166,16 +190,30 @@ def test_extract_stim_times_from_neo_data_two_events_start (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) - seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_start" )) + seg.events.append( + neo.core.Event( + times=[0.0] * pq.ms, + units=pq.ms, + name="stim_start")) + seg.events.append( + neo.core.Event( + times=[20.0] * pq.ms, + units=pq.ms, + name="stim_start")) bl.segments.append(seg) - nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + nt.assert_raises( + ValueError, + efel.io.extract_stim_times_from_neo_data, + [bl], + None, + None) + -def test_extract_stim_times_from_neo_data_two_events_end (): +def test_extract_stim_times_from_neo_data_two_events_end(): import neo import efel import quantities as pq @@ -183,16 +221,30 @@ def test_extract_stim_times_from_neo_data_two_events_end (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_end" )) - seg.events.append(neo.core.Event(times=[20.0]*pq.ms, units=pq.ms, name="stim_end" )) + seg.events.append( + neo.core.Event( + times=[0.0] * pq.ms, + units=pq.ms, + name="stim_end")) + seg.events.append( + neo.core.Event( + times=[20.0] * pq.ms, + units=pq.ms, + name="stim_end")) bl.segments.append(seg) - nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + nt.assert_raises( + ValueError, + efel.io.extract_stim_times_from_neo_data, + [bl], + None, + None) + -def test_extract_stim_times_from_neo_data_start_in_epoch_event (): +def test_extract_stim_times_from_neo_data_start_in_epoch_event(): import neo import efel import quantities as pq @@ -200,17 +252,30 @@ def test_extract_stim_times_from_neo_data_start_in_epoch_event (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) - seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_start" )) + seg.epochs.append( + neo.core.Epoch( + times=pq.Quantity([0.0, 20.0], + units=pq.ms), + name="stim")) + seg.events.append( + neo.core.Event( + times=[0.0] * pq.ms, + units=pq.ms, + name="stim_start")) bl.segments.append(seg) - nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + nt.assert_raises( + ValueError, + efel.io.extract_stim_times_from_neo_data, + [bl], + None, + None) -def test_extract_stim_times_from_neo_data_end_in_epoch_event (): +def test_extract_stim_times_from_neo_data_end_in_epoch_event(): import neo import efel import quantities as pq @@ -218,16 +283,30 @@ def test_extract_stim_times_from_neo_data_end_in_epoch_event (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.epochs.append(neo.core.Epoch(times=pq.Quantity([0.0,20.0], units=pq.ms), name="stim")) - seg.events.append(neo.core.Event(times=[0.0]*pq.ms, units=pq.ms, name="stim_end" )) + seg.epochs.append( + neo.core.Epoch( + times=pq.Quantity([0.0, 20.0], + units=pq.ms), + name="stim")) + seg.events.append( + neo.core.Event( + times=[0.0] * pq.ms, + units=pq.ms, + name="stim_end")) bl.segments.append(seg) - nt.assert_raises(ValueError, efel.io.extract_stim_times_from_neo_data, [bl], None, None) + nt.assert_raises( + ValueError, + efel.io.extract_stim_times_from_neo_data, + [bl], + None, + None) + -def test_extract_stim_times_from_neo_data_event_time_list (): +def test_extract_stim_times_from_neo_data_event_time_list(): import neo import efel import quantities as pq @@ -235,44 +314,55 @@ def test_extract_stim_times_from_neo_data_event_time_list (): bl = neo.core.Block() seg = neo.core.Segment() data = range(10) - rate = 1000*pq.Hz + rate = 1000 * pq.Hz signal = neo.core.AnalogSignal(data, sampling_rate=rate, units="mV") seg.analogsignals.append(signal) - seg.events.append(neo.core.Event(times=[0.0, 1.0]*pq.ms, units=pq.ms, name="stim_start" )) - seg.events.append(neo.core.Event(times=[10.0, 20.0]*pq.ms, units=pq.ms, name="stim_end" )) + seg.events.append( + neo.core.Event( + times=[ + 0.0, + 1.0] * pq.ms, + units=pq.ms, + name="stim_start")) + seg.events.append( + neo.core.Event( + times=[ + 10.0, + 20.0] * pq.ms, + units=pq.ms, + name="stim_end")) bl.segments.append(seg) - nt.assert_equal((0.0,20.0), efel.io.extract_stim_times_from_neo_data([bl], None, None) ) - - - + nt.assert_equal( + (0.0, 20.0), efel.io.extract_stim_times_from_neo_data( + [bl], None, None)) +def test_load_neo_file_stim_time_epoch(): + import efel + file_name = os.path.join( + neo_test_files_dir, + "neo_test_file_epoch_times.mat") + result = efel.io.load_neo_file(file_name) + nt.assert_equal(result[0][0][0]['stim_start'], [0.0]) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0]) -def test_load_neo_file_stim_time_epoch (): - import neo +def test_load_neo_file_stim_time_events(): import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_epoch_times.mat") + file_name = os.path.join( + neo_test_files_dir, + "neo_test_file_events_time.mat") result = efel.io.load_neo_file(file_name) - nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) - nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) - + nt.assert_equal(result[0][0][0]['stim_start'], [0.0]) + nt.assert_equal(result[0][0][0]['stim_end'], [20.0]) -def test_load_neo_file_stim_time_events (): - import neo - import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time.mat") - result = efel.io.load_neo_file(file_name) - nt.assert_equal(result[0][0][0]['stim_start'], [0.0] ) - nt.assert_equal(result[0][0][0]['stim_end'], [20.0] ) - -def test_load_neo_file_stim_time_events_incomplete (): - import neo +def test_load_neo_file_stim_time_events_incomplete(): import efel - file_name = os.path.join(neo_test_files_dir, "neo_test_file_events_time_incomplete.mat") + file_name = os.path.join(neo_test_files_dir, + "neo_test_file_events_time_incomplete.mat") nt.assert_raises(ValueError, efel.io.load_neo_file, file_name) diff --git a/setup.py b/setup.py index 4af12aa..7255902 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,8 @@ name="efel", version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - install_requires=['numpy>=1.6', 'six', 'neo==0.5.0', 'scipy', 'quantities'], + install_requires=['numpy>=1.6', 'six', 'neo>=0.5.0', 'quantities', + 'scipy'], packages=['efel'], author="BlueBrain Project, EPFL", maintainer="Werner Van Geit",