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


Python h5py.ExternalLink方法代码示例

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


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

示例1: test_get_link_class

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_get_link_class(self):
        """ Get link classes """
        default = object()

        sl = SoftLink('/mongoose')
        el = ExternalLink('somewhere.hdf5', 'mongoose')

        self.f.create_group('hard')
        self.f['soft'] = sl
        self.f['external'] = el

        out_hl = self.f.get('hard', default, getlink=True, getclass=True)
        out_sl = self.f.get('soft', default, getlink=True, getclass=True)
        out_el = self.f.get('external', default, getlink=True, getclass=True)

        self.assertEqual(out_hl, HardLink)
        self.assertEqual(out_sl, SoftLink)
        self.assertEqual(out_el, ExternalLink) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_group.py

示例2: test_get_link

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_get_link(self):
        """ Get link values """
        sl = SoftLink('/mongoose')
        el = ExternalLink('somewhere.hdf5', 'mongoose')

        self.f.create_group('hard')
        self.f['soft'] = sl
        self.f['external'] = el

        out_hl = self.f.get('hard', getlink=True)
        out_sl = self.f.get('soft', getlink=True)
        out_el = self.f.get('external', getlink=True)

        #TODO: redo with SoftLink/ExternalLink built-in equality
        self.assertIsInstance(out_hl, HardLink)
        self.assertIsInstance(out_sl, SoftLink)
        self.assertEqual(out_sl._path, sl._path)
        self.assertIsInstance(out_el, ExternalLink)
        self.assertEqual(out_el._path, el._path)
        self.assertEqual(out_el._filename, el._filename) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:test_group.py

示例3: test_mode_external

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_mode_external(self):
        """ Mode property works for files opened via external links

        Issue 190.
        """
        fname1 = self.mktemp()
        fname2 = self.mktemp()

        f1 = File(fname1,'w')
        f1.close()

        f2 = File(fname2,'w')
        try:
            f2['External'] = h5py.ExternalLink(fname1, '/')
            f3 = f2['External'].file
            self.assertEqual(f3.mode, 'r+')
        finally:
            f2.close()
            f3.close()

        f2 = File(fname2,'r')
        try:
            f3 = f2['External'].file
            self.assertEqual(f3.mode, 'r')
        finally:
            f2.close()
            f3.close() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:29,代码来源:test_file.py

示例4: test_softlinks

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_softlinks(self):
        """ Broken softlinks are contained, but their members are not """
        self.f.create_group('grp')
        self.f['/grp/soft'] = h5py.SoftLink('/mongoose')
        self.f['/grp/external'] = h5py.ExternalLink('mongoose.hdf5', '/mongoose')
        self.assertIn('/grp/soft', self.f)
        self.assertNotIn('/grp/soft/something', self.f)
        self.assertIn('/grp/external', self.f)
        self.assertNotIn('/grp/external/something', self.f) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_group.py

示例5: test_epath

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_epath(self):
        """ External link paths attributes """
        el = ExternalLink('foo.hdf5', '/foo')
        self.assertEqual(el.filename, 'foo.hdf5')
        self.assertEqual(el.path, '/foo') 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_group.py

示例6: test_create

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_create(self):
        """ Creating external links """
        self.f['ext'] = ExternalLink(self.ename, '/external')
        grp = self.f['ext']
        self.ef = grp.file
        self.assertNotEqual(self.ef, self.f)
        self.assertEqual(grp.name, '/external') 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_group.py

示例7: test_exc

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_exc(self):
        """ KeyError raised when attempting to open broken link """
        self.f['ext'] = ExternalLink(self.ename, '/missing')
        with self.assertRaises(KeyError):
            self.f['ext']

    # I would prefer IOError but there's no way to fix this as the exception
    # class is determined by HDF5. 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:10,代码来源:test_group.py

示例8: test_exc_missingfile

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_exc_missingfile(self):
        """ KeyError raised when attempting to open missing file """
        self.f['ext'] = ExternalLink('mongoose.hdf5','/foo')
        with self.assertRaises(KeyError):
            self.f['ext'] 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:7,代码来源:test_group.py

