当前位置: 首页>>代码示例>>Python>>正文


Python BaseNeo.merge_annotations方法代码示例

本文整理汇总了Python中neo.core.baseneo.BaseNeo.merge_annotations方法的典型用法代码示例。如果您正苦于以下问题:Python BaseNeo.merge_annotations方法的具体用法?Python BaseNeo.merge_annotations怎么用?Python BaseNeo.merge_annotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neo.core.baseneo.BaseNeo的用法示例。


在下文中一共展示了BaseNeo.merge_annotations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Test_BaseNeo_merge_annotations_merge

# 需要导入模块: from neo.core.baseneo import BaseNeo [as 别名]
# 或者: from neo.core.baseneo.BaseNeo import merge_annotations [as 别名]
class Test_BaseNeo_merge_annotations_merge(unittest.TestCase):
    '''
    TestCase to make sure merge_annotations and merge methods work
    '''
    def setUp(self):
        self.name1 = 'a base 1'
        self.name2 = 'a base 2'
        self.description1 = 'this is a test 1'
        self.description2 = 'this is a test 2'
        self.base1 = BaseNeo(name=self.name1, description=self.description1)
        self.base2 = BaseNeo(name=self.name2, description=self.description2)

    def test_merge_annotations__dict(self):
        self.base1.annotations = {'val0': 'val0', 'val1': 1,
                                  'val2': 2.2, 'val3': 'test1',
                                  'val4': [.4], 'val5': {0: 0, 1: {0: 0}},
                                  'val6': np.array([0, 1, 2])}
        self.base2.annotations = {'val2': 2.2, 'val3': 'test2',
                                  'val4': [4, 4.4], 'val5': {1: {1: 1}, 2: 2},
                                  'val6': np.array([4, 5, 6]), 'val7': True}

        ann1 = self.base1.annotations
        ann2 = self.base2.annotations
        ann1c = self.base1.annotations.copy()
        ann2c = self.base2.annotations.copy()

        targ = {'val0': 'val0', 'val1': 1, 'val2': 2.2, 'val3': 'test1;test2',
                'val4': [.4, 4, 4.4], 'val5': {0: 0, 1: {0: 0, 1: 1}, 2: 2},
                'val7': True}

        self.base1.merge_annotations(self.base2)

        val6t = np.array([0, 1, 2, 4, 5, 6])
        val61 = ann1.pop('val6')
        val61c = ann1c.pop('val6')
        val62 = ann2.pop('val6')
        val62c = ann2c.pop('val6')

        self.assertEqual(ann1, self.base1.annotations)
        self.assertNotEqual(ann1c, self.base1.annotations)
        self.assertEqual(ann2c, self.base2.annotations)
        self.assertEqual(targ, self.base1.annotations)

        assert_arrays_equal(val61, val6t)
        self.assertRaises(AssertionError, assert_arrays_equal, val61c, val6t)
        assert_arrays_equal(val62, val62c)

        self.assertEqual(self.name1, self.base1.name)
        self.assertEqual(self.name2, self.base2.name)
        self.assertEqual(self.description1, self.base1.description)
        self.assertEqual(self.description2, self.base2.description)

    def test_merge_annotations__func__dict(self):
        ann1 = {'val0': 'val0', 'val1': 1, 'val2': 2.2, 'val3': 'test1',
                'val4': [.4], 'val5': {0: 0, 1: {0: 0}},
                'val6': np.array([0, 1, 2])}
        ann2 = {'val2': 2.2, 'val3': 'test2',
                'val4': [4, 4.4], 'val5': {1: {1: 1}, 2: 2},
                'val6': np.array([4, 5, 6]), 'val7': True}

        ann1c = ann1.copy()
        ann2c = ann2.copy()

        targ = {'val0': 'val0', 'val1': 1, 'val2': 2.2, 'val3': 'test1;test2',
                'val4': [.4, 4, 4.4], 'val5': {0: 0, 1: {0: 0, 1: 1}, 2: 2},
                'val7': True}

        res = merge_annotations(ann1, ann2)

        val6t = np.array([0, 1, 2, 4, 5, 6])
        val6r = res.pop('val6')
        val61 = ann1.pop('val6')
        val61c = ann1c.pop('val6')
        val62 = ann2.pop('val6')
        val62c = ann2c.pop('val6')

        self.assertEqual(ann1, ann1c)
        self.assertEqual(ann2, ann2c)
        self.assertEqual(res, targ)

        assert_arrays_equal(val6r, val6t)
        self.assertRaises(AssertionError, assert_arrays_equal, val61, val6t)
        assert_arrays_equal(val61, val61c)
        assert_arrays_equal(val62, val62c)

    def test_merge_annotation__func__str(self):
        ann1 = 'test1'
        ann2 = 'test2'

        targ = 'test1;test2'

        res = merge_annotation(ann1, ann2)

        self.assertEqual(res, targ)

    def test_merge_annotation__func__ndarray(self):
        ann1 = np.array([0, 1, 2])
        ann2 = np.array([4, 5, 6])

        ann1c = ann1.copy()
#.........这里部分代码省略.........
开发者ID:CINPLA,项目名称:python-neo,代码行数:103,代码来源:test_base.py


注:本文中的neo.core.baseneo.BaseNeo.merge_annotations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。