UCBerkeleySETI / blimpy

Breakthrough Listen I/O Methods for Python
https://blimpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
48 stars 41 forks source link

read_header not working with .h5 files #60

Closed umranhaji closed 6 years ago

umranhaji commented 6 years ago

Hi folks,

The older version of blimpy allowed .fil files to have their headers read with the read_header function. Are the .h5 files supposed to be compatible with this function as well? It's not clear from read_header's docstring or from my perusing of the source code for the past several minutes.

I ask because I am getting errors when attempting to use this function on .h5 files. For example, attempting to call read_header on any of the files in bls0:/mnt_bls5/datax3/holding.Lband.692.0001020304050607/ gives me the following error:

/opt/pyve/sci/local/lib/python2.7/site-packages/blimpy/sigproc.pyc in read_header(filename, return_idxs)
    230 
    231         # Check this is a blimpy file
--> 232         keyword, value, idx = read_next_header_keyword(fh)
    233 
    234         try:

/opt/pyve/sci/local/lib/python2.7/site-packages/blimpy/sigproc.pyc in read_next_header_keyword(fh)
    193         return keyword, 0, fh.tell()
    194     else:
--> 195         dtype = header_keyword_types[keyword]
    196         #print dtype
    197         idx = fh.tell()

KeyError: '\r\n\x1a\n\x00\x00\x00\x00\x00\x08\x08\x00\x04\x00\x10\x00'
telegraphic commented 6 years ago

Hey @umranhaji -- h5 files are read with an external library called h5py. You would read the header as:

h = h5py.File(filename)
header = h['data'].attrs.items()

Everything within sigproc.py is solely for reading sigproc-standard filterbanks.

We could / (should?) theoretically provide a high-level read_header() function that worked on both h5 and fil files.

umranhaji commented 6 years ago

Thanks @telegraphic! And yes, I think a universal blimpy function to read headers would be convenient and appreciated in the future, even if just a combined wrapper around the sigproc and h5py functions.

telegraphic commented 6 years ago

(moved discussion to a new issue labeled as 'enhancement'