mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-11-13 10:03:32 +01:00
ZH: rewrite read_beacon_hdf5 function
This commit is contained in:
parent
006a0903ab
commit
e57403e765
1 changed files with 32 additions and 27 deletions
|
@ -42,41 +42,46 @@ 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():
|
||||||
mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
|
ant = Antenna_from_h5ant(h5ant, **h5ant_kwargs)
|
||||||
ant = Antenna(**mydict)
|
|
||||||
|
|
||||||
if traces_key not in h5ant:
|
|
||||||
if raise_exception:
|
|
||||||
raise ValueError("Traces_key not in file")
|
|
||||||
else:
|
|
||||||
ant.t = h5ant[traces_key][0]
|
|
||||||
ant.Ex = h5ant[traces_key][1]
|
|
||||||
ant.Ey = h5ant[traces_key][2]
|
|
||||||
ant.Ez = h5ant[traces_key][3]
|
|
||||||
if len(h5ant[traces_key]) > 4:
|
|
||||||
ant.beacon = h5ant[traces_key][4]
|
|
||||||
|
|
||||||
if read_AxB and 'E_AxB' in h5ant:
|
|
||||||
ant.t_AxB = h5ant['E_AxB'][0]
|
|
||||||
ant.E_AxB = h5ant['E_AxB'][1]
|
|
||||||
|
|
||||||
if h5ant.attrs:
|
|
||||||
ant.attrs = {**h5ant.attrs}
|
|
||||||
|
|
||||||
antennas.append(ant)
|
antennas.append(ant)
|
||||||
|
|
||||||
return f_beacon, tx, antennas
|
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'] }
|
||||||
|
ant = Antenna(**mydict)
|
||||||
|
|
||||||
|
if traces_key is None:
|
||||||
|
pass
|
||||||
|
elif traces_key not in h5ant:
|
||||||
|
if raise_exception:
|
||||||
|
raise ValueError("Traces_key not in file")
|
||||||
|
else:
|
||||||
|
ant.t = h5ant[traces_key][0]
|
||||||
|
ant.Ex = h5ant[traces_key][1]
|
||||||
|
ant.Ey = h5ant[traces_key][2]
|
||||||
|
ant.Ez = h5ant[traces_key][3]
|
||||||
|
if len(h5ant[traces_key]) > 4:
|
||||||
|
ant.beacon = h5ant[traces_key][4]
|
||||||
|
|
||||||
|
if read_AxB and 'E_AxB' in h5ant:
|
||||||
|
ant.t_AxB = h5ant['E_AxB'][0]
|
||||||
|
ant.E_AxB = h5ant['E_AxB'][1]
|
||||||
|
|
||||||
|
if h5ant.attrs:
|
||||||
|
ant.attrs = {**h5ant.attrs}
|
||||||
|
|
||||||
|
return ant
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
if tx is not None or f_beacon is not None:
|
if tx is not None or f_beacon is not None:
|
||||||
|
|
Loading…
Reference in a new issue