ZH: precalculate E_AxB (bandpassed) for hdf5 file

This commit is contained in:
Eric Teunis de Boone 2022-11-22 09:40:58 +01:00
parent 22a54da1c8
commit b91971368d

View file

@ -12,7 +12,7 @@ import h5py
import os.path as path
from copy import deepcopy as copy
from earsim import REvent, Antenna
from earsim import REvent, Antenna, block_filter
import lib
tx_fname = 'tx.json'
@ -42,7 +42,7 @@ def read_tx_file(fname):
return tx, f_beacon
def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True):
def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True, read_AxB=True):
with h5py.File(fname, 'r') as h5:
tx_attrs = h5['tx'].attrs
f_beacon = tx_attrs.get('f_beacon')
@ -51,25 +51,29 @@ def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True):
tx = Antenna(**mydict)
antennas = []
for k, ant in h5['antennas'].items():
mydict = { k:ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
antenna = Antenna(**mydict)
for k, h5ant in h5['antennas'].items():
mydict = { k:h5ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
ant = Antenna(**mydict)
if traces_key not in ant:
if traces_key not in h5ant:
if raise_exception:
raise ValueError("Traces_key not in file")
else:
antenna.t = ant[traces_key][0]
antenna.Ex = ant[traces_key][1]
antenna.Ey = ant[traces_key][2]
antenna.Ez = ant[traces_key][3]
if len(ant[traces_key]) > 4:
antenna.beacon = ant[traces_key][4]
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 ant.attrs:
antenna.attrs = {**ant.attrs}
if read_AxB and 'E_AxB' in h5ant:
ant.t_AxB = h5ant['E_AxB'][0]
ant.E_AxB = h5ant['E_AxB'][1]
antennas.append(antenna)
if h5ant.attrs:
ant.attrs = {**h5ant.attrs}
antennas.append(ant)
return f_beacon, tx, antennas
@ -141,6 +145,10 @@ if __name__ == "__main__":
tx = Antenna(x=-500,y=0,z=0,name='tx') # m
f_beacon = 51.53e-3 # GHz
# Bandpass for E field blockfilter
low_bp = 0.03 # GHz
high_bp = 0.08 # GHz
beacon_amplitudes = 1e-6*np.array([1e2, 0, 0]) # mu V/m
beacon_radiate_rsq = True
@ -177,12 +185,19 @@ if __name__ == "__main__":
beacon = lib.beacon_from(tx, antenna, f_beacon, antenna.t, t0=t0, c_light=np.inf, radiate_rsq=beacon_radiate_rsq)
E = np.array([antenna.Ex, antenna.Ey, antenna.Ez, beacon])
append_antenna_hdf5( antennas_fname, antenna, E, name='orig_traces', prepend_time=True)
# add to relevant polarisation
# and apply block filter
dt = antenna.t[1] - antenna.t[0]
for j, _ in enumerate(beacon_amplitudes):
E[j] += beacon_amplitudes[j]*beacon
E[j] += block_filter(beacon_amplitudes[j]*beacon, dt, low_bp, high_bp)
append_antenna_hdf5( antennas_fname, antenna, E, name='traces', prepend_time=True, attrs_dict=dict(t0=t0))
# Save E field in E_AxB
E = [np.dot(ev.uAxB,[ex,ey,ez]) for ex,ey,ez in zip(E[0], E[1], E[2])]
append_antenna_hdf5( antennas_fname, antenna, [E], name='E_AxB', prepend_time=True)
print("Antenna HDF5 file written as " + str(antennas_fname))