示例9: test_close_file

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_close_file(self):
        """ Files opened by accessing external links can be closed

        Issue 189.
        """
        self.f['ext'] = ExternalLink(self.ename, '/')
        grp = self.f['ext']
        f2 = grp.file
        f2.close()
        self.assertFalse(f2) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,代码来源:test_group.py

示例10: test_unicode_encode

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_unicode_encode(self):
        """
        Check that external links encode unicode filenames properly
        Testing issue #732
        """
        ext_filename = os.path.join(mkdtemp(), u"α.hdf5")
        with File(ext_filename, "w") as ext_file:
            ext_file.create_group('external')
        self.f['ext'] = ExternalLink(ext_filename, '/external') 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_group.py

示例11: test_unicode_hdf5_path

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_unicode_hdf5_path(self):
        """
        Check that external links handle unicode hdf5 paths properly
        Testing issue #333
        """
        ext_filename = os.path.join(mkdtemp(), "external.hdf5")
        with File(ext_filename, "w") as ext_file:
            ext_file.create_group(u'α')
            ext_file[u"α"].attrs["ext_attr"] = "test"
        self.f['ext'] = ExternalLink(ext_filename, u'/α')
        self.assertEqual(self.f["ext"].attrs["ext_attr"], "test") 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:13,代码来源:test_group.py

示例12: test_issue_212

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_issue_212(self):
        """ Issue 212

        Fails with:

        AttributeError: 'SharedConfig' object has no attribute 'lapl'
        """
        def closer(x):
            def w():
                try:
                    if x:
                        x.close()
                except IOError:
                    pass
            return w
        orig_name = self.mktemp()
        new_name = self.mktemp()
        f = File(orig_name, 'w')
        self.addCleanup(closer(f))
        f.create_group('a')
        f.close()

        g = File(new_name, 'w')
        self.addCleanup(closer(g))
        g['link'] = ExternalLink(orig_name, '/')  # note root group
        g.close()

        h = File(new_name, 'r')
        self.addCleanup(closer(h))
        self.assertIsInstance(h['link']['a'], Group) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:32,代码来源:test_group.py

示例13: test_copy_external_links

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def test_copy_external_links(self):

        filename = self.f1.filename
        self.f1['foo'] = [1,2,3]
        self.f2['bar'] = ExternalLink(filename, 'foo')
        self.f1.close()
        self.f1 = None

        self.assertArrayEqual(self.f2['bar'], np.array([1,2,3]))

        self.f2.copy('bar', 'baz', expand_external=True)
        os.unlink(filename)
        self.assertArrayEqual(self.f2['baz'], np.array([1,2,3])) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:15,代码来源:test_group.py

示例14: _copy

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import ExternalLink [as 别名]
def _copy(src_uri, dst_uri, overwrite, link, rename, soft_link):
    src_path, src_group = parse_cooler_uri(src_uri)
    dst_path, dst_group = parse_cooler_uri(dst_uri)

    if sum([link, rename, soft_link]) > 1:
        raise ValueError('Must provide at most one of: "link", "rename", "soft_link"')

    if not os.path.isfile(dst_path) or overwrite:
        write_mode = "w"
    else:
        write_mode = "r+"

    with h5py.File(src_path, "r+") as src, h5py.File(
        dst_path, write_mode
    ) as dst:  # noqa

        if src_path == dst_path:
            if link or rename:
                src[dst_group] = src[src_group]
                if rename:
                    del src[src_group]
            elif soft_link:
                src[dst_group] = h5py.SoftLink(src_group)
            else:
                src.copy(src_group, dst_group)
        else:
            if link:
                raise OSError("Can't hard link between two different files.")
            elif soft_link:
                dst[dst_group] = h5py.ExternalLink(src_path, src_group)
            else:
                if dst_group == "/":
                    for subgrp in src[src_group].keys():
                        src.copy(src_group + "/" + subgrp, dst, subgrp)
                    dst[dst_group].attrs.update(src[src_group].attrs)
                else:
                    src.copy(src_group, dst, dst_group if dst_group != "/" else None) 
开发者ID:mirnylab,项目名称:cooler,代码行数:39,代码来源:fileops.py


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