HDF5中的XML文件,h5py

cha*_*itu 4 python hdf5 h5py

我正在使用h5py来保存数据(浮点数).除了数据本身,我还需要在hdf5中包含一个附加文件(包含必要信息的.xml文件).我该怎么做呢?我的方法有误吗?

f = h5py.File('filename.h5')
f.create_dataset('/data/1',numpy_array_1)
f.create_dataset('/data/2',numpy_array_2)
.
.
Run Code Online (Sandbox Code Playgroud)

我的h5树应该是这样的:

/ 
/data
/data/1 (numpy_array_1)
/data/2 (numpy_array_2)
.
.
/morphology.xml (?)
Run Code Online (Sandbox Code Playgroud)

Joe*_*ton 5

一种选择是将其添加为可变长度字符串数据集.

http://code.google.com/p/h5py/wiki/HowTo#Variable-length_strings

例如:

import h5py
xmldata = """<xml>
<something>
    <else>Text</else>
</something>
</xml>
"""

# Write the xml file...
f = h5py.File('test.hdf5', 'w')
str_type = h5py.new_vlen(str)
ds = f.create_dataset('something.xml', shape=(1,), dtype=str_type)
ds[:] = xmldata
f.close()

# Read the xml file back...
f = h5py.File('test.hdf5', 'r')
print f['something.xml'][0]
Run Code Online (Sandbox Code Playgroud)