From 1e6c6ad4fd52b9e6f42d41e576c708fce03ecd93 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Mon, 21 Nov 2022 13:43:58 +0100 Subject: [PATCH] ZH: rename beacon_phase to beacon_phase_measured Also reorganises lib.py slightly --- .../airshower_beacon_simulation/Makefile | 6 ++++++ .../aa_generate_beacon.py | 19 ++++++++++++------- .../ba_beacon_phases.py | 4 ++-- .../airshower_beacon_simulation/lib.py | 17 ++++++++--------- .../show_beacon_amplitude_antennas.py | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/simulations/airshower_beacon_simulation/Makefile b/simulations/airshower_beacon_simulation/Makefile index 6fb7223..e78c2be 100644 --- a/simulations/airshower_beacon_simulation/Makefile +++ b/simulations/airshower_beacon_simulation/Makefile @@ -9,6 +9,12 @@ beacon: clocks: ./ab_modify_clocks.py +phases: + ./ba_beacon_phases.py + +period_multiples: + ./bb_beacon_multiples.py + dist-clean: rm -f ZH_airshower/antennas.hdf5 rm -f ZH_airshower/clocks.csv diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index eef6861..48e6c53 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -42,7 +42,7 @@ def read_tx_file(fname): return tx, f_beacon -def read_beacon_hdf5(fname, traces_key='traces'): +def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True): with h5py.File(fname, 'r') as h5: tx_attrs = h5['tx'].attrs f_beacon = tx_attrs.get('f_beacon') @@ -54,12 +54,17 @@ def read_beacon_hdf5(fname, traces_key='traces'): for k, ant in h5['antennas'].items(): mydict = { k:ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] } antenna = Antenna(**mydict) - 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] + + if traces_key not in ant: + 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] if ant.attrs: antenna.attrs = {**ant.attrs} diff --git a/simulations/airshower_beacon_simulation/ba_beacon_phases.py b/simulations/airshower_beacon_simulation/ba_beacon_phases.py index 047f888..f4a168e 100755 --- a/simulations/airshower_beacon_simulation/ba_beacon_phases.py +++ b/simulations/airshower_beacon_simulation/ba_beacon_phases.py @@ -71,7 +71,7 @@ if __name__ == "__main__": if not True: # only take the Beacon trace - test_traces = traces[4] + test_traces = [traces[4]] orients = ['B'] else: test_traces = traces[1:] @@ -112,7 +112,7 @@ if __name__ == "__main__": ax.legend() ant_group.attrs['beacon_freq'] = frequency - ant_group.attrs['beacon_phase'] = phase + ant_group.attrs['beacon_phase_measured'] = phase ant_group.attrs['beacon_amplitude'] = amplitude ant_group.attrs['beacon_orientation'] = orientation diff --git a/simulations/airshower_beacon_simulation/lib.py b/simulations/airshower_beacon_simulation/lib.py index 7b14641..cee5129 100644 --- a/simulations/airshower_beacon_simulation/lib.py +++ b/simulations/airshower_beacon_simulation/lib.py @@ -7,12 +7,19 @@ from numpy.polynomial import Polynomial from earsim import Antenna +""" Beacon utils """ def sine_beacon(f, t, t0=0, amplitude=1, baseline=0, phase=0): """ Return a sine appropriate as a beacon """ return amplitude * np.sin(2*np.pi*f*(t+t0) + phase) + baseline +def phase_mod(phase, low=np.pi): + """ + Modulo phase such that it falls within the + interval $[-low, 2\pi - low)$. + """ + return (phase + low) % (2*np.pi) - low def distance(x1, x2): """ @@ -38,7 +45,7 @@ def beacon_from(tx, rx, f, t=0, t0=0, c_light=3e8, radiate_rsq=True, amplitude=1 return sine_beacon(f, t, t0=t0, amplitude=amplitude,**kwargs) - +""" Fourier """ def ft_corr_vectors(freqs, time): """ Get the cosine and sine terms for freqs at time. @@ -94,14 +101,6 @@ def phase_field_from_tx(x, y, tx, f_beacon, c_light=3e8, t0=0, wrap_phase=True, return phase, (np.repeat(xs, len(ys), axis=0), np.repeat(ys, len(xs[0]), axis=1)) -def phase_mod(phase, low=np.pi): - """ - Modulo phase such that it falls within the - interval $[-low, 2\pi - low)$. - """ - return (phase + low) % (2*np.pi) - low - - def find_beacon_in_traces( traces, t_trace, diff --git a/simulations/airshower_beacon_simulation/show_beacon_amplitude_antennas.py b/simulations/airshower_beacon_simulation/show_beacon_amplitude_antennas.py index 70e2f62..c6410af 100755 --- a/simulations/airshower_beacon_simulation/show_beacon_amplitude_antennas.py +++ b/simulations/airshower_beacon_simulation/show_beacon_amplitude_antennas.py @@ -28,7 +28,7 @@ if __name__ == "__main__": if True: beacon_frequencies = np.array([ant.attrs['beacon_freq'] for ant in antennas]) beacon_amplitudes = np.array([ant.attrs['beacon_amplitude'] for ant in antennas]) - beacon_phases = np.array([lib.phase_mod(ant.attrs['beacon_phase']) for ant in antennas]) + beacon_phases = np.array([lib.phase_mod(ant.attrs['beacon_phase_measured']) for ant in antennas]) else: subtitle = " Phases from t0" beacon_frequencies = np.array([ f_beacon for ant in antennas ])