Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)