ZH: write more beacon properties to tx file

This commit is contained in:
Eric Teunis de Boone 2022-11-25 12:08:00 +01:00
parent 4131b3775a
commit 616a23ef2b

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# vim: fdm=indent ts=4 # vim: fdm=marker ts=4
""" """
Add a beacon measurement on top of the Add a beacon measurement on top of the
@ -15,23 +15,27 @@ from copy import deepcopy
from earsim import REvent, Antenna, block_filter from earsim import REvent, Antenna, block_filter
import lib import lib
# {{{ vim marker
tx_fname = 'tx.json' tx_fname = 'tx.json'
antennas_fname = 'antennas.hdf5' antennas_fname = 'antennas.hdf5'
def write_tx_file(fname, tx, f_beacon): def write_tx_file(fname, tx, f_beacon, **kwargs):
with open(fname, 'w') as fp: with open(fname, 'w') as fp:
return json.dump( return json.dump(
dict( {
f_beacon=f_beacon, **kwargs,
tx=dict( **dict(
x=tx.x, f_beacon=f_beacon,
y=tx.y, tx=dict(
z=tx.z, x=tx.x,
name=tx.name y=tx.y,
z=tx.z,
name=tx.name
) )
), )
},
fp fp
) )
def read_tx_file(fname): def read_tx_file(fname):
with open(fname, 'r') as fp: with open(fname, 'r') as fp:
@ -40,7 +44,10 @@ def read_tx_file(fname):
f_beacon = data['f_beacon'] f_beacon = data['f_beacon']
tx = Antenna(**data['tx']) tx = Antenna(**data['tx'])
return tx, f_beacon del data['f_beacon']
del data['tx']
return tx, f_beacon, data
def read_beacon_hdf5(fname, **h5ant_kwargs): def read_beacon_hdf5(fname, **h5ant_kwargs):
with h5py.File(fname, 'r') as h5: with h5py.File(fname, 'r') as h5:
@ -227,15 +234,26 @@ def write_baseline_time_diffs_hdf5(fname, baselines, true_phase_diffs, k_periods
data = np.vstack( (time_diffs, f_beacon, true_phase_diffs, k_periods) ).T data = np.vstack( (time_diffs, f_beacon, true_phase_diffs, k_periods) ).T
dset = group.create_dataset(dset_name, data=data) dset = group.create_dataset(dset_name, data=data)
# }}} vim marker
if __name__ == "__main__": if __name__ == "__main__":
from os import path from os import path
fname = "ZH_airshower/mysim.sry"
# Transmitter
remake_tx = True remake_tx = True
fname = "ZH_airshower/mysim.sry" tx = Antenna(x=-2e3,y=0,z=0,name='tx') # m
tx = Antenna(x=-500,y=0,z=0,name='tx') # m if False:
if not True: # slowest beacon to be found: # Move tx out a long way
tx.x, tx.y = -75e3, 75e3 # m
elif False:
# Move it to 0,0,0 (among the antennas)
tx.x, tx.y = 0, 0 #m
# Beacon properties
if False: # slowest beacon to be found:
f_beacon = 10e-3 # GHz f_beacon = 10e-3 # GHz
low_bp = 5e-3 # GHz low_bp = 5e-3 # GHz
high_bp = 80e-3 # GHz high_bp = 80e-3 # GHz
@ -246,31 +264,35 @@ if __name__ == "__main__":
low_bp = 30e-3 # GHz low_bp = 30e-3 # GHz
high_bp = 80e-3 # GHz high_bp = 80e-3 # GHz
# Disable block_filter beacon_amplitudes = 1e-6*np.array([1e5, 0, 0]) # mu V/m
if False: beacon_radiate_rsq = True # beacon_amplitude is repaired for distance to 0,0,0
block_filter = lambda x, dt, low, high: x
beacon_amplitudes = 1e-6*np.array([1e2, 0, 0]) # mu V/m
beacon_radiate_rsq = True
# modify beacon power to be beacon_amplitude at 0,0,0
if beacon_radiate_rsq: if beacon_radiate_rsq:
# Move tx out, and magnify beacon_amplitude (at tx)
tx = Antenna(x=-20e3,y=0,z=0,name='tx') # m
dist = lib.distance(tx, Antenna(x=0, y=0, z=0)) dist = lib.distance(tx, Antenna(x=0, y=0, z=0))
ampl = max(1, dist**2) ampl = max(1, dist**2)
beacon_amplitudes *= ampl beacon_amplitudes *= ampl
# Disable block_filter
if False:
block_filter = lambda x, dt, low, high: x
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)
tx_fname = path.join(fname_dir, tx_fname) tx_fname = path.join(fname_dir, tx_fname)
antennas_fname = path.join(fname_dir, antennas_fname) antennas_fname = path.join(fname_dir, antennas_fname)
# read/write tx properties
if not path.isfile(tx_fname) or remake_tx: if not path.isfile(tx_fname) or remake_tx:
write_tx_file(tx_fname, tx, f_beacon) write_tx_file(tx_fname, tx, f_beacon, amplitudes=beacon_amplitudes.tolist(), radiate_rsq=beacon_radiate_rsq)
else: else:
tx, f_beacon = read_tx_file(tx_fname) tx, f_beacon, _ = read_tx_file(tx_fname)
print("Beacon amplitude at (0,0,0) [muV/m]:", beacon_amplitudes)
print("Tx location:", [tx.x, tx.y, tx.z])
# read in antennas # read in antennas
ev = REvent(fname) ev = REvent(fname)