From 8c1eb516e8ec61da4ed7c7b4908fd08d34a86a5b Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 12 Jan 2023 14:31:21 +0100 Subject: [PATCH 1/6] ZH: introduce argparse for showing plots --- .../ac_show_signal_to_noise.py | 7 +++++-- .../ba_measure_beacon_phase.py | 9 +++++++-- .../bb_measure_true_phase.py | 6 +++++- .../bc_baseline_phase_deltas.py | 8 ++++++-- .../bd_antenna_phase_deltas.py | 6 +++++- .../ca_period_from_shower.py | 6 +++++- ...cb_report_measured_antenna_time_offsets.py | 6 +++++- .../da_reconstruction.py | 6 +++++- .../db_longitudinal_figure.py | 6 +++++- .../airshower_beacon_simulation/scriptlib.py | 20 +++++++++++++++++++ 10 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 simulations/airshower_beacon_simulation/scriptlib.py diff --git a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py index 8141abe..46aac64 100755 --- a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py +++ b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py @@ -15,7 +15,6 @@ from earsim import REvent, block_filter import aa_generate_beacon as beacon import lib - if __name__ == "__main__": from os import path import sys @@ -24,10 +23,14 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" fig_dir = "./figures/" - show_plots = not False + show_plots = args.show_plots #### fname_dir = path.dirname(fname) diff --git a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py index 7da7f03..c638e18 100755 --- a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py +++ b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py @@ -21,14 +21,19 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + parser.add_argument('--no-use-AxB', dest='use_AxB_trace', action='store_false') + args = parser.parse_args() + f_beacon_band = (49e-3,55e-3) #GHz allow_frequency_fitting = False read_frequency_from_file = True - use_AxB_trace = True if len(sys.argv) < 2 else bool(int(sys.argv[1])) + use_AxB_trace = args.use_AxB_trace use_beacon_trace = True # only applicable if AxB = False - show_plots = True + show_plots = args.show_plots fname = "ZH_airshower/mysim.sry" diff --git a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py index 0c3e6b5..b0791a2 100755 --- a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py +++ b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py @@ -18,9 +18,13 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" c_light = lib.c_light - show_plots = True + show_plots = args.show_plots remove_absolute_phase_offset_first_antenna = True # takes precedence remove_absolute_phase_offset_minimum = True diff --git a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py index 70c4512..6d78b96 100755 --- a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py @@ -19,10 +19,14 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" c_light = 3e8*1e-9 - show_plots = True - ref_ant_id = None if not True else [50] # leave None for all baselines + show_plots = args.show_plots + ref_ant_id = None if True else [50] # leave None for all baselines #### fname_dir = path.dirname(fname) diff --git a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py index 242e3fc..894780d 100755 --- a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py @@ -21,9 +21,13 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" - show_plots = True + show_plots = args.show_plots ref_ant_id = None # leave None for all baselines #### diff --git a/simulations/airshower_beacon_simulation/ca_period_from_shower.py b/simulations/airshower_beacon_simulation/ca_period_from_shower.py index 6d2aaf7..82e562c 100755 --- a/simulations/airshower_beacon_simulation/ca_period_from_shower.py +++ b/simulations/airshower_beacon_simulation/ca_period_from_shower.py @@ -149,11 +149,15 @@ if __name__ == "__main__": atm = AtmoCal() + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" fig_dir = "./figures/periods_from_shower_figures/" fig_subdir = path.join(fig_dir, 'shifts/') - show_plots = False + show_plots = args.show_plots allowed_ks = [ -2, -1, 0, 1, 2] Xref = 400 diff --git a/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py b/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py index 0f89f0d..dd5265f 100755 --- a/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py +++ b/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py @@ -18,10 +18,14 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" fig_dir = "./figures" # set None to disable saving - show_plots = not False + show_plots = args.show_plots #### fname_dir = path.dirname(fname) diff --git a/simulations/airshower_beacon_simulation/da_reconstruction.py b/simulations/airshower_beacon_simulation/da_reconstruction.py index 55cbf46..fcbd59d 100755 --- a/simulations/airshower_beacon_simulation/da_reconstruction.py +++ b/simulations/airshower_beacon_simulation/da_reconstruction.py @@ -28,11 +28,15 @@ if __name__ == "__main__": atm = AtmoCal() + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" fig_dir = "./figures/" fig_subdir = path.join(fig_dir, 'reconstruction') - show_plots = False + show_plots = args.show_plots #### fname_dir = path.dirname(fname) diff --git a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py index 980bb7d..b84f6e3 100755 --- a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py +++ b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py @@ -24,10 +24,14 @@ if __name__ == "__main__": if os.name == 'posix' and "DISPLAY" not in os.environ: matplotlib.use('Agg') + from scriptlib import MyArgumentParser + parser = MyArgumentParser() + args = parser.parse_args() + fname = "ZH_airshower/mysim.sry" fig_dir = "./figures/" - show_plots = False + show_plots = args.show_plots #### fname_dir = path.dirname(fname) diff --git a/simulations/airshower_beacon_simulation/scriptlib.py b/simulations/airshower_beacon_simulation/scriptlib.py new file mode 100644 index 0000000..766aab6 --- /dev/null +++ b/simulations/airshower_beacon_simulation/scriptlib.py @@ -0,0 +1,20 @@ +""" +Some preconfigured ArgumentParser +""" + +from argparse import ArgumentParser + +def MyArgumentParser(default_show_plots=False, **kwargs): + """ + A somewhat preconfigured ArgumentParser + + Set show_plots=True to by default enable showing plots. + """ + parser = ArgumentParser(**kwargs) + + # Whether to show plots + parser.add_argument('--show-plots', action='store_true') + parser.add_argument('--no-show-plots', dest='show-plots', action='store_false') + parser.set_defaults(show_plots=default_show_plots) + + return parser From 8ec7ab05ed8a3aa9c0012bb9f138847ecacfa04b Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 12 Jan 2023 14:49:54 +0100 Subject: [PATCH 2/6] ZH: use argparse for fig_dir --- .../airshower_beacon_simulation/ac_show_signal_to_noise.py | 2 +- .../airshower_beacon_simulation/ba_measure_beacon_phase.py | 2 +- .../airshower_beacon_simulation/bb_measure_true_phase.py | 2 +- .../airshower_beacon_simulation/bc_baseline_phase_deltas.py | 2 +- .../airshower_beacon_simulation/bd_antenna_phase_deltas.py | 2 +- .../airshower_beacon_simulation/ca_period_from_shower.py | 4 ++-- .../cb_report_measured_antenna_time_offsets.py | 2 +- .../airshower_beacon_simulation/da_reconstruction.py | 2 +- .../airshower_beacon_simulation/db_longitudinal_figure.py | 2 +- simulations/airshower_beacon_simulation/scriptlib.py | 6 +++++- 10 files changed, 15 insertions(+), 11 deletions(-) diff --git a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py index 46aac64..819b4e8 100755 --- a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py +++ b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py @@ -29,7 +29,7 @@ if __name__ == "__main__": fname = "ZH_airshower/mysim.sry" - fig_dir = "./figures/" + fig_dir = args.fig_dir show_plots = args.show_plots #### diff --git a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py index c638e18..a1ecd4a 100755 --- a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py +++ b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py @@ -43,7 +43,7 @@ if __name__ == "__main__": fname_dir = path.dirname(fname) antennas_fname = path.join(fname_dir, beacon.antennas_fname) - fig_dir = "./figures" # set None to disable saving + fig_dir = args.fig_dir # set None to disable saving if not path.isfile(antennas_fname): print("Antenna file cannot be found, did you try generating a beacon?") diff --git a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py index b0791a2..a040a73 100755 --- a/simulations/airshower_beacon_simulation/bb_measure_true_phase.py +++ b/simulations/airshower_beacon_simulation/bb_measure_true_phase.py @@ -33,7 +33,7 @@ if __name__ == "__main__": fname_dir = path.dirname(fname) antennas_fname = path.join(fname_dir, beacon.antennas_fname) - fig_dir = "./figures" # set None to disable saving + fig_dir = args.fig_dir # set None to disable saving if not path.isfile(antennas_fname): print("Antenna file cannot be found, did you try generating a beacon?") diff --git a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py index 6d78b96..725aa4b 100755 --- a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py @@ -33,7 +33,7 @@ if __name__ == "__main__": antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if False else antennas_fname - fig_dir = "./figures" # set None to disable saving + fig_dir = args.fig_dir # set None to disable saving if not path.isfile(antennas_fname): print("Antenna file cannot be found, did you try generating a beacon?") diff --git a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py index 894780d..da1da20 100755 --- a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py @@ -34,7 +34,7 @@ if __name__ == "__main__": fname_dir = path.dirname(fname) antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if False else antennas_fname - fig_dir = "./figures" # set None to disable saving + fig_dir = args.fig_dir # set None to disable saving basenames, time_diffs, f_beacons, true_phase_diffs, k_periods = beacon.read_baseline_time_diffs_hdf5(time_diffs_fname) diff --git a/simulations/airshower_beacon_simulation/ca_period_from_shower.py b/simulations/airshower_beacon_simulation/ca_period_from_shower.py index 82e562c..cd5da35 100755 --- a/simulations/airshower_beacon_simulation/ca_period_from_shower.py +++ b/simulations/airshower_beacon_simulation/ca_period_from_shower.py @@ -150,12 +150,12 @@ if __name__ == "__main__": atm = AtmoCal() from scriptlib import MyArgumentParser - parser = MyArgumentParser() + parser = MyArgumentParser(default_fig_dir="./figures/periods_from_shower_figures/") args = parser.parse_args() fname = "ZH_airshower/mysim.sry" - fig_dir = "./figures/periods_from_shower_figures/" + fig_dir = args.fig_dir fig_subdir = path.join(fig_dir, 'shifts/') show_plots = args.show_plots diff --git a/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py b/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py index dd5265f..367b521 100755 --- a/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py +++ b/simulations/airshower_beacon_simulation/cb_report_measured_antenna_time_offsets.py @@ -24,7 +24,7 @@ if __name__ == "__main__": fname = "ZH_airshower/mysim.sry" - fig_dir = "./figures" # set None to disable saving + fig_dir = args.fig_dir # set None to disable saving show_plots = args.show_plots #### diff --git a/simulations/airshower_beacon_simulation/da_reconstruction.py b/simulations/airshower_beacon_simulation/da_reconstruction.py index fcbd59d..b7937a6 100755 --- a/simulations/airshower_beacon_simulation/da_reconstruction.py +++ b/simulations/airshower_beacon_simulation/da_reconstruction.py @@ -34,7 +34,7 @@ if __name__ == "__main__": fname = "ZH_airshower/mysim.sry" - fig_dir = "./figures/" + fig_dir = args.fig_dir fig_subdir = path.join(fig_dir, 'reconstruction') show_plots = args.show_plots diff --git a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py index b84f6e3..63f1da2 100755 --- a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py +++ b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py @@ -30,7 +30,7 @@ if __name__ == "__main__": fname = "ZH_airshower/mysim.sry" - fig_dir = "./figures/" + fig_dir = args.fig_dir show_plots = args.show_plots #### diff --git a/simulations/airshower_beacon_simulation/scriptlib.py b/simulations/airshower_beacon_simulation/scriptlib.py index 766aab6..165f32f 100644 --- a/simulations/airshower_beacon_simulation/scriptlib.py +++ b/simulations/airshower_beacon_simulation/scriptlib.py @@ -4,11 +4,12 @@ Some preconfigured ArgumentParser from argparse import ArgumentParser -def MyArgumentParser(default_show_plots=False, **kwargs): +def MyArgumentParser(default_fig_dir='./figures', default_show_plots=False, **kwargs): """ A somewhat preconfigured ArgumentParser Set show_plots=True to by default enable showing plots. + Likewise, set fig_dir=None to by default disable saving figures. """ parser = ArgumentParser(**kwargs) @@ -17,4 +18,7 @@ def MyArgumentParser(default_show_plots=False, **kwargs): parser.add_argument('--no-show-plots', dest='show-plots', action='store_false') parser.set_defaults(show_plots=default_show_plots) + # Figures directory + parser.add_argument('--fig-dir', type=str, default=default_fig_dir) + return parser From 25a5539a81df234f11104c15639691b6def746d9 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 12 Jan 2023 14:59:00 +0100 Subject: [PATCH 3/6] ZH: update Makefile to use fig_dir args --- .../airshower_beacon_simulation/Makefile | 28 +++++++++++++------ .../airshower_beacon_simulation/README.md | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/simulations/airshower_beacon_simulation/Makefile b/simulations/airshower_beacon_simulation/Makefile index 034c0fb..cbdbbec 100644 --- a/simulations/airshower_beacon_simulation/Makefile +++ b/simulations/airshower_beacon_simulation/Makefile @@ -1,22 +1,32 @@ .PHONY: all -all: beacon clocks + +FIG_DIR := ./figures + +all: beacon clocks phases findks reconstruct beacon: - ./aa_generate_beacon.py + ./aa_generate_beacon.py > figures/aa.log + ./ab_modify_clocks.py 0 > figures/ab.log + ./ac_show_signal_to_noise.py --no-show-plots --fig-dir=${FIG_DIR} clocks: - ./ab_modify_clocks.py + ./ab_modify_clocks.py 15 phases: - ./ba_measure_beacon_phase.py - ./bb_measure_true_phase.py - ./bc_baseline_phase_deltas.py - ./bd_antenna_phase_deltas.py + ./ba_measure_beacon_phase.py --no-show-plots --fig-dir=${FIG_DIR} + ./bb_measure_true_phase.py --no-show-plots --fig-dir=${FIG_DIR} + ./bc_baseline_phase_deltas.py --no-show-plots --fig-dir=${FIG_DIR} + ./bd_antenna_phase_deltas.py --no-show-plots --fig-dir=${FIG_DIR} -period_multiples: - ./ca_periods_from_shower.py +findks: + ./ca_period_from_shower.py --no-show-plots --fig-dir=${FIG_DIR} + ./cb_report_measured_antenna_time_offsets.py --no-show-plots --fig-dir=${FIG_DIR} + +reconstruct: + ./da_reconstruction.py --no-show-plots --fig-dir=${FIG_DIR} + ./db_longitudinal_figure.py --no-show-plots --fig-dir=${FIG_DIR} dist-clean: rm -f ZH_airshower/antennas.hdf5 diff --git a/simulations/airshower_beacon_simulation/README.md b/simulations/airshower_beacon_simulation/README.md index 65f7226..5d1a989 100644 --- a/simulations/airshower_beacon_simulation/README.md +++ b/simulations/airshower_beacon_simulation/README.md @@ -30,4 +30,4 @@ Steps: 3. Find k\*2\\pi phase offsets (periods) ([./ca_periods_from_showers.py]) - 4. Rewrite clocks + 4. Rewrite clocks and do interferometric reconstruction ([./da_reconstruction.py]) From 031e21636d43b94736bb6b8c010488bd9d35d340 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Fri, 13 Jan 2023 16:23:15 +0100 Subject: [PATCH 4/6] ZH: cli arguments for beacon generation --- .../aa_generate_beacon.py | 86 ++++++++++++------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index 64ea898..aff1098 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -241,36 +241,44 @@ def write_baseline_time_diffs_hdf5(fname, baselines, true_phase_diffs, k_periods if __name__ == "__main__": from os import path + from argparse import ArgumentParser + + parser = ArgumentParser() + parser.add_argument('-n', '--noise-sigma', type=float, default=1e3, help='in [muV/m]') + parser.add_argument('-f', '--beacon-frequency', type=float, default=51.53e-3, help='The beacon\'s frequency [GHz]') + + # Beacon Properties + parser.add_argument('-a', '--beacon-amplitudes', type=float, nargs=3, default=[1e3, 0, 0], help='in [muV/m]') + parser.add_argument('-d', '--beacon-rsq-decay', type=bool, default=True, help='Use Beacon amplitudes at 0,0,0') + + # Bandpass + parser.add_argument('-p', '--use-passband', type=bool, default=True) + parser.add_argument('-l', '--passband-low', type=float, default=30e-3, help='Lower frequency [GHz] of the passband filter. (set -1 for np.inf)') + parser.add_argument('-u', '--passband-high', type=float, default=80e-3, help='Upper frequency [GHz] of the passband filter. (set -1 for np.inf)') + + # Trace length modification + parser.add_argument('-N', '--new-trace-length', type=float, help='resize airshower trace', default=1e4) + parser.add_argument('-P', '--pre-trace-length', type=float, help='amount of trace to prepend the airshower when resizing', default=2e3) + + args = parser.parse_args() + + ## + ## End of ArgumentParsing + ## rng = np.random.default_rng() fname = "ZH_airshower/mysim.sry" - # Transmitter - remake_tx = True - - tx = Antenna(x=-2e3,y=0,z=0,name='tx') # m - if False: - # 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 + # Noise properties + noise_sigma = args.noise_sigma # mu V/m set to None to ignore # Beacon properties - if False: # slowest beacon to be found: - f_beacon = 10e-3 # GHz - low_bp = 5e-3 # GHz - high_bp = 80e-3 # GHz - else: # original wanted beacon - f_beacon = 51.53e-3 # GHz + beacon_amplitudes = np.array(args.beacon_amplitudes) # mu V/m + beacon_radiate_rsq = args.beacon_rsq_decay # beacon_amplitude is repaired for distance to 0,0,0 - # Bandpass for E field blockfilter - low_bp = 30e-3 # GHz - high_bp = 80e-3 # GHz - - beacon_amplitudes = 1e-6*np.array([1e3, 0, 0]) # mu V/m - beacon_radiate_rsq = True # beacon_amplitude is repaired for distance to 0,0,0 + # Beacon properties + f_beacon = args.beacon_frequency # GHz # modify beacon power to be beacon_amplitude at 0,0,0 if beacon_radiate_rsq: @@ -280,11 +288,23 @@ if __name__ == "__main__": beacon_amplitudes *= ampl - # Noise properties - noise_sigma = 1e-4 # set to None to ignore + # Transmitter + remake_tx = True - # Disable block_filter - if False: + tx = Antenna(x=0,y=0,z=0,name='tx') # m + if True: + # 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 + + # Bandpass for E field blockfilter + low_bp = args.passband_low if args.passband_low >= 0 else np.inf # GHz + high_bp = args.passband_high if args.passband_high >= 0 else np.inf # GHz + + # Enable/Disable block_filter + if not args.use_passband: block_filter = lambda x, dt, low, high: x #### @@ -300,8 +320,9 @@ if __name__ == "__main__": print("Beacon amplitude at tx [muV/m]:", beacon_amplitudes) + print("Beacon amplitude at 0,0,0 [muV/m]:", beacon_amplitudes/ampl) print("Tx location:", [tx.x, tx.y, tx.z]) - print("Noise sigma:", noise_sigma) + print("Noise sigma [muV/m]:", noise_sigma) # read in antennas ev = REvent(fname) @@ -315,11 +336,10 @@ if __name__ == "__main__": if i%10 == 0: print(f"Beaconed antenna {i} out of", len(ev.antennas)) - if not False: # modify trace lengths + if args.new_trace_length: # modify trace lengths N_samples = len(antenna.t) - #new_N = 2*N_samples - new_N = 10000 # ns = 10us - pre_N = 2000 # ns = 2us + new_N = int(args.new_trace_length) + pre_N = int(args.pre_trace_length) after_N = new_N - pre_N dt = antenna.t[1] - antenna.t[0] @@ -335,12 +355,12 @@ if __name__ == "__main__": if i%10 == 0: print(f"Modified trace lengths by {pre_N},{after_N-N_samples}") - beacon = lib.beacon_from(tx, antenna, f_beacon, antenna.t, c_light=c_light, radiate_rsq=beacon_radiate_rsq) + beacon = 1e-6 * lib.beacon_from(tx, antenna, f_beacon, antenna.t, c_light=c_light, radiate_rsq=beacon_radiate_rsq) # mu V/m # noise realisation noise_realisation = 0 if noise_sigma is not None: - noise_realisation = rng.normal(0, noise_sigma, size=len(beacon)) + noise_realisation = 1e-6 * rng.normal(0, noise_sigma, size=len(beacon)) # mu V/m # Collect all data to be saved (with the first 3 values the E fields) traces = np.array([antenna.Ex, antenna.Ey, antenna.Ez, beacon, noise_realisation]) From 7b18837d6d3f4797b31eb8955cd381d0b82a63cd Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Fri, 13 Jan 2023 17:07:18 +0100 Subject: [PATCH 5/6] ZH: cli arguments for clock modification --- simulations/airshower_beacon_simulation/Makefile | 2 +- .../ab_modify_clocks.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/simulations/airshower_beacon_simulation/Makefile b/simulations/airshower_beacon_simulation/Makefile index cbdbbec..7528db2 100644 --- a/simulations/airshower_beacon_simulation/Makefile +++ b/simulations/airshower_beacon_simulation/Makefile @@ -12,7 +12,7 @@ beacon: ./ac_show_signal_to_noise.py --no-show-plots --fig-dir=${FIG_DIR} clocks: - ./ab_modify_clocks.py 15 + ./ab_modify_clocks.py 15 --gaussian phases: ./ba_measure_beacon_phase.py --no-show-plots --fig-dir=${FIG_DIR} diff --git a/simulations/airshower_beacon_simulation/ab_modify_clocks.py b/simulations/airshower_beacon_simulation/ab_modify_clocks.py index 413b03a..51c7e78 100755 --- a/simulations/airshower_beacon_simulation/ab_modify_clocks.py +++ b/simulations/airshower_beacon_simulation/ab_modify_clocks.py @@ -19,7 +19,17 @@ if __name__ == "__main__": from os import path import sys - max_clock_offset = 100 if len(sys.argv) < 2 else float(sys.argv[1]) # ns + from argparse import ArgumentParser + + parser = ArgumentParser() + parser.add_argument('max_clock_offset', nargs='?', type=float, default=25, help='(Default: %(default)d)') + parser.add_argument('--uniform', action='store_const', const='uniform', dest='dist_type') + parser.add_argument('--gaussian', action='store_const', const='gauss', dest='dist_type') + parser.set_defaults(dist_type='gauss') + + args = parser.parse_args() + + max_clock_offset = args.max_clock_offset # ns remake_clock_offsets = True seed = 12345 @@ -54,7 +64,7 @@ if __name__ == "__main__": if True: print(f"Modifying clocks upto {max_clock_offset}ns.") clock_offsets = np.zeros( N_antennas ) - if not True: # uniform + if args.dist_type == 'uniform': # uniform print("Uniform distribution") clock_offsets = max_clock_offset * (2*rng.uniform(size=N_antennas) - 1) else: # normal From 967ed3d2326bed4488550e0d8e790fd7eafdbe5d Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Fri, 13 Jan 2023 17:53:07 +0100 Subject: [PATCH 6/6] ZH: cli arguments to snr script --- .../ac_show_signal_to_noise.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py index 819b4e8..d189559 100755 --- a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py +++ b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py @@ -25,6 +25,12 @@ if __name__ == "__main__": from scriptlib import MyArgumentParser parser = MyArgumentParser() + + # Bandpass + parser.add_argument('-p', '--use-passband', type=bool, default=True) + parser.add_argument('-l', '--passband-low', type=float, default=30e-3, help='Lower frequency [GHz] of the passband filter. (set -1 for np.inf)') + parser.add_argument('-u', '--passband-high', type=float, default=80e-3, help='Upper frequency [GHz] of the passband filter. (set -1 for np.inf)') + args = parser.parse_args() fname = "ZH_airshower/mysim.sry" @@ -47,12 +53,15 @@ if __name__ == "__main__": # general properties dt = antennas[0].t[1] - antennas[0].t[0] # ns - pb = lib.passband(30e-3, 80e-3) # GHz beacon_pb = lib.passband(f_beacon-1e-3, f_beacon+1e-3) # GHz - beacon_amp = np.max(txdata['amplitudes'])# mu V/m - if True: # Apply filter to raw beacon/noise to compare with Filtered Traces + # General Bandpass + low_bp = args.passband_low if args.passband_low >= 0 else np.inf # GHz + high_bp = args.passband_high if args.passband_high >= 0 else np.inf # GHz + pb = lib.passband(low_bp, high_bp) # GHz + + if args.use_passband: # Apply filter to raw beacon/noise to compare with Filtered Traces myfilter = lambda x: block_filter(x, dt, pb[0], pb[1]) else: # Compare raw beacon/noise with Filtered Traces myfilter = lambda x: x