ZH: introduce argparse for showing plots

This commit is contained in:
Eric Teunis de Boone 2023-01-12 14:31:21 +01:00
parent 9af9815a31
commit 8c1eb516e8
10 changed files with 68 additions and 12 deletions

View file

@ -15,7 +15,6 @@ from earsim import REvent, block_filter
import aa_generate_beacon as beacon import aa_generate_beacon as beacon
import lib import lib
if __name__ == "__main__": if __name__ == "__main__":
from os import path from os import path
import sys import sys
@ -24,10 +23,14 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
fig_dir = "./figures/" fig_dir = "./figures/"
show_plots = not False show_plots = args.show_plots
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)

View file

@ -21,14 +21,19 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') 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 f_beacon_band = (49e-3,55e-3) #GHz
allow_frequency_fitting = False allow_frequency_fitting = False
read_frequency_from_file = True 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 use_beacon_trace = True # only applicable if AxB = False
show_plots = True show_plots = args.show_plots
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"

View file

@ -18,9 +18,13 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
c_light = lib.c_light 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_first_antenna = True # takes precedence
remove_absolute_phase_offset_minimum = True remove_absolute_phase_offset_minimum = True

View file

@ -19,10 +19,14 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
c_light = 3e8*1e-9 c_light = 3e8*1e-9
show_plots = True show_plots = args.show_plots
ref_ant_id = None if not True else [50] # leave None for all baselines ref_ant_id = None if True else [50] # leave None for all baselines
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)

View file

@ -21,9 +21,13 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
show_plots = True show_plots = args.show_plots
ref_ant_id = None # leave None for all baselines ref_ant_id = None # leave None for all baselines
#### ####

View file

@ -149,11 +149,15 @@ if __name__ == "__main__":
atm = AtmoCal() atm = AtmoCal()
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
fig_dir = "./figures/periods_from_shower_figures/" fig_dir = "./figures/periods_from_shower_figures/"
fig_subdir = path.join(fig_dir, 'shifts/') fig_subdir = path.join(fig_dir, 'shifts/')
show_plots = False show_plots = args.show_plots
allowed_ks = [ -2, -1, 0, 1, 2] allowed_ks = [ -2, -1, 0, 1, 2]
Xref = 400 Xref = 400

View file

@ -18,10 +18,14 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
fig_dir = "./figures" # set None to disable saving fig_dir = "./figures" # set None to disable saving
show_plots = not False show_plots = args.show_plots
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)

View file

@ -28,11 +28,15 @@ if __name__ == "__main__":
atm = AtmoCal() atm = AtmoCal()
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
fig_dir = "./figures/" fig_dir = "./figures/"
fig_subdir = path.join(fig_dir, 'reconstruction') fig_subdir = path.join(fig_dir, 'reconstruction')
show_plots = False show_plots = args.show_plots
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)

View file

@ -24,10 +24,14 @@ if __name__ == "__main__":
if os.name == 'posix' and "DISPLAY" not in os.environ: if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use('Agg') matplotlib.use('Agg')
from scriptlib import MyArgumentParser
parser = MyArgumentParser()
args = parser.parse_args()
fname = "ZH_airshower/mysim.sry" fname = "ZH_airshower/mysim.sry"
fig_dir = "./figures/" fig_dir = "./figures/"
show_plots = False show_plots = args.show_plots
#### ####
fname_dir = path.dirname(fname) fname_dir = path.dirname(fname)

View file

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