本文整理汇总了Python中h5py.File.create_group方法的典型用法代码示例。如果您正苦于以下问题:Python File.create_group方法的具体用法?Python File.create_group怎么用?Python File.create_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h5py.File
的用法示例。
在下文中一共展示了File.create_group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_block
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_write_block(self):
""" Test that writing to a user block does not destroy the file """
name = self.mktemp()
f = File(name, 'w', userblock_size=512)
f.create_group("Foobar")
f.close()
pyfile = open(name, 'r+b')
try:
pyfile.write(b'X'*512)
finally:
pyfile.close()
f = h5py.File(name, 'r')
try:
assert "Foobar" in f
finally:
f.close()
pyfile = open(name, 'rb')
try:
self.assertEqual(pyfile.read(512), b'X'*512)
finally:
pyfile.close()
示例2: test_issue_212
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [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)
示例3: test_backing
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_backing(self):
""" Core driver saves to file when backing store used """
fname = self.mktemp()
fid = File(fname, 'w', driver='core', backing_store=True)
fid.create_group('foo')
fid.close()
fid = File(fname, 'r')
assert 'foo' in fid
fid.close()
示例4: test_close_multiple_mpio_driver
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_close_multiple_mpio_driver(self):
""" MPIO driver and options """
from mpi4py import MPI
fname = self.mktemp()
f = File(fname, 'w', driver='mpio', comm=MPI.COMM_WORLD)
f.create_group("test")
f.close()
f.close()
示例5: test_create
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_create(self):
""" Mode 'w' opens file in overwrite mode """
fname = self.mktemp()
fid = File(fname, 'w')
self.assertTrue(fid)
fid.create_group('foo')
fid.close()
fid = File(fname, 'w')
self.assertNotIn('foo', fid)
fid.close()
示例6: test_readwrite
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_readwrite(self):
""" Mode 'r+' opens existing file in readwrite mode """
fname = self.mktemp()
fid = File(fname, 'w')
fid.create_group('foo')
fid.close()
fid = File(fname, 'r+')
assert 'foo' in fid
fid.create_group('bar')
assert 'bar' in fid
fid.close()
示例7: test_readonly
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_readonly(self):
""" Mode 'r' opens file in readonly mode """
fname = self.mktemp()
fid = File(fname, 'w')
fid.close()
self.assertFalse(fid)
fid = File(fname, 'r')
self.assertTrue(fid)
with self.assertRaises(ValueError):
fid.create_group('foo')
fid.close()
示例8: BaseMapping
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
class BaseMapping(BaseGroup):
"""
Base class for mapping tests
"""
def setUp(self):
self.f = File(self.mktemp(), 'w')
self.groups = ('a','b','c','d')
for x in self.groups:
self.f.create_group(x)
self.f['x'] = h5py.SoftLink('/mongoose')
self.groups = self.groups + ('x',)
def tearDown(self):
if self.f:
self.f.close()
示例9: test_append
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_append(self):
""" Mode 'a' opens file in append/readwrite mode, creating if necessary """
fname = self.mktemp()
fid = File(fname, 'a')
try:
self.assertTrue(fid)
fid.create_group('foo')
assert 'foo' in fid
finally:
fid.close()
fid = File(fname, 'a')
try:
assert 'foo' in fid
fid.create_group('bar')
assert 'bar' in fid
finally:
fid.close()
示例10: test_mode
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_mode(self):
""" Retrieved File objects have a meaningful mode attribute """
hfile = File(self.mktemp(),'w')
try:
grp = hfile.create_group('foo')
self.assertEqual(grp.file.mode, hfile.mode)
finally:
hfile.close()
示例11: test_readonly_delete_exception
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_readonly_delete_exception(self):
""" Deleting object in readonly file raises KeyError """
# Note: it is impossible to restore the old behavior (ValueError)
# without breaking the above test (non-existing objects)
fname = self.mktemp()
hfile = File(fname,'w')
try:
hfile.create_group('foo')
finally:
hfile.close()
hfile = File(fname, 'r')
try:
with self.assertRaises(KeyError):
del hfile['foo']
finally:
hfile.close()
示例12: weightsToHDF
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def weightsToHDF(w, name):
f=File(name+".h5","w")
weights=f.create_group("Weights")
for i in range(len(w[:-1])):
weights.create_dataset("Hidden "+str(i+1),data=w[i])
weights.create_dataset("Output",data=w[-1])
f.close()
示例13: test_close
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def test_close(self):
""" All retrieved File objects are closed at the same time """
fname = self.mktemp()
hfile = File(fname, 'w')
grp = hfile.create_group('foo')
hfile2 = grp.file
hfile3 = hfile['/'].file
hfile2.close()
self.assertFalse(hfile)
self.assertFalse(hfile2)
self.assertFalse(hfile3)
示例14: TestVisit
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
class TestVisit(TestCase):
"""
Feature: The .visit and .visititems methods allow iterative access to
group and subgroup members
"""
def setUp(self):
self.f = File(self.mktemp(), 'w')
self.groups = [
'grp1', 'grp1/sg1', 'grp1/sg2', 'grp2', 'grp2/sg1', 'grp2/sg1/ssg1'
]
for x in self.groups:
self.f.create_group(x)
def tearDown(self):
self.f.close()
def test_visit(self):
""" All subgroups are visited """
l = []
self.f.visit(l.append)
self.assertSameElements(l, self.groups)
def test_visititems(self):
""" All subgroups and contents are visited """
l = []
comp = [(x, self.f[x]) for x in self.groups]
self.f.visititems(lambda x, y: l.append((x,y)))
self.assertSameElements(comp, l)
def test_bailout(self):
""" Returning a non-None value immediately aborts iteration """
x = self.f.visit(lambda x: x)
self.assertEqual(x, self.groups[0])
x = self.f.visititems(lambda x, y: (x,y))
self.assertEqual(x, (self.groups[0], self.f[self.groups[0]]))
示例15: save_to_hdf5
# 需要导入模块: from h5py import File [as 别名]
# 或者: from h5py.File import create_group [as 别名]
def save_to_hdf5(f: h5py.File, iteration, time, dt, r, p, m, q):
# TODO use OpenPMD for saving instead of hdf5?
N = r.shape[0]
g = f.create_group(f.attrs["iterationFormat"].format(iteration))
g.attrs["time"] = time
g.attrs["dt"] = dt
g.attrs["timeUnitSI"] = time # TODO decide on something
particles = g.create_group(f.attrs["particlesPath"] + b"particles")
openPMD_positions = np.array([1] + [0] * 6, dtype=float)
openPMD_momentum = np.array([1, 1, -1, 0, 0, 0, 0], dtype=float)
openPMD_charge = np.array([0, 0, 1, 1, 0, 0, 0], dtype=float)
openPMD_mass = np.array([0, 1, 0, 0, 0, 0, 0], dtype=float)
for index, direction in enumerate("xyz"):
position = particles.create_dataset(f"position/{direction}", data=r[:, index])
position.attrs["unitSI"] = 1.0
position.attrs["unitDimension"] = openPMD_positions
position.attrs["timeOffset"] = 0.0
positionOffset = particles.create_dataset(
f"positionOffset/{direction}", data=np.zeros(N)
)
positionOffset.attrs["unitSI"] = 1.0
positionOffset.attrs["unitDimension"] = openPMD_positions
positionOffset.attrs["timeOffset"] = 0.0
momentum = particles.create_dataset(f"momentum/{direction}", data=p[:, index])
momentum.attrs["unitSI"] = 1.0
momentum.attrs["unitDimension"] = openPMD_momentum
momentum.attrs["timeOffset"] = 0.0
charge = particles.create_dataset("charge", data=q[:, 0])
charge.attrs["unitSI"] = 1.0
charge.attrs["unitDimension"] = openPMD_charge
charge.attrs["timeOffset"] = 0.0
mass = particles.create_dataset("mass", data=m[:, 0])
mass.attrs["unitSI"] = 1.0
mass.attrs["unitDimension"] = openPMD_mass
mass.attrs["timeOffset"] = 0.0