From 3fce4036f3b5b9eefae366d402cbfac925f1137a Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 15 Dec 2022 14:40:20 +0100 Subject: [PATCH] ZH: move c_light value to lib --- .../aa_generate_beacon.py | 14 +++----------- .../bb_measure_true_phase.py | 2 +- simulations/airshower_beacon_simulation/lib/lib.py | 9 +++++---- .../lib/tests/test_calculated_phase_measurement.py | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index 71147ca..4c0f0d6 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -18,6 +18,7 @@ import lib # {{{ vim marker tx_fname = 'tx.json' antennas_fname = 'antennas.hdf5' +c_light = lib.c_light def write_tx_file(fname, tx, f_beacon, **kwargs): with open(fname, 'w') as fp: @@ -326,16 +327,7 @@ if __name__ == "__main__": if i%10 == 0: print(f"Modified trace lengths by {pre_N},{after_N-N_samples}") - t0 = 0 - c_light = 3e8*1e-9 # m/ns - if False: - # precalculate t0 - # set c_light=np.inf to suppress the time delay - # in the function call - t0 = lib.distance(tx, antenna)/c_light - c_light = np.inf - - beacon = lib.beacon_from(tx, antenna, f_beacon, antenna.t, t0=t0, c_light=c_light, radiate_rsq=beacon_radiate_rsq) + beacon = lib.beacon_from(tx, antenna, f_beacon, antenna.t, c_light=c_light, radiate_rsq=beacon_radiate_rsq) traces = np.array([antenna.Ex, antenna.Ey, antenna.Ez, beacon]) # add to relevant polarisation @@ -344,7 +336,7 @@ if __name__ == "__main__": for j, amp in enumerate(beacon_amplitudes): traces[j] = block_filter(traces[j] + amp*beacon, dt, low_bp, high_bp) - append_antenna_hdf5( antennas_fname, antenna, traces, name='traces', prepend_time=True, attrs_dict=dict(t0=t0)) + append_antenna_hdf5( antennas_fname, antenna, traces, name='traces', prepend_time=True) # Save E field in E_AxB E_AxB = [np.dot(ev.uAxB,[ex,ey,ez]) for ex,ey,ez in zip(traces[0], traces[1], traces[2])] diff --git a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py index e9e04b5..fc8fd46 100755 --- a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py +++ b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py @@ -19,7 +19,7 @@ if __name__ == "__main__": matplotlib.use('Agg') fname = "ZH_airshower/mysim.sry" - c_light = 3e8*1e-9 # m/ns + c_light = lib.c_light show_plots = True remove_absolute_phase_offset_first_antenna = True # takes precedence diff --git a/simulations/airshower_beacon_simulation/lib/lib.py b/simulations/airshower_beacon_simulation/lib/lib.py index 85ddfd5..295916b 100644 --- a/simulations/airshower_beacon_simulation/lib/lib.py +++ b/simulations/airshower_beacon_simulation/lib/lib.py @@ -6,6 +6,7 @@ import numpy as np from numpy.polynomial import Polynomial from earsim import Antenna +c_light = 3e8*1e-9 # m/ns """ Beacon utils """ def sine_beacon(f, t, t0=0, amplitude=1, baseline=0, phase=0): @@ -34,13 +35,13 @@ def distance(x1, x2): return np.sqrt( np.sum( (x1-x2)**2 ) ) -def geometry_time(dist, x2=None, c_light=3e8): +def geometry_time(dist, x2=None, c_light=c_light): if x2 is not None: dist = distance(dist, x2) return dist/c_light -def beacon_from(tx, rx, f, t=0, t0=0, c_light=3e8, radiate_rsq=True, amplitude=1,**kwargs): +def beacon_from(tx, rx, f, t=0, t0=0, c_light=c_light, radiate_rsq=True, amplitude=1,**kwargs): dist = distance(tx,rx) # suppress extra time delay from distance if c_light is not None and np.isfinite(c_light): @@ -53,7 +54,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) -def remove_antenna_geometry_phase(tx, antennas, f_beacon, measured_phases=None, c_light=3e8): +def remove_antenna_geometry_phase(tx, antennas, f_beacon, measured_phases=None, c_light=c_light): """ Remove the geometrical phase from the measured antenna phase. """ @@ -110,7 +111,7 @@ def direct_fourier_transform(freqs, time, samplesets_iterable): # Numpy array return np.dot(c_k, samplesets_iterable), np.dot(s_k, samplesets_iterable) -def phase_field_from_tx(x, y, tx, f_beacon, c_light=3e8, t0=0, wrap_phase=True, return_meshgrid=True): +def phase_field_from_tx(x, y, tx, f_beacon, c_light=c_light, t0=0, wrap_phase=True, return_meshgrid=True): """ """ diff --git a/simulations/airshower_beacon_simulation/lib/tests/test_calculated_phase_measurement.py b/simulations/airshower_beacon_simulation/lib/tests/test_calculated_phase_measurement.py index 6a19b57..f36619e 100755 --- a/simulations/airshower_beacon_simulation/lib/tests/test_calculated_phase_measurement.py +++ b/simulations/airshower_beacon_simulation/lib/tests/test_calculated_phase_measurement.py @@ -17,7 +17,7 @@ seed = 12345 dt = 1 # ns frequency = 45e-3 # GHz N = 5e2 -c_light = 3e8*1e-9 +c_light = lib.c_light t = np.arange(0, 10*int(1e3), dt, dtype=float) rng = np.random.default_rng(seed)