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] 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