コード例 #1
0
ファイル: test_event.py プロジェクト: wvangeit/python-neo
    def test_slice(self):
        params = {'test2': 'y1', 'test3': True}
        arr_ann = {'index': np.arange(10), 'test': np.arange(100, 110)}
        evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.0, 3.1, 3.3] * pq.ms,
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    test1=1,
                    array_annotations=arr_ann,
                    **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        targ = Event([2.2, 2.9, 3.0] * pq.ms)
        result = evt[5:8]

        assert_arrays_equal(targ, result)
        self.assertEqual(evt.name, result.name)
        self.assertEqual(evt.description, result.description)
        self.assertEqual(evt.file_origin, result.file_origin)
        self.assertEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertEqual(evt.annotations['test2'], result.annotations['test2'])
        assert_arrays_equal(result.array_annotations['index'], np.arange(5, 8))
        assert_arrays_equal(result.array_annotations['test'],
                            np.arange(105, 108))
        self.assertIsInstance(result.array_annotations, ArrayDict)
コード例 #2
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
    def test_time_slice_differnt_units(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.1, 3.3] * pq.ms,
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    test1=1,
                    **params)
        assert_neo_object_is_compliant(evt)
        evt.annotate(test1=1.1, test0=[1, 2])

        targ = Event([2.2, 2.9] * pq.ms,
                     name='test',
                     description='tester',
                     file_origin='test.file',
                     test1=1,
                     **params)
        assert_neo_object_is_compliant(targ)
        targ.annotate(test1=1.1, test0=[1, 2])

        t_start = 0.002 * pq.s
        t_stop = 0.003 * pq.s

        result = evt.time_slice(t_start, t_stop)

        assert_arrays_equal(targ, result)
        self.assertEqual(targ.name, result.name)
        self.assertEqual(targ.description, result.description)
        self.assertEqual(targ.file_origin, result.file_origin)
        self.assertEqual(targ.annotations['test0'],
                         result.annotations['test0'])
        self.assertEqual(targ.annotations['test1'],
                         result.annotations['test1'])
        self.assertEqual(targ.annotations['test2'],
                         result.annotations['test2'])
コード例 #3
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def test_time_slice_differnt_units(self):
        params = {'test2': 'y1', 'test3': True}
        arr_ann = {'index': np.arange(9), 'test': np.arange(100, 109)}
        evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.1, 3.3] * pq.ms, name='test',
                    description='tester', file_origin='test.file', test1=1,
                    array_annotations=arr_ann, **params)
        assert_neo_object_is_compliant(evt)
        evt.annotate(test1=1.1, test0=[1, 2])

        targ = Event([2.2, 2.9] * pq.ms, name='test', description='tester',
                     file_origin='test.file', test1=1, **params)
        assert_neo_object_is_compliant(targ)
        targ.annotate(test1=1.1, test0=[1, 2])

        t_start = 0.002 * pq.s
        t_stop = 0.003 * pq.s

        result = evt.time_slice(t_start, t_stop)

        assert_arrays_equal(targ, result)
        self.assertEqual(targ.name, result.name)
        self.assertEqual(targ.description, result.description)
        self.assertEqual(targ.file_origin, result.file_origin)
        self.assertEqual(targ.annotations['test0'], result.annotations['test0'])
        self.assertEqual(targ.annotations['test1'], result.annotations['test1'])
        self.assertEqual(targ.annotations['test2'], result.annotations['test2'])
        assert_arrays_equal(result.array_annotations['index'], np.arange(5, 7))
        assert_arrays_equal(result.array_annotations['test'], np.arange(105, 107))
        self.assertIsInstance(result.array_annotations, ArrayDict)
コード例 #4
0
ファイル: test_event.py プロジェクト: testvidya11/python-neo
 def test_epoch_merge_NotImplementedError(self):
     evt1 = Event(1.5 * pq.ms,
                  label='test epoch',
                  name='test',
                  description='tester',
                  file_origin='test.file',
                  testarg1=1)
     evt2 = Event(1.5 * pq.ms,
                  label='test epoch',
                  name='test',
                  description='tester',
                  file_origin='test.file',
                  testarg1=1)
     self.assertRaises(NotImplementedError, evt1.merge, evt2)
