ZH: rewrite read_beacon_hdf5 function

This commit is contained in:
Eric Teunis de Boone 2022-11-22 11:06:15 +01:00
parent 006a0903ab
commit e57403e765

View file

@ -42,20 +42,26 @@ def read_tx_file(fname):
return tx, f_beacon return tx, f_beacon
def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True, read_AxB=True): def read_beacon_hdf5(fname, **h5ant_kwargs):
with h5py.File(fname, 'r') as h5: with h5py.File(fname, 'r') as h5:
tx_attrs = h5['tx'].attrs tx = Antenna_from_h5ant(h5['tx'], traces_key=None)
f_beacon = tx_attrs.get('f_beacon') f_beacon = tx.attrs['f_beacon']
mydict = { k:tx_attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
tx = Antenna(**mydict)
antennas = [] antennas = []
for k, h5ant in h5['antennas'].items(): for k, h5ant in h5['antennas'].items():
ant = Antenna_from_h5ant(h5ant, **h5ant_kwargs)
antennas.append(ant)
return f_beacon, tx, antennas
def Antenna_from_h5ant(h5ant, traces_key='traces', raise_exception=True, read_AxB=True):
mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] } mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
ant = Antenna(**mydict) ant = Antenna(**mydict)
if traces_key not in h5ant: if traces_key is None:
pass
elif traces_key not in h5ant:
if raise_exception: if raise_exception:
raise ValueError("Traces_key not in file") raise ValueError("Traces_key not in file")
else: else:
@ -73,9 +79,8 @@ def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True, read_AxB=
if h5ant.attrs: if h5ant.attrs:
ant.attrs = {**h5ant.attrs} ant.attrs = {**h5ant.attrs}
antennas.append(ant) return ant
return f_beacon, tx, antennas
def init_antenna_hdf5(fname, tx = None, f_beacon = None): def init_antenna_hdf5(fname, tx = None, f_beacon = None):
with h5py.File(fname, 'w') as fp: with h5py.File(fname, 'w') as fp: