在 Python 中将基于 HDF5 的文件读取为 numpy 数组
Read HDF5 based file as a numpy array in Python
如何将 .hws
文件作为 numpy 数组加载?
根据 http://kingler.net/2007/05/22/90 which says it is a HDF5 based format, so I found https://confluence.slac.stanford.edu/display/PSDM/How+to+access+HDF5+data+from+Python 中的描述可能会有用。但是,按照页面中描述的说明进行操作:
hdf5_file_name = '/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r0546.h5'
dataset_name = '/Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1/XppSb4Pim.1:Tm6740.1/image'
event_number = 5
file = h5py.File(hdf5_file_name, 'r')
dataset = file[dataset_name]
arr1ev = dataset[event_number]
file.close()
按照我的情况修改前三行后,第六行出现错误:
file_name = '~/Desktop/audioData_A.hws'
item = h5py.File(file_name, 'r')
print item.name
ds = item['/']
print len(ds)
arr1ev = ds[1]
哪个returns:
<HDF5 group "/" (1 members)>
1
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-59-b33014aeccc8> in <module>()
4 ds = item['/']
5 print len(ds)
----> 6 arr1ev = ds[1]
/usr/local/lib/python2.7/site-packages/h5py/_objects.so in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2405)()
/usr/local/lib/python2.7/site-packages/h5py/_objects.so in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2362)()
/usr/local/lib/python2.7/site-packages/h5py/_hl/group.pyc in __getitem__(self, name)
158 raise ValueError("Invalid HDF5 object reference")
159 else:
--> 160 oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
161
162 otype = h5i.get_type(oid)
/usr/local/lib/python2.7/site-packages/h5py/_hl/base.pyc in _e(self, name, lcpl)
119 else:
120 try:
--> 121 name = name.encode('ascii')
122 coding = h5t.CSET_ASCII
123 except UnicodeEncodeError:
AttributeError: 'int' object has no attribute 'encode'
问题是我不知道如何获取dataset_name
和event_number
的信息。通过item.parent
,在我的第二行,我猜相应的值应该是/
和1
,这是行不通的。
如果您需要,请在link中找到该文件:
https://drive.google.com/file/d/0B1UyTlIs325wbWhwR3NTVmFpWTg/view?usp=sharing
我下载了您的文件并查看了它。阅读 .hws
文件后,您会得到一个只有一个键 "wfm_group0"
的字典(您可以使用 item.keys()
查看文件中的键)。此键的值再次与键 "axes"
、"id"
、"traces"
和 "vector"
类似字典。
不知道你想从那里去哪里,但也许你可以尝试一下这些信息,看看它能把你带到哪里。
如何将 .hws
文件作为 numpy 数组加载?
根据 http://kingler.net/2007/05/22/90 which says it is a HDF5 based format, so I found https://confluence.slac.stanford.edu/display/PSDM/How+to+access+HDF5+data+from+Python 中的描述可能会有用。但是,按照页面中描述的说明进行操作:
hdf5_file_name = '/reg/d/psdm/XPP/xppcom10/hdf5/xppcom10-r0546.h5'
dataset_name = '/Configure:0000/Run:0000/CalibCycle:0000/Camera::FrameV1/XppSb4Pim.1:Tm6740.1/image'
event_number = 5
file = h5py.File(hdf5_file_name, 'r')
dataset = file[dataset_name]
arr1ev = dataset[event_number]
file.close()
按照我的情况修改前三行后,第六行出现错误:
file_name = '~/Desktop/audioData_A.hws'
item = h5py.File(file_name, 'r')
print item.name
ds = item['/']
print len(ds)
arr1ev = ds[1]
哪个returns:
<HDF5 group "/" (1 members)>
1
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-59-b33014aeccc8> in <module>()
4 ds = item['/']
5 print len(ds)
----> 6 arr1ev = ds[1]
/usr/local/lib/python2.7/site-packages/h5py/_objects.so in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2405)()
/usr/local/lib/python2.7/site-packages/h5py/_objects.so in h5py._objects.with_phil.wrapper (/Users/travis/build/MacPython/h5py-wheels/h5py/h5py/_objects.c:2362)()
/usr/local/lib/python2.7/site-packages/h5py/_hl/group.pyc in __getitem__(self, name)
158 raise ValueError("Invalid HDF5 object reference")
159 else:
--> 160 oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
161
162 otype = h5i.get_type(oid)
/usr/local/lib/python2.7/site-packages/h5py/_hl/base.pyc in _e(self, name, lcpl)
119 else:
120 try:
--> 121 name = name.encode('ascii')
122 coding = h5t.CSET_ASCII
123 except UnicodeEncodeError:
AttributeError: 'int' object has no attribute 'encode'
问题是我不知道如何获取dataset_name
和event_number
的信息。通过item.parent
,在我的第二行,我猜相应的值应该是/
和1
,这是行不通的。
如果您需要,请在link中找到该文件: https://drive.google.com/file/d/0B1UyTlIs325wbWhwR3NTVmFpWTg/view?usp=sharing
我下载了您的文件并查看了它。阅读 .hws
文件后,您会得到一个只有一个键 "wfm_group0"
的字典(您可以使用 item.keys()
查看文件中的键)。此键的值再次与键 "axes"
、"id"
、"traces"
和 "vector"
类似字典。
不知道你想从那里去哪里,但也许你可以尝试一下这些信息,看看它能把你带到哪里。