コード例 #5
0
ファイル: test_event.py プロジェクト: wvangeit/python-neo
    def test_to_epoch(self):
        seg = Segment(name="test")
        event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]),
                      units="ms",
                      labels=np.array(["A", "B", "C", "D"]))
        event.segment = seg

        # Mode 1
        epoch = event.to_epoch()
        self.assertIsInstance(epoch, Epoch)
        assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0]))
        assert_array_equal(epoch.durations.magnitude,
                           np.array([7.0, 11.0, 22.0]))
        assert_array_equal(epoch.labels, np.array(['A-B', 'B-C', 'C-D']))

        # Mode 2
        epoch = event.to_epoch(pairwise=True)
        assert_array_equal(epoch.times.magnitude, np.array([5.0, 23.0]))
        assert_array_equal(epoch.durations.magnitude, np.array([7.0, 22.0]))
        assert_array_equal(epoch.labels, np.array(['A-B', 'C-D']))

        # Mode 3 (scalar)
        epoch = event.to_epoch(durations=2.0 * pq.ms)
        assert_array_equal(epoch.times.magnitude,
                           np.array([5.0, 12.0, 23.0, 45.0]))
        assert_array_equal(epoch.durations.magnitude,
                           np.array([2.0, 2.0, 2.0, 2.0]))
        self.assertEqual(epoch.durations.size, 4)
        assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D']))

        # Mode 3 (array)
        epoch = event.to_epoch(durations=np.array([2.0, 3.0, 4.0, 5.0]) *
                               pq.ms)
        assert_array_equal(epoch.times.magnitude,
                           np.array([5.0, 12.0, 23.0, 45.0]))
        assert_array_equal(epoch.durations.magnitude,
                           np.array([2.0, 3.0, 4.0, 5.0]))
        assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D']))

        # Error conditions
        self.assertRaises(ValueError,
                          event.to_epoch,
                          pairwise=True,
                          durations=2.0 * pq.ms)

        odd_event = Event(times=np.array([5.0, 12.0, 23.0]),
                          units="ms",
                          labels=np.array(["A", "B", "C"]))
        self.assertRaises(ValueError, odd_event.to_epoch, pairwise=True)
コード例 #6
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
 def test_set_labels(self):
     evt = Event([1.1, 1.5, 1.7] * pq.ms,
                 labels=['A', 'B', 'C'])
     assert_array_equal(evt.labels, np.array(['A', 'B', 'C']))
     evt.labels = ['D', 'E', 'F']
     assert_array_equal(evt.labels, np.array(['D', 'E', 'F']))
     self.assertRaises(ValueError, setattr, evt, "labels", ['X', 'Y'])
