<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import os <EOL> import pickle <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> import numpy as np <EOL> import quantities as pq <EOL> try : <EOL> from IPython . lib . pretty import pretty <EOL> except ImportError as err : <EOL> HAVE_IPYTHON = False <EOL> else : <EOL> HAVE_IPYTHON = True <EOL> from neo . core . analogsignal import AnalogSignal , _get_sampling_rate <EOL> from neo . core import Segment , RecordingChannel <EOL> from neo . test . tools import ( assert_arrays_almost_equal , assert_arrays_equal , <EOL> assert_neo_object_is_compliant , <EOL> assert_same_sub_schema ) <EOL> from neo . test . generate_datasets import ( get_fake_value , get_fake_values , <EOL> fake_neo , TEST_ANNOTATIONS ) <EOL> class Test__generate_datasets ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> self . annotations = dict ( [ ( str ( x ) , TEST_ANNOTATIONS [ x ] ) for x in <EOL> range ( len ( TEST_ANNOTATIONS ) ) ] ) <EOL> def test__get_fake_values ( self ) : <EOL> self . annotations [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> signal = get_fake_value ( '<STR_LIT>' , pq . Quantity , seed = <NUM_LIT:0> , dim = <NUM_LIT:1> ) <EOL> sampling_rate = get_fake_value ( '<STR_LIT>' , pq . Quantity , <EOL> seed = <NUM_LIT:1> , dim = <NUM_LIT:0> ) <EOL> t_start = get_fake_value ( '<STR_LIT>' , pq . Quantity , seed = <NUM_LIT:2> , dim = <NUM_LIT:0> ) <EOL> channel_index = get_fake_value ( '<STR_LIT>' , int , seed = <NUM_LIT:3> ) <EOL> name = get_fake_value ( '<STR_LIT:name>' , str , seed = <NUM_LIT:4> , obj = AnalogSignal ) <EOL> description = get_fake_value ( '<STR_LIT:description>' , str , seed = <NUM_LIT:5> , <EOL> obj = '<STR_LIT>' ) <EOL> file_origin = get_fake_value ( '<STR_LIT>' , str ) <EOL> attrs1 = { '<STR_LIT>' : channel_index , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:description>' : description , <EOL> '<STR_LIT>' : file_origin } <EOL> attrs2 = attrs1 . copy ( ) <EOL> attrs2 . update ( self . annotations ) <EOL> res11 = get_fake_values ( AnalogSignal , annotate = False , seed = <NUM_LIT:0> ) <EOL> res12 = get_fake_values ( '<STR_LIT>' , annotate = False , seed = <NUM_LIT:0> ) <EOL> res21 = get_fake_values ( AnalogSignal , annotate = True , seed = <NUM_LIT:0> ) <EOL> res22 = get_fake_values ( '<STR_LIT>' , annotate = True , seed = <NUM_LIT:0> ) <EOL> assert_arrays_equal ( res11 . pop ( '<STR_LIT>' ) , signal ) <EOL> assert_arrays_equal ( res12 . pop ( '<STR_LIT>' ) , signal ) <EOL> assert_arrays_equal ( res21 . pop ( '<STR_LIT>' ) , signal ) <EOL> assert_arrays_equal ( res22 . pop ( '<STR_LIT>' ) , signal ) <EOL> assert_arrays_equal ( res11 . pop ( '<STR_LIT>' ) , sampling_rate ) <EOL> assert_arrays_equal ( res12 . pop ( '<STR_LIT>' ) , sampling_rate ) <EOL> assert_arrays_equal ( res21 . pop ( '<STR_LIT>' ) , sampling_rate ) <EOL> assert_arrays_equal ( res22 . pop ( '<STR_LIT>' ) , sampling_rate ) <EOL> assert_arrays_equal ( res11 . pop ( '<STR_LIT>' ) , t_start ) <EOL> assert_arrays_equal ( res12 . pop ( '<STR_LIT>' ) , t_start ) <EOL> assert_arrays_equal ( res21 . pop ( '<STR_LIT>' ) , t_start ) <EOL> assert_arrays_equal ( res22 . pop ( '<STR_LIT>' ) , t_start ) <EOL> self . assertEqual ( res11 , attrs1 ) <EOL> self . assertEqual ( res12 , attrs1 ) <EOL> self . assertEqual ( res21 , attrs2 ) <EOL> self . assertEqual ( res22 , attrs2 ) <EOL> def test__fake_neo__cascade ( self ) : <EOL> self . annotations [ '<STR_LIT>' ] = None <EOL> obj_type = AnalogSignal <EOL> cascade = True <EOL> res = fake_neo ( obj_type = obj_type , cascade = cascade ) <EOL> self . assertTrue ( isinstance ( res , AnalogSignal ) ) <EOL> assert_neo_object_is_compliant ( res ) <EOL> self . assertEqual ( res . annotations , self . annotations ) <EOL> def test__fake_neo__nocascade ( self ) : <EOL> self . annotations [ '<STR_LIT>' ] = None <EOL> obj_type = '<STR_LIT>' <EOL> cascade = False <EOL> res = fake_neo ( obj_type = obj_type , cascade = cascade ) <EOL> self . assertTrue ( isinstance ( res , AnalogSignal ) ) <EOL> assert_neo_object_is_compliant ( res ) <EOL> self . assertEqual ( res . annotations , self . annotations ) <EOL> class TestAnalogSignalConstructor ( unittest . TestCase ) : <EOL> def test__create_from_list ( self ) : <EOL> data = range ( <NUM_LIT:10> ) <EOL> rate = <NUM_LIT:1000> * pq . Hz <EOL> signal = AnalogSignal ( data , sampling_rate = rate , units = "<STR_LIT>" ) <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . t_start , <NUM_LIT:0> * pq . ms ) <EOL> self . assertEqual ( signal . t_stop , len ( data ) / rate ) <EOL> self . assertEqual ( signal [ <NUM_LIT:9> ] , <NUM_LIT> * pq . uV ) <EOL> def test__create_from_np_array ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) <EOL> rate = <NUM_LIT:1> * pq . kHz <EOL> signal = AnalogSignal ( data , sampling_rate = rate , units = "<STR_LIT>" ) <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . t_start , <NUM_LIT:0> * pq . ms ) <EOL> self . assertEqual ( signal . t_stop , data . size / rate ) <EOL> self . assertEqual ( signal [ <NUM_LIT:9> ] , <NUM_LIT> * pq . mV ) <EOL> def test__create_from_quantities_array ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> rate = <NUM_LIT> * pq . Hz <EOL> signal = AnalogSignal ( data , sampling_rate = rate ) <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . t_start , <NUM_LIT:0> * pq . ms ) <EOL> self . assertEqual ( signal . t_stop , data . size / rate ) <EOL> self . assertEqual ( signal [ <NUM_LIT:9> ] , <NUM_LIT> * pq . V ) <EOL> def test__create_from_array_no_units_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) <EOL> self . assertRaises ( ValueError , AnalogSignal , data , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz ) <EOL> def test__create_from_quantities_array_inconsistent_units_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> self . assertRaises ( ValueError , AnalogSignal , data , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz , units = "<STR_LIT>" ) <EOL> def test__create_without_sampling_rate_or_period_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> self . assertRaises ( ValueError , AnalogSignal , data ) <EOL> def test__create_with_None_sampling_rate_should_raise_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> self . assertRaises ( ValueError , AnalogSignal , data , sampling_rate = None ) <EOL> def test__create_with_None_t_start_should_raise_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> rate = <NUM_LIT> * pq . Hz <EOL> self . assertRaises ( ValueError , AnalogSignal , data , <EOL> sampling_rate = rate , t_start = None ) <EOL> def test__create_inconsistent_sampling_rate_and_period_ValueError ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> self . assertRaises ( ValueError , AnalogSignal , data , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz , sampling_period = <NUM_LIT:5> * pq . s ) <EOL> def test__create_with_copy_true_should_return_copy ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> rate = <NUM_LIT> * pq . Hz <EOL> signal = AnalogSignal ( data , copy = True , sampling_rate = rate ) <EOL> data [ <NUM_LIT:3> ] = <NUM_LIT> * pq . mV <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertNotEqual ( signal [ <NUM_LIT:3> ] , <NUM_LIT> * pq . mV ) <EOL> def test__create_with_copy_false_should_return_view ( self ) : <EOL> data = np . arange ( <NUM_LIT> ) * pq . mV <EOL> rate = <NUM_LIT> * pq . Hz <EOL> signal = AnalogSignal ( data , copy = False , sampling_rate = rate ) <EOL> data [ <NUM_LIT:3> ] = <NUM_LIT> * pq . mV <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal [ <NUM_LIT:3> ] , <NUM_LIT> * pq . mV ) <EOL> def test__create_with_additional_argument ( self ) : <EOL> signal = AnalogSignal ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , units = "<STR_LIT>" , sampling_rate = <NUM_LIT:1> * pq . kHz , <EOL> file_origin = '<STR_LIT>' , ratname = '<STR_LIT>' ) <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . annotations , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( signal . file_origin , '<STR_LIT>' ) <EOL> class TestAnalogSignalProperties ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . t_start = [ <NUM_LIT:0.0> * pq . ms , <NUM_LIT:100> * pq . ms , - <NUM_LIT:200> * pq . ms ] <EOL> self . rates = [ <NUM_LIT:1> * pq . kHz , <NUM_LIT> * pq . Hz , <NUM_LIT> * pq . Hz ] <EOL> self . rates2 = [ <NUM_LIT:2> * pq . kHz , <NUM_LIT> * pq . Hz , <NUM_LIT> * pq . Hz ] <EOL> self . data = [ np . arange ( <NUM_LIT> ) * pq . nA , <EOL> np . arange ( - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) * pq . mV , <EOL> np . random . uniform ( size = <NUM_LIT:100> ) * pq . uV ] <EOL> self . signals = [ AnalogSignal ( D , sampling_rate = r , t_start = t , <EOL> testattr = '<STR_LIT:test>' ) <EOL> for r , D , t in zip ( self . rates , <EOL> self . data , <EOL> self . t_start ) ] <EOL> def test__compliant ( self ) : <EOL> for signal in self . signals : <EOL> assert_neo_object_is_compliant ( signal ) <EOL> def test__t_stop_getter ( self ) : <EOL> for i , signal in enumerate ( self . signals ) : <EOL> self . assertEqual ( signal . t_stop , <EOL> self . t_start [ i ] + self . data [ i ] . size / self . rates [ i ] ) <EOL> def test__duration_getter ( self ) : <EOL> for signal in self . signals : <EOL> self . assertAlmostEqual ( signal . duration , <EOL> signal . t_stop - signal . t_start , <EOL> delta = <NUM_LIT> ) <EOL> def test__sampling_rate_getter ( self ) : <EOL> for signal , rate in zip ( self . signals , self . rates ) : <EOL> self . assertEqual ( signal . sampling_rate , rate ) <EOL> def test__sampling_period_getter ( self ) : <EOL> for signal , rate in zip ( self . signals , self . rates ) : <EOL> self . assertEqual ( signal . sampling_period , <NUM_LIT:1> / rate ) <EOL> def test__sampling_rate_setter ( self ) : <EOL> for signal , rate in zip ( self . signals , self . rates2 ) : <EOL> signal . sampling_rate = rate <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . sampling_rate , rate ) <EOL> self . assertEqual ( signal . sampling_period , <NUM_LIT:1> / rate ) <EOL> def test__sampling_period_setter ( self ) : <EOL> for signal , rate in zip ( self . signals , self . rates2 ) : <EOL> signal . sampling_period = <NUM_LIT:1> / rate <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertEqual ( signal . sampling_rate , rate ) <EOL> self . assertEqual ( signal . sampling_period , <NUM_LIT:1> / rate ) <EOL> def test__sampling_rate_setter_None_ValueError ( self ) : <EOL> self . assertRaises ( ValueError , setattr , self . signals [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , None ) <EOL> def test__sampling_rate_setter_not_quantity_ValueError ( self ) : <EOL> self . assertRaises ( ValueError , setattr , self . signals [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , <NUM_LIT> ) <EOL> def test__sampling_period_setter_None_ValueError ( self ) : <EOL> signal = self . signals [ <NUM_LIT:0> ] <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertRaises ( ValueError , setattr , signal , '<STR_LIT>' , None ) <EOL> def test__sampling_period_setter_not_quantity_ValueError ( self ) : <EOL> self . assertRaises ( ValueError , setattr , self . signals [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , <NUM_LIT> ) <EOL> def test__t_start_setter_None_ValueError ( self ) : <EOL> signal = self . signals [ <NUM_LIT:0> ] <EOL> assert_neo_object_is_compliant ( signal ) <EOL> self . assertRaises ( ValueError , setattr , signal , '<STR_LIT>' , None ) <EOL> def test__times_getter ( self ) : <EOL> for i , signal in enumerate ( self . signals ) : <EOL> targ = np . arange ( self . data [ i ] . size ) <EOL> targ = targ / self . rates [ i ] + self . t_start [ i ] <EOL> assert_neo_object_is_compliant ( signal ) <EOL> assert_arrays_almost_equal ( signal . times , targ , <NUM_LIT> * pq . ms ) <EOL> def test__duplicate_with_new_array ( self ) : <EOL> signal1 = self . signals [ <NUM_LIT:1> ] <EOL> signal2 = self . signals [ <NUM_LIT:2> ] <EOL> data2 = self . data [ <NUM_LIT:2> ] <EOL> signal1b = signal1 . duplicate_with_new_array ( data2 ) <EOL> assert_arrays_almost_equal ( np . asarray ( signal1b ) , <EOL> np . asarray ( signal2 / <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( signal1b . t_start , signal1 . t_start ) <EOL> self . assertEqual ( signal1b . sampling_rate , signal1 . sampling_rate ) <EOL> def test__children ( self ) : <EOL> signal = self . signals [ <NUM_LIT:0> ] <EOL> segment = Segment ( name = '<STR_LIT>' ) <EOL> segment . analogsignals = [ signal ] <EOL> segment . create_many_to_one_relationship ( ) <EOL> rchan = RecordingChannel ( name = '<STR_LIT>' ) <EOL> rchan . analogsignals = [ signal ] <EOL> rchan . create_many_to_one_relationship ( ) <EOL> self . assertEqual ( signal . _single_parent_objects , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( signal . _multi_parent_objects , ( ) ) <EOL> self . assertEqual ( signal . _single_parent_containers , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( signal . _multi_parent_containers , ( ) ) <EOL> self . assertEqual ( signal . _parent_objects , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( signal . _parent_containers , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( signal . parents ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( signal . parents [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( signal . parents [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> assert_neo_object_is_compliant ( signal ) <EOL> def test__repr ( self ) : <EOL> for i , signal in enumerate ( self . signals ) : <EOL> prepr = repr ( signal ) <EOL> targ = '<STR_LIT>' % ( repr ( self . data [ i ] ) , <EOL> self . t_start [ i ] , <EOL> self . t_start [ i ] + len ( self . data [ i ] ) / self . rates [ i ] , <EOL> self . rates [ i ] ) <EOL> self . assertEqual ( prepr , targ ) <EOL> @ unittest . skipUnless ( HAVE_IPYTHON , "<STR_LIT>" ) <EOL> def test__pretty ( self ) : <EOL> for i , signal in enumerate ( self . signals ) : <EOL> prepr = pretty ( signal ) <EOL> targ = ( ( '<STR_LIT>' % <EOL> ( signal . units , len ( signal ) , signal . dtype ) ) + <EOL> ( '<STR_LIT>' % signal . annotations ) + <EOL> ( '<STR_LIT>' % signal . channel_index ) + <EOL> ( '<STR_LIT>' % signal . sampling_rate ) + <EOL> ( '<STR_LIT>' % ( signal . t_start , signal . t_stop ) ) ) <EOL> self . assertEqual ( prepr , targ ) <EOL> class TestAnalogSignalArrayMethods ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data1 = np . arange ( <NUM_LIT> ) <EOL> self . data1quant = self . data1 * pq . nA <EOL> self . signal1 = AnalogSignal ( self . data1quant , sampling_rate = <NUM_LIT:1> * pq . kHz , <EOL> name = '<STR_LIT>' , description = '<STR_LIT>' , <EOL> file_origin = '<STR_LIT>' , arg1 = '<STR_LIT:test>' ) <EOL> def test__compliant ( self ) : <EOL> assert_neo_object_is_compliant ( self . signal1 ) <EOL> def test__slice_should_return_AnalogSignal ( self ) : <EOL> result = self . signal1 [ <NUM_LIT:3> : <NUM_LIT:8> ] <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( result . size , <NUM_LIT:5> ) <EOL> self . assertEqual ( result . sampling_period , self . signal1 . sampling_period ) <EOL> self . assertEqual ( result . sampling_rate , self . signal1 . sampling_rate ) <EOL> self . assertEqual ( result . t_start , <EOL> self . signal1 . t_start + <NUM_LIT:3> * result . sampling_period ) <EOL> self . assertEqual ( result . t_stop , <EOL> result . t_start + <NUM_LIT:5> * result . sampling_period ) <EOL> assert_arrays_equal ( result , self . data1 [ <NUM_LIT:3> : <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result . file_origin , self . signal1 . file_origin ) <EOL> self . assertEqual ( result . name , self . signal1 . name ) <EOL> self . assertEqual ( result . description , self . signal1 . description ) <EOL> self . assertEqual ( result . annotations , self . signal1 . annotations ) <EOL> def test__slice_should_change_sampling_period ( self ) : <EOL> result1 = self . signal1 [ : <NUM_LIT:2> ] <EOL> result2 = self . signal1 [ : : <NUM_LIT:2> ] <EOL> result3 = self . signal1 [ <NUM_LIT:1> : <NUM_LIT:7> : <NUM_LIT:2> ] <EOL> self . assertIsInstance ( result1 , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result1 ) <EOL> self . assertEqual ( result1 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result1 . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result1 . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result1 . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertIsInstance ( result2 , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result2 ) <EOL> self . assertEqual ( result2 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result2 . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result2 . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result2 . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertIsInstance ( result3 , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result3 ) <EOL> self . assertEqual ( result3 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result3 . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result3 . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result3 . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( result1 . sampling_period , self . signal1 . sampling_period ) <EOL> self . assertEqual ( result2 . sampling_period , <EOL> self . signal1 . sampling_period * <NUM_LIT:2> ) <EOL> self . assertEqual ( result3 . sampling_period , <EOL> self . signal1 . sampling_period * <NUM_LIT:2> ) <EOL> assert_arrays_equal ( result1 , self . data1 [ : <NUM_LIT:2> ] ) <EOL> assert_arrays_equal ( result2 , self . data1 [ : : <NUM_LIT:2> ] ) <EOL> assert_arrays_equal ( result3 , self . data1 [ <NUM_LIT:1> : <NUM_LIT:7> : <NUM_LIT:2> ] ) <EOL> def test__getitem_should_return_single_quantity ( self ) : <EOL> result1 = self . signal1 [ <NUM_LIT:0> ] <EOL> result2 = self . signal1 [ <NUM_LIT:9> ] <EOL> self . assertIsInstance ( result1 , pq . Quantity ) <EOL> self . assertFalse ( hasattr ( result1 , '<STR_LIT:name>' ) ) <EOL> self . assertFalse ( hasattr ( result1 , '<STR_LIT:description>' ) ) <EOL> self . assertFalse ( hasattr ( result1 , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( result1 , '<STR_LIT>' ) ) <EOL> self . assertIsInstance ( result2 , pq . Quantity ) <EOL> self . assertFalse ( hasattr ( result2 , '<STR_LIT:name>' ) ) <EOL> self . assertFalse ( hasattr ( result2 , '<STR_LIT:description>' ) ) <EOL> self . assertFalse ( hasattr ( result2 , '<STR_LIT>' ) ) <EOL> self . assertFalse ( hasattr ( result2 , '<STR_LIT>' ) ) <EOL> self . assertEqual ( result1 , <NUM_LIT:0> * pq . nA ) <EOL> self . assertEqual ( result2 , <NUM_LIT:9> * pq . nA ) <EOL> def test__getitem_out_of_bounds_IndexError ( self ) : <EOL> self . assertRaises ( IndexError , self . signal1 . __getitem__ , <NUM_LIT:10> ) <EOL> def test_comparison_operators ( self ) : <EOL> assert_arrays_equal ( self . signal1 >= <NUM_LIT:5> * pq . nA , <EOL> np . array ( [ False , False , False , False , False , <EOL> True , True , True , True , True ] ) ) <EOL> assert_arrays_equal ( self . signal1 >= <NUM_LIT:5> * pq . pA , <EOL> np . array ( [ False , True , True , True , True , <EOL> True , True , True , True , True ] ) ) <EOL> def test__comparison_with_inconsistent_units_should_raise_Exception ( self ) : <EOL> self . assertRaises ( ValueError , self . signal1 . __gt__ , <NUM_LIT:5> * pq . mV ) <EOL> def test__simple_statistics ( self ) : <EOL> self . assertEqual ( self . signal1 . max ( ) , <NUM_LIT:9> * pq . nA ) <EOL> self . assertEqual ( self . signal1 . min ( ) , <NUM_LIT:0> * pq . nA ) <EOL> self . assertEqual ( self . signal1 . mean ( ) , <NUM_LIT> * pq . nA ) <EOL> def test__rescale_same ( self ) : <EOL> result = self . signal1 . copy ( ) <EOL> result = result . rescale ( pq . nA ) <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( result . units , <NUM_LIT:1> * pq . nA ) <EOL> assert_arrays_equal ( result , self . data1 ) <EOL> assert_same_sub_schema ( result , self . signal1 ) <EOL> def test__rescale_new ( self ) : <EOL> result = self . signal1 . copy ( ) <EOL> result = result . rescale ( pq . pA ) <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( result . units , <NUM_LIT:1> * pq . pA ) <EOL> assert_arrays_almost_equal ( np . array ( result ) , self . data1 * <NUM_LIT> , <NUM_LIT> ) <EOL> def test__rescale_new_incompatible_ValueError ( self ) : <EOL> self . assertRaises ( ValueError , self . signal1 . rescale , pq . mV ) <EOL> class TestAnalogSignalEquality ( unittest . TestCase ) : <EOL> def test__signals_with_different_data_complement_should_be_not_equal ( self ) : <EOL> signal1 = AnalogSignal ( np . arange ( <NUM_LIT> ) , units = "<STR_LIT>" , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz ) <EOL> signal2 = AnalogSignal ( np . arange ( <NUM_LIT> ) , units = "<STR_LIT>" , <EOL> sampling_rate = <NUM_LIT:2> * pq . kHz ) <EOL> assert_neo_object_is_compliant ( signal1 ) <EOL> assert_neo_object_is_compliant ( signal2 ) <EOL> self . assertNotEqual ( signal1 , signal2 ) <EOL> class TestAnalogSignalCombination ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . data1 = np . arange ( <NUM_LIT> ) <EOL> self . data1quant = self . data1 * pq . mV <EOL> self . signal1 = AnalogSignal ( self . data1quant , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz , <EOL> name = '<STR_LIT>' , description = '<STR_LIT>' , <EOL> file_origin = '<STR_LIT>' , <EOL> arg1 = '<STR_LIT:test>' ) <EOL> def test__compliant ( self ) : <EOL> assert_neo_object_is_compliant ( self . signal1 ) <EOL> self . assertEqual ( self . signal1 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( self . signal1 . description , '<STR_LIT>' ) <EOL> self . assertEqual ( self . signal1 . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( self . signal1 . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> def test__add_const_quantity_should_preserve_data_complement ( self ) : <EOL> result = self . signal1 + <NUM_LIT> * pq . V <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> assert_arrays_equal ( result , self . data1 + <NUM_LIT> ) <EOL> self . assertEqual ( self . signal1 [ <NUM_LIT:9> ] , <NUM_LIT:9> * pq . mV ) <EOL> self . assertEqual ( result [ <NUM_LIT:9> ] , <NUM_LIT> * pq . mV ) <EOL> self . assertEqual ( self . signal1 . t_start , result . t_start ) <EOL> self . assertEqual ( self . signal1 . sampling_rate , result . sampling_rate ) <EOL> def test__add_quantity_should_preserve_data_complement ( self ) : <EOL> data2 = np . arange ( <NUM_LIT> , <NUM_LIT> ) <EOL> data2quant = data2 * pq . mV <EOL> result = self . signal1 + data2quant <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> targ = AnalogSignal ( np . arange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , units = "<STR_LIT>" , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz , <EOL> name = '<STR_LIT>' , description = '<STR_LIT>' , <EOL> file_origin = '<STR_LIT>' , arg1 = '<STR_LIT:test>' ) <EOL> assert_neo_object_is_compliant ( targ ) <EOL> assert_arrays_equal ( result , targ ) <EOL> assert_same_sub_schema ( result , targ ) <EOL> def test__add_two_consistent_signals_should_preserve_data_complement ( self ) : <EOL> data2 = np . arange ( <NUM_LIT> , <NUM_LIT> ) <EOL> data2quant = data2 * pq . mV <EOL> signal2 = AnalogSignal ( data2quant , sampling_rate = <NUM_LIT:1> * pq . kHz ) <EOL> assert_neo_object_is_compliant ( signal2 ) <EOL> result = self . signal1 + signal2 <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> targ = AnalogSignal ( np . arange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , units = "<STR_LIT>" , <EOL> sampling_rate = <NUM_LIT:1> * pq . kHz , <EOL> name = '<STR_LIT>' , description = '<STR_LIT>' , <EOL> file_origin = '<STR_LIT>' , arg1 = '<STR_LIT:test>' ) <EOL> assert_neo_object_is_compliant ( targ ) <EOL> assert_arrays_equal ( result , targ ) <EOL> assert_same_sub_schema ( result , targ ) <EOL> def test__add_signals_with_inconsistent_data_complement_ValueError ( self ) : <EOL> self . signal1 . t_start = <NUM_LIT:0.0> * pq . ms <EOL> assert_neo_object_is_compliant ( self . signal1 ) <EOL> signal2 = AnalogSignal ( np . arange ( <NUM_LIT> ) , units = "<STR_LIT>" , <EOL> t_start = <NUM_LIT> * pq . ms , sampling_rate = <NUM_LIT:0.5> * pq . kHz ) <EOL> assert_neo_object_is_compliant ( signal2 ) <EOL> self . assertRaises ( ValueError , self . signal1 . __add__ , signal2 ) <EOL> def test__subtract_const_should_preserve_data_complement ( self ) : <EOL> result = self . signal1 - <NUM_LIT> * pq . mV <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( self . signal1 [ <NUM_LIT:9> ] , <NUM_LIT:9> * pq . mV ) <EOL> self . assertEqual ( result [ <NUM_LIT:9> ] , - <NUM_LIT> * pq . mV ) <EOL> assert_arrays_equal ( result , self . data1 - <NUM_LIT> ) <EOL> self . assertEqual ( self . signal1 . sampling_rate , result . sampling_rate ) <EOL> def test__subtract_from_const_should_return_signal ( self ) : <EOL> result = <NUM_LIT:10> * pq . mV - self . signal1 <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( self . signal1 [ <NUM_LIT:9> ] , <NUM_LIT:9> * pq . mV ) <EOL> self . assertEqual ( result [ <NUM_LIT:9> ] , <NUM_LIT:1> * pq . mV ) <EOL> assert_arrays_equal ( result , <NUM_LIT:10> - self . data1 ) <EOL> self . assertEqual ( self . signal1 . sampling_rate , result . sampling_rate ) <EOL> def test__mult_by_const_float_should_preserve_data_complement ( self ) : <EOL> result = self . signal1 * <NUM_LIT:2> <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( self . signal1 [ <NUM_LIT:9> ] , <NUM_LIT:9> * pq . mV ) <EOL> self . assertEqual ( result [ <NUM_LIT:9> ] , <NUM_LIT> * pq . mV ) <EOL> assert_arrays_equal ( result , self . data1 * <NUM_LIT:2> ) <EOL> self . assertEqual ( self . signal1 . sampling_rate , result . sampling_rate ) <EOL> def test__divide_by_const_should_preserve_data_complement ( self ) : <EOL> result = self . signal1 / <NUM_LIT:0.5> <EOL> self . assertIsInstance ( result , AnalogSignal ) <EOL> assert_neo_object_is_compliant ( result ) <EOL> self . assertEqual ( result . name , '<STR_LIT>' ) <EOL> self . assertEqual ( result . description , '<STR_LIT>' ) <EOL> self . assertEqual ( result . file_origin , '<STR_LIT>' ) <EOL> self . assertEqual ( result . annotations , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> self . assertEqual ( self . signal1 [ <NUM_LIT:9> ] , <NUM_LIT:9> * pq . mV ) <EOL> self . assertEqual ( result [ <NUM_LIT:9> ] , <NUM_LIT> * pq . mV ) <EOL> assert_arrays_equal ( result , self . data1 / <NUM_LIT:0.5> ) <EOL> self . assertEqual ( self . signal1 . sampling_rate , result . sampling_rate ) <EOL> def test__merge_NotImplementedError ( self ) : <EOL> self . assertRaises ( NotImplementedError , <EOL> self . signal1 . merge , self . signal1 ) <EOL> class TestAnalogSignalFunctions ( unittest . TestCase ) : <EOL> def test__pickle ( self ) : <EOL> signal1 = AnalogSignal ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , sampling_period = <NUM_LIT:1> * pq . ms , <EOL> units = pq . S , channel_index = <NUM_LIT> ) <EOL> signal1 . annotations [ '<STR_LIT:index>' ] = <NUM_LIT:2> <EOL> fobj = open ( '<STR_LIT>' , '<STR_LIT:wb>' ) <EOL> pickle . dump ( signal1 , fobj ) <EOL> fobj . close ( ) <EOL> fobj = open ( '<STR_LIT>' , '<STR_LIT:rb>' ) <EOL> try : <EOL> signal2 = pickle . load ( fobj ) <EOL> except ValueError : <EOL> signal2 = None <EOL> assert_arrays_equal ( signal1 , signal2 ) <EOL> self . assertEqual ( signal1 . channel_index , signal2 . channel_index , <NUM_LIT> ) <EOL> fobj . close ( ) <EOL> os . remove ( '<STR_LIT>' ) <EOL> class TestAnalogSignalSampling ( unittest . TestCase ) : <EOL> def test___get_sampling_rate__period_none_rate_none_ValueError ( self ) : <EOL> sampling_rate = None <EOL> sampling_period = None <EOL> self . assertRaises ( ValueError , _get_sampling_rate , <EOL> sampling_rate , sampling_period ) <EOL> def test___get_sampling_rate__period_quant_rate_none ( self ) : <EOL> sampling_rate = None <EOL> sampling_period = pq . Quantity ( <NUM_LIT> , units = pq . s ) <EOL> targ_rate = <NUM_LIT:1> / sampling_period <EOL> out_rate = _get_sampling_rate ( sampling_rate , sampling_period ) <EOL> self . assertEqual ( targ_rate , out_rate ) <EOL> def test___get_sampling_rate__period_none_rate_quant ( self ) : <EOL> sampling_rate = pq . Quantity ( <NUM_LIT> , units = pq . Hz ) <EOL> sampling_period = None <EOL> targ_rate = sampling_rate <EOL> out_rate = _get_sampling_rate ( sampling_rate , sampling_period ) <EOL> self . assertEqual ( targ_rate , out_rate ) <EOL> def test___get_sampling_rate__period_rate_equivalent ( self ) : <EOL> sampling_rate = pq . Quantity ( <NUM_LIT> , units = pq . Hz ) <EOL> sampling_period = pq . Quantity ( <NUM_LIT:0.1> , units = pq . s ) <EOL> targ_rate = sampling_rate <EOL> out_rate = _get_sampling_rate ( sampling_rate , sampling_period ) <EOL> self . assertEqual ( targ_rate , out_rate ) <EOL> def test___get_sampling_rate__period_rate_not_equivalent_ValueError ( self ) : <EOL> sampling_rate = pq . Quantity ( <NUM_LIT> , units = pq . Hz ) <EOL> sampling_period = pq . Quantity ( <NUM_LIT:10> , units = pq . s ) <EOL> self . assertRaises ( ValueError , _get_sampling_rate , <EOL> sampling_rate , sampling_period ) <EOL> def test___get_sampling_rate__period_none_rate_float_TypeError ( self ) : <EOL> sampling_rate = <NUM_LIT> <EOL> sampling_period = None <EOL> self . assertRaises ( TypeError , _get_sampling_rate , <EOL> sampling_rate , sampling_period ) <EOL> def test___get_sampling_rate__period_array_rate_none_TypeError ( self ) : <EOL> sampling_rate = None <EOL> sampling_period = np . array ( <NUM_LIT> ) <EOL> self . assertRaises ( TypeError , _get_sampling_rate , <EOL> sampling_rate , sampling_period ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
