From 47916e2e88efac6f0c4461f63022213abd9e70e5 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 2 Feb 2023 17:55:37 +0100 Subject: [PATCH] ZH: separate data-dir and input-dir on cli --- .../airshower_beacon_simulation/Makefile | 39 +++++++++++-------- .../aa_generate_beacon.py | 16 ++++++-- .../ab_modify_clocks.py | 6 +-- .../ac_show_signal_to_noise.py | 3 +- .../ba_measure_beacon_phase.py | 3 +- .../bb_measure_clock_phase.py | 3 +- .../bc_baseline_phase_deltas.py | 3 +- .../bd_antenna_phase_deltas.py | 3 +- .../ca_period_from_shower.py | 12 ++++-- ...cb_report_measured_antenna_time_offsets.py | 3 +- .../da_reconstruction.py | 12 ++++-- .../db_longitudinal_figure.py | 4 +- .../dc_grid_power_time_fixes.py | 12 ++++-- .../airshower_beacon_simulation/scriptlib.py | 4 ++ .../view_beaconed_antenna.py | 3 +- 15 files changed, 76 insertions(+), 50 deletions(-) diff --git a/simulations/airshower_beacon_simulation/Makefile b/simulations/airshower_beacon_simulation/Makefile index 1a5067d..b90d0c9 100644 --- a/simulations/airshower_beacon_simulation/Makefile +++ b/simulations/airshower_beacon_simulation/Makefile @@ -19,35 +19,40 @@ PB_HIGH ?= 0.08 REF_ANTS ?= +DATA_DIR ?= ./data +INPUT_DIR ?= ./ZH_airshower/ + all: beacon clocks phases findks vary-fixes reconstruct beacon: - ./aa_generate_beacon.py -N ${TRACE_N} -P ${TRACE_PRE} -n ${NOISE_SIGMA} -a ${BEAC_AMP} -f ${BEAC_F} -l ${PB_LOW} -u ${PB_HIGH} -d ${BEAC_DECAY} | tee ${FIG_DIR}/aa.log - ./ab_modify_clocks.py 0 | tee ${FIG_DIR}/ab.log - ./ac_show_signal_to_noise.py --no-show-plots --fig-dir=${FIG_DIR} - ./view_beaconed_antenna.py 72 -p x -p y -p z -p n -p b --ft --no-show-plots --fig-dir=${FIG_DIR} + ./aa_generate_beacon.py -N ${TRACE_N} -P ${TRACE_PRE} -n ${NOISE_SIGMA} -a ${BEAC_AMP} -f ${BEAC_F} -l ${PB_LOW} -u ${PB_HIGH} -d ${BEAC_DECAY} --data-dir ${DATA_DIR} --input-fname ${INPUT_DIR} | tee ${FIG_DIR}/aa.log + ./ab_modify_clocks.py 0 --data-dir ${DATA_DIR} | tee ${FIG_DIR}/ab.log + ./ac_show_signal_to_noise.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} + ./view_beaconed_antenna.py 72 -p x -p y -p z -p n -p b --ft --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} clocks: - ./ab_modify_clocks.py ${CLK_DEV} --gaussian + ./ab_modify_clocks.py ${CLK_DEV} --gaussian --data-dir ${DATA_DIR} phases: - ./ba_measure_beacon_phase.py --no-show-plots --fig-dir=${FIG_DIR} - ./bb_measure_clock_phase.py --no-show-plots --fig-dir=${FIG_DIR} - ./bc_baseline_phase_deltas.py ${REF_ANTS} --no-show-plots --fig-dir=${FIG_DIR} - ./bd_antenna_phase_deltas.py --no-show-plots --fig-dir=${FIG_DIR} + ./ba_measure_beacon_phase.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} + ./bb_measure_clock_phase.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} + ./bc_baseline_phase_deltas.py ${REF_ANTS} --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} + ./bd_antenna_phase_deltas.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} findks: - ./ca_period_from_shower.py --max-k ${MAX_K} --no-show-plots --fig-dir=${FIG_DIR} - ./cb_report_measured_antenna_time_offsets.py --no-show-plots --fig-dir=${FIG_DIR} + ./ca_period_from_shower.py --input-fname ${INPUT_DIR} --max-k ${MAX_K} --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} + ./cb_report_measured_antenna_time_offsets.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} vary-fixes: - ./dc_grid_power_time_fixes.py --no-show-plots --fig-dir=${FIG_DIR} + ./dc_grid_power_time_fixes.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} --input-fname ${INPUT_DIR} reconstruct: - ./da_reconstruction.py --no-show-plots --fig-dir=${FIG_DIR} - ./db_longitudinal_figure.py --no-show-plots --fig-dir=${FIG_DIR} + ./da_reconstruction.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} --input-fname ${INPUT_DIR} + ./db_longitudinal_figure.py --no-show-plots --fig-dir=${FIG_DIR} --data-dir ${DATA_DIR} dist-clean: - rm -f ZH_airshower/antennas.hdf5 - rm -f ZH_airshower/clocks.csv - rm -f ZH_airshower/tx.json + rm -vf ${DATA_DIR}/antennas.hdf5 + rm -vf ${DATA_DIR}/ca_breaked_run + rm -vf ${DATA_DIR}/res.pkl + rm -vf ${DATA_DIR}/clocks.csv + rm -vf ${DATA_DIR}/tx.json diff --git a/simulations/airshower_beacon_simulation/aa_generate_beacon.py b/simulations/airshower_beacon_simulation/aa_generate_beacon.py index 0f77fd2..2ac92a9 100755 --- a/simulations/airshower_beacon_simulation/aa_generate_beacon.py +++ b/simulations/airshower_beacon_simulation/aa_generate_beacon.py @@ -289,16 +289,24 @@ if __name__ == "__main__": parser.add_argument('-N', '--new-trace-length', type=float, help='resize airshower trace (Default: %(default)d)', default=1e4) parser.add_argument('-P', '--pre-trace-length', type=float, help='amount of trace to prepend the airshower when resizing (Default: %(default)d)', default=2e3) + # Input directory + parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)') + parser.add_argument('--data-dir', type=str, default="./ZH_airshower", help='Path to Data Directory. (Default: %(default)s)') + args = parser.parse_args() + if not args.input_fname: + args.input_fname = args.data_dir + + if path.isdir(args.input_fname): + args.input_fname = path.join(args.input_fname, "mysim.sry") + ## ## End of ArgumentParsing ## rng = np.random.default_rng() - fname = "ZH_airshower/mysim.sry" - # Noise properties noise_sigma = args.noise_sigma # mu V/m set to None to ignore @@ -337,7 +345,7 @@ if __name__ == "__main__": block_filter = lambda x, dt, low, high: x #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir tx_fname = path.join(fname_dir, tx_fname) antennas_fname = path.join(fname_dir, antennas_fname) @@ -354,7 +362,7 @@ if __name__ == "__main__": print("Noise sigma [muV/m]:", noise_sigma) # read in antennas - ev = REvent(fname) + ev = REvent(args.input_fname) N_antennas = len(ev.antennas) # initialize hdf5 file diff --git a/simulations/airshower_beacon_simulation/ab_modify_clocks.py b/simulations/airshower_beacon_simulation/ab_modify_clocks.py index 0c33300..f9e8654 100755 --- a/simulations/airshower_beacon_simulation/ab_modify_clocks.py +++ b/simulations/airshower_beacon_simulation/ab_modify_clocks.py @@ -27,6 +27,8 @@ if __name__ == "__main__": parser.add_argument('--gaussian', action='store_const', const='gauss', dest='dist_type') parser.set_defaults(dist_type='gauss') + parser.add_argument('--data-dir', type=str, default="./data", help='Path to Data Directory. (Default: %(default)s)') + args = parser.parse_args() max_clock_offset = args.max_clock_offset # ns @@ -35,10 +37,8 @@ if __name__ == "__main__": seed = 12345 rng = np.random.default_rng(seed) - fname = "ZH_airshower/mysim.sry" - #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir clocks_fname = path.join(fname_dir, clocks_fname) antennas_fname = path.join(fname_dir, beacon.antennas_fname) 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 adb1d86..1c8fad9 100755 --- a/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py +++ b/simulations/airshower_beacon_simulation/ac_show_signal_to_noise.py @@ -33,14 +33,13 @@ if __name__ == "__main__": args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) fig_dir = args.fig_dir show_plots = args.show_plots #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) tx_fname = path.join(fname_dir, beacon.tx_fname) diff --git a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py index 20e07a8..8b097d4 100755 --- a/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py +++ b/simulations/airshower_beacon_simulation/ba_measure_beacon_phase.py @@ -35,13 +35,12 @@ if __name__ == "__main__": show_plots = args.show_plots - fname = "ZH_airshower/mysim.sry" figsize = (12,8) print("use_AxB_trace:", use_AxB_trace, "use_beacon_trace:",use_beacon_trace) #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) fig_dir = args.fig_dir # set None to disable saving diff --git a/simulations/airshower_beacon_simulation/bb_measure_clock_phase.py b/simulations/airshower_beacon_simulation/bb_measure_clock_phase.py index eb324a5..a83f717 100755 --- a/simulations/airshower_beacon_simulation/bb_measure_clock_phase.py +++ b/simulations/airshower_beacon_simulation/bb_measure_clock_phase.py @@ -22,7 +22,6 @@ if __name__ == "__main__": parser = MyArgumentParser() args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) c_light = lib.c_light show_plots = args.show_plots @@ -31,7 +30,7 @@ if __name__ == "__main__": remove_absolute_phase_offset_minimum = True #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) fig_dir = args.fig_dir # set None to disable saving diff --git a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py index 84f167a..d3028c1 100755 --- a/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bc_baseline_phase_deltas.py @@ -24,14 +24,13 @@ if __name__ == "__main__": parser.add_argument('ref_ant_idx', default=None, nargs='*', type=int, help='Reference Antenna Indices for Baselines(ref_ant_idx, *). Leave empty to use all available antennas. (Default: %(default)s) ') args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) c_light = 3e8*1e-9 show_plots = args.show_plots ref_ant_id = args.ref_ant_idx # leave None for all baselines #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if False else antennas_fname diff --git a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py index 48b7685..6abd475 100755 --- a/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py +++ b/simulations/airshower_beacon_simulation/bd_antenna_phase_deltas.py @@ -25,14 +25,13 @@ if __name__ == "__main__": parser = MyArgumentParser() args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) show_plots = args.show_plots ref_ant_id = None # leave None for all baselines #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if False else antennas_fname fig_dir = args.fig_dir # set None to disable saving diff --git a/simulations/airshower_beacon_simulation/ca_period_from_shower.py b/simulations/airshower_beacon_simulation/ca_period_from_shower.py index 1ffe608..bd9ac33 100755 --- a/simulations/airshower_beacon_simulation/ca_period_from_shower.py +++ b/simulations/airshower_beacon_simulation/ca_period_from_shower.py @@ -152,9 +152,15 @@ if __name__ == "__main__": from scriptlib import MyArgumentParser parser = MyArgumentParser(default_fig_dir="./figures/periods_from_shower_figures/") parser.add_argument('--max-k', type=float, default=2, help='Maximum abs(k) allowed to be shifted. (Default: %(default)d)') + parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)') args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" + if not args.input_fname: + args.input_fname = args.data_dir + + if path.isdir(args.input_fname): + args.input_fname = path.join(args.input_fname, "mysim.sry") + figsize = (12,8) fig_dir = args.fig_dir @@ -170,7 +176,7 @@ if __name__ == "__main__": apply_signal_window_from_max = True #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if not True else antennas_fname @@ -188,7 +194,7 @@ if __name__ == "__main__": # Read in antennas from file _, tx, antennas = beacon.read_beacon_hdf5(antennas_fname) # Read original REvent - ev = REvent(fname) + ev = REvent(args.input_fname) # .. patch in our antennas ev.antennas = antennas 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 46ac28c..547216f 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 @@ -22,14 +22,13 @@ if __name__ == "__main__": parser = MyArgumentParser() args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) fig_dir = args.fig_dir # set None to disable saving show_plots = args.show_plots #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) time_diffs_fname = 'time_diffs.hdf5' if not True else antennas_fname diff --git a/simulations/airshower_beacon_simulation/da_reconstruction.py b/simulations/airshower_beacon_simulation/da_reconstruction.py index 1395913..d85d764 100755 --- a/simulations/airshower_beacon_simulation/da_reconstruction.py +++ b/simulations/airshower_beacon_simulation/da_reconstruction.py @@ -31,9 +31,15 @@ if __name__ == "__main__": from scriptlib import MyArgumentParser parser = MyArgumentParser() + parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)') args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" + if not args.input_fname: + args.input_fname = args.data_dir + + if path.isdir(args.input_fname): + args.input_fname = path.join(args.input_fname, "mysim.sry") + figsize = (12,8) fig_dir = args.fig_dir @@ -43,7 +49,7 @@ if __name__ == "__main__": remove_beacon_from_traces = True #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) pickle_fname = path.join(fname_dir, 'res.pkl') tx_fname = path.join(fname_dir, beacon.tx_fname) @@ -58,7 +64,7 @@ if __name__ == "__main__": _, tx, antennas = beacon.read_beacon_hdf5(antennas_fname) _, __, txdata = beacon.read_tx_file(tx_fname) # Read original REvent - ev = REvent(fname) + ev = REvent(args.input_fname) # .. patch in our antennas ev.antennas = antennas diff --git a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py index 63f1da2..c5da800 100755 --- a/simulations/airshower_beacon_simulation/db_longitudinal_figure.py +++ b/simulations/airshower_beacon_simulation/db_longitudinal_figure.py @@ -28,13 +28,11 @@ if __name__ == "__main__": parser = MyArgumentParser() args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" - fig_dir = args.fig_dir show_plots = args.show_plots #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) pickle_fname = path.join(fname_dir, 'res.pkl') diff --git a/simulations/airshower_beacon_simulation/dc_grid_power_time_fixes.py b/simulations/airshower_beacon_simulation/dc_grid_power_time_fixes.py index fbade2c..210e158 100755 --- a/simulations/airshower_beacon_simulation/dc_grid_power_time_fixes.py +++ b/simulations/airshower_beacon_simulation/dc_grid_power_time_fixes.py @@ -32,6 +32,7 @@ if __name__ == "__main__": from scriptlib import MyArgumentParser parser = MyArgumentParser() + parser.add_argument('--input-fname', type=str, default=None, help='Path to mysim.sry, either directory or path. If empty it takes DATA_DIR and appends mysim.sry. (Default: %(default)s)') group = parser.add_argument_group('figures') for case in valid_cases: @@ -39,12 +40,17 @@ if __name__ == "__main__": args = parser.parse_args() + if not args.input_fname: + args.input_fname = args.data_dir + + if path.isdir(args.input_fname): + args.input_fname = path.join(args.input_fname, "mysim.sry") + wanted_cases = args.figures if not wanted_cases or 'all' in wanted_cases: wanted_cases = valid_cases - fname = "ZH_airshower/mysim.sry" figsize = (12,8) fig_dir = args.fig_dir @@ -54,7 +60,7 @@ if __name__ == "__main__": apply_signal_window_from_max = True #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) pickle_fname = path.join(fname_dir, 'res.pkl') tx_fname = path.join(fname_dir, beacon.tx_fname) @@ -67,7 +73,7 @@ if __name__ == "__main__": _, tx, antennas = beacon.read_beacon_hdf5(antennas_fname) _, __, txdata = beacon.read_tx_file(tx_fname) # Read original REvent - ev = REvent(fname) + ev = REvent(args.input_fname) bak_ants = ev.antennas # .. patch in our antennas ev.antennas = antennas diff --git a/simulations/airshower_beacon_simulation/scriptlib.py b/simulations/airshower_beacon_simulation/scriptlib.py index 0edc5d6..90f0046 100644 --- a/simulations/airshower_beacon_simulation/scriptlib.py +++ b/simulations/airshower_beacon_simulation/scriptlib.py @@ -7,6 +7,7 @@ from argparse import ArgumentParser def MyArgumentParser( default_fig_dir='./figures', default_show_plots=False, + default_data_dir='./ZH_airshower', **kwargs): """ A somewhat preconfigured ArgumentParser to be shared across @@ -22,6 +23,9 @@ def MyArgumentParser( group1.add_argument('--show-plots', action='store_true', default=default_show_plots, help='Default: %(default)s') group1.add_argument('--no-show-plots', dest='show-plots', action='store_false') + # Data directory + parser.add_argument('--data-dir', type=str, default=default_data_dir, help='Path to Data Directory. (Default: %(default)s)') + # Figures directory parser.add_argument('--fig-dir', type=str, default=default_fig_dir, help='Set None to disable saving figures. (Default: %(default)s)') diff --git a/simulations/airshower_beacon_simulation/view_beaconed_antenna.py b/simulations/airshower_beacon_simulation/view_beaconed_antenna.py index 4ea412c..22ec5e5 100755 --- a/simulations/airshower_beacon_simulation/view_beaconed_antenna.py +++ b/simulations/airshower_beacon_simulation/view_beaconed_antenna.py @@ -27,7 +27,6 @@ if __name__ == "__main__": args = parser.parse_args() - fname = "ZH_airshower/mysim.sry" figsize = (12,8) plot_ft_amplitude = args.ft @@ -40,7 +39,7 @@ if __name__ == "__main__": args.polarisations = ['x','y', 'z'] #### - fname_dir = path.dirname(fname) + fname_dir = args.data_dir antennas_fname = path.join(fname_dir, beacon.antennas_fname) tx_fname = path.join(fname_dir, beacon.tx_fname)