Skip to content

Commit

Permalink
Merge pull request #229 from texadactyl/master
Browse files Browse the repository at this point in the history
A betterfix to issue #226.
  • Loading branch information
texadactyl authored Aug 13, 2021
2 parents c310179 + 64b456a commit 0ec133e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions VERSION-HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ This file is a version history of turbo_seti amendments, beginning with version
<br>
| Date | Version | Contents |
| :--: | :--: | :-- |
| 2021-08-13 | 2.0.23 | A betterfix to issue #226. |
| 2021-08-10 | 2.0.22 | Non/broken HDF5 input files need better diagnosis (Issue #226). |
| 2021-08-07 | 2.0.21 | New signal_processing source file, "dedoppler.py" (discussion in PR #220). |
| 2021-08-06 | 2.0.20 | New utility, "stix" (Issue #221). |
Expand Down
19 changes: 2 additions & 17 deletions blimpy/h5diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from argparse import ArgumentParser
import h5py
from astropy.coordinates import Angle
from blimpy.io.hdf_reader import examine_h5


def oops(msg):
Expand Down Expand Up @@ -36,23 +37,7 @@ def read_header(h5):
def examine(filename):
r""" Diagnose the given HDF5 file"""
h5 = h5py.File(filename, mode="r")
if "CLASS" in h5.attrs:
classstr = h5.attrs["CLASS"]
else:
oops("CLASS attribute missing")
if classstr != "FILTERBANK":
oops("Expected CLASS attribute to be 'FILTERBANK' but saw '{}'".format(classstr))
if "VERSION" in h5.attrs:
versionstr = h5.attrs["VERSION"]
else:
oops("VERSION attribute missing")
print("VERSION is ", versionstr)
header = read_header(h5)
print("Header:", header)
if not "data" in h5:
oops("data attribute missing")
if h5["data"].ndim != 3:
oops("Expected data.ndim to be 3 but saw '{}'".format(h5["data"].ndim))
examine_h5(h5)
print("h5diag: data shape:", h5["data"].shape)


Expand Down
28 changes: 16 additions & 12 deletions blimpy/io/hdf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
from blimpy.io.base_reader import Reader, logger, GIGA


def examine_h5(h5):
if "CLASS" in h5.attrs:
classstr = h5.attrs["CLASS"]
else:
raise ValueError("HDF5 CLASS attribute missing")
if not classstr in ["FILTERBANK", b"FILTERBANK"]:
raise ValueError("Expected HDF5 CLASS attribute to be 'FILTERBANK' but saw '{}'".format(classstr))
if not "VERSION" in h5.attrs:
raise ValueError("HDF5 VERSION attribute missing")
if not "data" in h5:
raise ValueError("HDF5 data matrix missing")
if h5["data"].ndim != 3:
raise ValueError("Expected HDF5 data.ndim to be 3 but saw '{}'".format(h5["data"].ndim))


class H5Reader(Reader):
""" This class handles .h5 files.
"""
Expand Down Expand Up @@ -41,18 +56,7 @@ def __init__(self, filename, f_start=None, f_stop=None, t_start=None, t_stop=Non
self.filesize = self.filestat.st_size/(1024.0**2)
self.load_data = load_data
self.h5 = h5py.File(self.filename, mode='r')
if "CLASS" in self.h5.attrs:
classstr = self.h5.attrs["CLASS"]
else:
raise ValueError("CLASS attribute missing")
if classstr != "FILTERBANK":
raise ValueError("Expected CLASS attribute to be 'FILTERBANK' but saw '{}'".format(classstr))
if not "VERSION" in self.h5.attrs:
raise ValueError("VERSION attribute missing")
if not "data" in self.h5:
raise ValueError("data attribute missing")
if self.h5["data"].ndim != 3:
raise ValueError("Expected data.ndim to be 3 but saw '{}'".format(self.h5["data"].ndim))
examine_h5(self.h5)
self.read_header()
self.file_size_bytes = os.path.getsize(self.filename) # In bytes
self.n_ints_in_file = self.h5["data"].shape[self.time_axis] #
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from setuptools import setup, find_packages

__version__ = '2.0.22'
__version__ = '2.0.23'

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down

0 comments on commit 0ec133e

Please sign in to comment.