コード例 #7
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
    def test_Event_creation(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([1.1, 1.5, 1.7] * pq.ms,
                    labels=np.array(
                        ['test event 1', 'test event 2', 'test event 3'],
                        dtype='S'),
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    test1=1,
                    **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        assert_arrays_equal(evt.times, [1.1, 1.5, 1.7] * pq.ms)
        assert_arrays_equal(
            evt.labels,
            np.array(['test event 1', 'test event 2', 'test event 3'],
                     dtype='S'))
        self.assertEqual(evt.name, 'test')
        self.assertEqual(evt.description, 'tester')
        self.assertEqual(evt.file_origin, 'test.file')
        self.assertEqual(evt.annotations['test0'], [1, 2])
        self.assertEqual(evt.annotations['test1'], 1.1)
        self.assertEqual(evt.annotations['test2'], 'y1')
        self.assertTrue(evt.annotations['test3'])
コード例 #8
0
ファイル: test_event.py プロジェクト: wvangeit/python-neo
    def test_Event_creation(self):
        params = {'test2': 'y1', 'test3': True}
        arr_ann = {'names': ['a', 'b', 'c'], 'index': np.arange(10, 13)}
        evt = Event([1.1, 1.5, 1.7] * pq.ms,
                    labels=np.array(
                        ['test event 1', 'test event 2', 'test event 3'],
                        dtype='S'),
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    test1=1,
                    array_annotations=arr_ann,
                    **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        assert_arrays_equal(evt.times, [1.1, 1.5, 1.7] * pq.ms)
        assert_arrays_equal(
            evt.labels,
            np.array(['test event 1', 'test event 2', 'test event 3'],
                     dtype='S'))
        self.assertEqual(evt.name, 'test')
        self.assertEqual(evt.description, 'tester')
        self.assertEqual(evt.file_origin, 'test.file')
        self.assertEqual(evt.annotations['test0'], [1, 2])
        self.assertEqual(evt.annotations['test1'], 1.1)
        self.assertEqual(evt.annotations['test2'], 'y1')
        self.assertTrue(evt.annotations['test3'])
        assert_arrays_equal(evt.array_annotations['names'],
                            np.array(['a', 'b', 'c']))
        assert_arrays_equal(evt.array_annotations['index'], np.arange(10, 13))
        self.assertIsInstance(evt.array_annotations, ArrayDict)
コード例 #9
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
 def test_Event_creation_from_lists(self):
     evt = Event([1.1, 1.5, 1.7],
                 ['test event 1', 'test event 2', 'test event 3'],
                 units=pq.ms)
     assert_arrays_equal(evt.times, [1.1, 1.5, 1.7] * pq.ms)
     assert_arrays_equal(evt.labels,
                         np.array(['test event 1', 'test event 2', 'test event 3']))
コード例 #10
0
ファイル: test_event.py プロジェクト: wvangeit/python-neo
    def test__pickle(self):
        arr_ann = {'index': np.arange(3), 'test': ['a', 'b', 'c']}
        event1 = Event(np.arange(0, 30, 10) * pq.s,
                       labels=np.array(['t0', 't1', 't2'], dtype='S'),
                       units='s',
                       annotation1="foo",
                       annotation2="bar",
                       array_annotations=arr_ann)
        fobj = open('./pickle', 'wb')
        pickle.dump(event1, fobj)
        fobj.close()

        fobj = open('./pickle', 'rb')
        try:
            event2 = pickle.load(fobj)
        except ValueError:
            event2 = None

        fobj.close()
        assert_array_equal(event1.times, event2.times)
        assert_arrays_equal(event2.array_annotations['index'],
                            np.array(arr_ann['index']))
        assert_arrays_equal(event2.array_annotations['test'],
                            np.array(arr_ann['test']))
        self.assertIsInstance(event2.array_annotations, ArrayDict)
        # Make sure the dict can perform correct checks after unpickling
        event2.array_annotations['anno3'] = list(range(3, 6))
        with self.assertRaises(ValueError):
            event2.array_annotations['anno4'] = [2, 1]
        os.remove('./pickle')
        self.assertEqual(event2.annotations, event1.annotations)
コード例 #11
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
    def test__children(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([1.1, 1.5, 1.7] * pq.ms,
                    labels=np.array(
                        ['test event 1', 'test event 2', 'test event 3'],
                        dtype='S'),
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    test1=1,
                    **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        segment = Segment(name='seg1')
        segment.events = [evt]
        segment.create_many_to_one_relationship()

        self.assertEqual(evt._single_parent_objects, ('Segment', ))
        self.assertEqual(evt._multi_parent_objects, ())

        self.assertEqual(evt._single_parent_containers, ('segment', ))
        self.assertEqual(evt._multi_parent_containers, ())

        self.assertEqual(evt._parent_objects, ('Segment', ))
        self.assertEqual(evt._parent_containers, ('segment', ))

        self.assertEqual(len(evt.parents), 1)
        self.assertEqual(evt.parents[0].name, 'seg1')

        assert_neo_object_is_compliant(evt)
コード例 #12
0
 def setUp(self):
     self.params = {'test2': 'y1', 'test3': True}
     self.arr_ann = {'index': np.arange(10), 'test': np.arange(100, 110)}
     self.evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.0, 3.1, 3.3] * pq.ms, name='test',
                 description='tester', file_origin='test.file', test1=1,
                 array_annotations=self.arr_ann, **self.params)
     self.evt.annotate(test1=1.1, test0=[1, 2])
コード例 #13
0
 def setUp(self):
     self.data = np.array([0.1, 0.5, 1.2, 3.3, 6.4, 7])
     self.dataquant = self.data * pq.ms
     self.arr_ann = {
         'index': np.arange(6),
         'test': ['a', 'b', 'c', 'd', 'e', 'f']
     }
     self.event = Event(self.dataquant, array_annotations=self.arr_ann)
コード例 #14
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def test_Event_merge(self):
        warnings.simplefilter("always")
        params1 = {'test2': 'y1', 'test3': True}
        params2 = {'test2': 'no', 'test4': False}
        paramstarg = {'test2': 'yes;no', 'test3': True, 'test4': False}
        arr_ann1 = {'index': np.arange(10, 13)}
        arr_ann2 = {'index': np.arange(3), 'test': ['a', 'b', 'c']}
        evt1 = Event([1.1, 1.5, 1.7] * pq.ms,
                     labels=np.array(['test event 1 1', 'test event 1 2', 'test event 1 3'],
                                     dtype='S'), name='test', description='tester 1',
                     file_origin='test.file', array_annotations=arr_ann1, test1=1, **params1)
        evt2 = Event([2.1, 2.5, 2.7] * pq.us,
                     labels=np.array(['test event 2 1', 'test event 2 2', 'test event 2 3'],
                                     dtype='S'), name='test', description='tester 2',
                     file_origin='test.file', array_annotations=arr_ann2, test1=1, **params2)
        evttarg = Event([1.1, 1.5, 1.7, .0021, .0025, .0027] * pq.ms,
                        labels=np.array(['test event 1 1', 'test event 1 2', 'test event 1 3',
                                         'test event 2 1', 'test event 2 2', 'test event 2 3'],
                                        dtype='S'),
                        name='test',
                        description='merge(tester 1, tester 2)', file_origin='test.file',
                        array_annotations={'index': [10, 11, 12, 0, 1, 2]}, test1=1, **paramstarg)
        assert_neo_object_is_compliant(evt1)
        assert_neo_object_is_compliant(evt2)
        assert_neo_object_is_compliant(evttarg)

        with warnings.catch_warnings(record=True) as w:
            evtres = evt1.merge(evt2)

            self.assertEqual(len(w), 1)
            self.assertEqual(w[0].category, UserWarning)
            self.assertSequenceEqual(str(w[0].message), "The following array annotations were "
                                                        "omitted, because they were only present"
                                                        " in one of the merged objects: "
                                                        "[] from the one that was merged "
                                                        "into and ['test'] from the one that "
                                                        "was merged into the other")

        assert_neo_object_is_compliant(evtres)
        assert_same_sub_schema(evttarg, evtres)
        # Remove this, when array_annotations are added to assert_same_sub_schema
        assert_arrays_equal(evtres.array_annotations['index'], np.array([10, 11, 12, 0, 1, 2]))
        self.assertTrue('test' not in evtres.array_annotations)
        self.assertIsInstance(evtres.array_annotations, ArrayDict)
コード例 #15
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
    def test_Event_merge(self):
        params1 = {'test2': 'y1', 'test3': True}
        params2 = {'test2': 'no', 'test4': False}
        paramstarg = {'test2': 'yes;no', 'test3': True, 'test4': False}
        evt1 = Event(
            [1.1, 1.5, 1.7] * pq.ms,
            labels=np.array(
                ['test event 1 1', 'test event 1 2', 'test event 1 3'],
                dtype='S'),
            name='test',
            description='tester 1',
            file_origin='test.file',
            test1=1,
            **params1)
        evt2 = Event(
            [2.1, 2.5, 2.7] * pq.us,
            labels=np.array(
                ['test event 2 1', 'test event 2 2', 'test event 2 3'],
                dtype='S'),
            name='test',
            description='tester 2',
            file_origin='test.file',
            test1=1,
            **params2)
        evttarg = Event(
            [1.1, 1.5, 1.7, .0021, .0025, .0027] * pq.ms,
            labels=np.array([
                'test event 1 1', 'test event 1 2', 'test event 1 3',
                'test event 2 1', 'test event 2 2', 'test event 2 3'
            ],
                            dtype='S'),
            name='test',
            description='merge(tester 1, tester 2)',
            file_origin='test.file',
            test1=1,
            **paramstarg)
        assert_neo_object_is_compliant(evt1)
        assert_neo_object_is_compliant(evt2)
        assert_neo_object_is_compliant(evttarg)

        evtres = evt1.merge(evt2)
        assert_neo_object_is_compliant(evtres)
        assert_same_sub_schema(evttarg, evtres)
コード例 #16
0
    def tests_time_slice(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.0, 3.1, 3.3] * pq.ms,
                    name='test', description='tester',
                    file_origin='test.file',
                    test1=1, **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        targ = Event([2.2, 2.9, 3.0] * pq.ms)
        result = evt.time_slice(t_start=2.0, t_stop=3.0)

        assert_arrays_equal(targ, result)
        self.assertEqual(evt.name, result.name)
        self.assertEqual(evt.description, result.description)
        self.assertEqual(evt.file_origin, result.file_origin)
        self.assertEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertEqual(evt.annotations['test2'], result.annotations['test2'])
コード例 #17
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def test__pretty(self):
        evt = Event([1.1, 1.5, 1.7] * pq.ms,
                    labels=np.array(['test event 1', 'test event 2', 'test event 3'], dtype='S'),
                    name='test', description='tester', file_origin='test.file')
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        prepr = pretty(evt)
        targ = ("Event\nname: '%s'\ndescription: '%s'\nannotations: %s"
                "" % (evt.name, evt.description, pretty(evt.annotations)))

        self.assertEqual(prepr, targ)
コード例 #18
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def tests_time_slice_deepcopy_annotations(self):
        params = {'test0': 'y1', 'test1': ['deeptest'], 'test2': True}
        evt = Event([0.1, 0.5, 1.1, 1.5, 1.7, 2.2, 2.9, 3.0, 3.1, 3.3] * pq.ms,
                    name='test', description='tester',
                    file_origin='test.file', **params)
        result = evt.time_slice(t_start=2.0, t_stop=3.0)
        evt.annotate(test0='y2', test2=False)
        evt.annotations['test1'][0] = 'shallowtest'

        self.assertNotEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertNotEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertNotEqual(evt.annotations['test2'], result.annotations['test2'])
コード例 #19
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def test_Event_repr(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([1.1, 1.5, 1.7] * pq.ms,
                    labels=np.array(['test event 1', 'test event 2', 'test event 3'], dtype='S'),
                    name='test', description='tester', file_origin='test.file', test1=1, **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        assert_neo_object_is_compliant(evt)

        targ = ('<Event: test event [email protected] ms, test event [email protected] ms, ' + 'test event [email protected] ms>')

        res = repr(evt)

        self.assertEqual(targ, res)
コード例 #20
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
    def test__time_slice(self):
        data = [2, 3, 4, 5] * pq.ms
        evt = Event(data, foo='bar')

        evt1 = evt.time_slice(2.2 * pq.ms, 4.2 * pq.ms)
        assert_arrays_equal(evt1.times, [3, 4] * pq.ms)
        self.assertEqual(evt.annotations, evt1.annotations)

        evt2 = evt.time_slice(None, 4.2 * pq.ms)
        assert_arrays_equal(evt2.times, [2, 3, 4] * pq.ms)

        evt3 = evt.time_slice(2.2 * pq.ms, None)
        assert_arrays_equal(evt3.times, [3, 4, 5] * pq.ms)
コード例 #21
0
ファイル: test_event.py プロジェクト: xiki-tempula/python-neo
    def test__pretty(self):
        evt = Event(1.5 * pq.ms,
                    label='test epoch',
                    name='test',
                    description='tester',
                    file_origin='test.file')
        evt.annotate(targ1=1.1, targ0=[1])
        assert_neo_object_is_compliant(evt)

        prepr = pretty(evt)
        targ = ("Event\nname: '%s'\ndescription: '%s'\nannotations: %s" %
                (evt.name, evt.description, pretty(evt.annotations)))

        self.assertEqual(prepr, targ)
コード例 #22
0
 def test_event_to_epoch(self):
     seg = Segment(name="test")
     # event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms", labels=np.array(["A", "B", "C", "D"]))
     event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]),
                   units="ms",
                   labels=np.array(["A", "B", "C", "D"]))
     print("event : " + str(event))
     event.segment = seg
     epoch = event.to_epoch()
     print("epoch.magnitude : " + str(epoch.durations.magnitude))
     print("np.array([7.0, 11.0, 22.0]) : " +
           str(np.array([7.0, 11.0, 22.0])))
     assert_array_equal(epoch.durations.magnitude,
                        np.array([7.0, 11.0, 22.0]))
     self.assertEqual(str(type(epoch).__name__), 'Epoch')
     pass
コード例 #23
0
    def test__pickle(self):

        event1 = Event(np.arange(0, 30, 10)*pq.s, labels=np.array(['t0', 't1', 't2'], dtype='S'),
                       units='s')
        fobj = open('./pickle', 'wb')
        pickle.dump(event1, fobj)
        fobj.close()

        fobj = open('./pickle', 'rb')
        try:
            event2 = pickle.load(fobj)
        except ValueError:
            event2 = None

        fobj.close()
        assert_array_equal(event1.times, event2.times)
        os.remove('./pickle')
コード例 #24
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def tests_time_slice(self):

        evt = self.evt

        targ = Event([2.2, 2.9, 3.0] * pq.ms)
        result = evt.time_slice(t_start=2.0, t_stop=3.0)

        assert_arrays_equal(targ, result)
        self.assertEqual(evt.name, result.name)
        self.assertEqual(evt.description, result.description)
        self.assertEqual(evt.file_origin, result.file_origin)
        self.assertEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertEqual(evt.annotations['test2'], result.annotations['test2'])
        assert_arrays_equal(result.array_annotations['index'], np.arange(5, 8))
        assert_arrays_equal(result.array_annotations['test'], np.arange(105, 108))
        self.assertIsInstance(result.array_annotations, ArrayDict)
コード例 #25
0
    def test_time_slice_empty(self):
        params = {'test2': 'y1', 'test3': True}
        evt = Event([] * pq.ms,
                    name='test', description='tester',
                    file_origin='test.file',
                    test1=1, **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        result = evt.time_slice(t_start=0.0001, t_stop=30.0)
        assert_neo_object_is_compliant(evt)

        assert_arrays_equal(evt, result)
        self.assertEqual(evt.name, result.name)
        self.assertEqual(evt.description, result.description)
        self.assertEqual(evt.file_origin, result.file_origin)
        self.assertEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertEqual(evt.annotations['test2'], result.annotations['test2'])
コード例 #26
0
ファイル: test_event.py プロジェクト: testvidya11/python-neo
    def test__children(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        evt = Event(1.5 * pq.ms,
                    label='test epoch',
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    testarg1=1,
                    **params)
        evt.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        assert_neo_object_is_compliant(evt)

        segment = Segment(name='seg1')
        segment.events = [evt]
        segment.create_many_to_one_relationship()

        self.assertEqual(evt._container_child_objects, ())
        self.assertEqual(evt._data_child_objects, ())
        self.assertEqual(evt._single_parent_objects, ('Segment', ))
        self.assertEqual(evt._multi_child_objects, ())
        self.assertEqual(evt._multi_parent_objects, ())
        self.assertEqual(evt._child_properties, ())

        self.assertEqual(evt._single_child_objects, ())

        self.assertEqual(evt._container_child_containers, ())
        self.assertEqual(evt._data_child_containers, ())
        self.assertEqual(evt._single_child_containers, ())
        self.assertEqual(evt._single_parent_containers, ('segment', ))
        self.assertEqual(evt._multi_child_containers, ())
        self.assertEqual(evt._multi_parent_containers, ())

        self.assertEqual(evt._child_objects, ())
        self.assertEqual(evt._child_containers, ())
        self.assertEqual(evt._parent_objects, ('Segment', ))
        self.assertEqual(evt._parent_containers, ('segment', ))

        self.assertEqual(evt.children, ())
        self.assertEqual(len(evt.parents), 1)
        self.assertEqual(evt.parents[0].name, 'seg1')

        evt.create_many_to_one_relationship()
        evt.create_many_to_many_relationship()
        evt.create_relationship()
        assert_neo_object_is_compliant(evt)
コード例 #27
0
ファイル: test_event.py プロジェクト: rishidhingra/python-neo
    def test_time_slice_empty(self):
        params = {'test2': 'y1', 'test3': True}
        arr_ann = {'index': np.array([]), 'test': np.array([])}
        evt = Event([] * pq.ms, name='test', description='tester', file_origin='test.file',
                    test1=1, array_annotations=arr_ann, **params)
        evt.annotate(test1=1.1, test0=[1, 2])
        result = evt.time_slice(t_start=0.0001, t_stop=30.0)
        assert_neo_object_is_compliant(evt)

        assert_arrays_equal(evt, result)
        self.assertEqual(evt.name, result.name)
        self.assertEqual(evt.description, result.description)
        self.assertEqual(evt.file_origin, result.file_origin)
        self.assertEqual(evt.annotations['test0'], result.annotations['test0'])
        self.assertEqual(evt.annotations['test1'], result.annotations['test1'])
        self.assertEqual(evt.annotations['test2'], result.annotations['test2'])
        assert_arrays_equal(result.array_annotations['index'], np.asarray([]))
        assert_arrays_equal(result.array_annotations['test'], np.asarray([]))
        self.assertIsInstance(result.array_annotations, ArrayDict)
コード例 #28
0
    def test_rescale(self):
        times = [2, 3, 4, 5]
        labels = ["A", "B", "C", "D"]
        arr_ann = {'index': np.arange(4), 'test': ['a', 'b', 'c', 'd']}
        evt = Event(times * pq.ms, labels=labels, array_annotations=arr_ann)
        result = evt.rescale(pq.us)

        self.assertIsInstance(result, Event)
        assert_neo_object_is_compliant(result)
        assert_arrays_equal(result.array_annotations['index'], np.arange(4))
        assert_arrays_equal(result.array_annotations['test'],
                            np.array(['a', 'b', 'c', 'd']))
        self.assertIsInstance(result.array_annotations, ArrayDict)

        self.assertEqual(result.units, 1 * pq.us)
        assert_array_equal(evt.labels, result.labels)
        assert_arrays_almost_equal(result.times,
                                   [2000, 3000, 4000, 5000] * pq.us, 1e-9)
        assert_arrays_almost_equal(result.times.magnitude,
                                   np.array([2000, 3000, 4000, 5000]), 1e-9)
コード例 #29
0
ファイル: test_event.py プロジェクト: testvidya11/python-neo
    def test_Event_creation(self):
        params = {'testarg2': 'yes', 'testarg3': True}
        evt = Event(1.5 * pq.ms,
                    label='test epoch',
                    name='test',
                    description='tester',
                    file_origin='test.file',
                    testarg1=1,
                    **params)
        evt.annotate(testarg1=1.1, testarg0=[1, 2, 3])
        assert_neo_object_is_compliant(evt)

        self.assertEqual(evt.time, 1.5 * pq.ms)
        self.assertEqual(evt.label, 'test epoch')
        self.assertEqual(evt.name, 'test')
        self.assertEqual(evt.description, 'tester')
        self.assertEqual(evt.file_origin, 'test.file')
        self.assertEqual(evt.annotations['testarg0'], [1, 2, 3])
        self.assertEqual(evt.annotations['testarg1'], 1.1)
        self.assertEqual(evt.annotations['testarg2'], 'yes')
        self.assertTrue(evt.annotations['testarg3'])
コード例 #30
0
ファイル: test_event.py プロジェクト: csmarc/python-neo
 def setUp(self):
     self.data = np.array([0.1, 0.5, 1.2, 3.3, 6.4, 7])
     self.dataquant = self.data * pq.ms
     self.event = Event(self.dataquant)