1

How can I load in a .hws file as a numpy array?
Based on the description in 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 might be useful. However, by following the instruction described in the page:

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()

I got error in the sixth line after I fixed the first three line as my case:

file_name = '~/Desktop/audioData_A.hws'
item = h5py.File(file_name, 'r')
print item.name 
ds = item['/']
print len(ds)
arr1ev = ds[1]

which 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'

The problem is that I don't know how to get the information of dataset_name and event_number. By item.parent, the second line in my case, I guess the corresponding values should be / and 1, which doesn't work.

Please find the file in the link if you need: https://drive.google.com/file/d/0B1UyTlIs325wbWhwR3NTVmFpWTg/view?usp=sharing

Francis
  • 6,416
  • 5
  • 24
  • 32

1 Answers1

2

I downloaded your file and took a look at it. After reading the .hws file you get a dictionary with exactly one key "wfm_group0" (You can see keys in the file by using item.keys()). The value to this key is again dictionary-like with the keys "axes", "id", "traces" and "vector".

Don't know where you want to go from there, but maybe you can play around with this information and see where it gets you.

ali_m
  • 71,714
  • 23
  • 223
  • 298
dudenr33
  • 1,119
  • 1
  • 10
  • 26
  • Thanks, by recursively checking the keys, I finally found the data and converted it to numpy array. It really is a 'Hierarchical' storage. – Francis Feb 28 '15 at 17:39