def parse_arguments(): """ This function takes care of parsing the command-line arguments and asking the user for any missing parameters that we need """ parser = argparse.ArgumentParser(description="Calculates the GOF " "from a pair or timeseries files or " "from a list of timeseries.") parser.add_argument("--obs", dest="obs_file", help="input file containing recorded data") parser.add_argument("--syn", action="append", dest="syn_files", help="input files containing synthetic data") parser.add_argument("--leading", type=float, dest="leading", help="leading time for the simulation (seconds)") parser.add_argument("--eq-time", dest="eq_time", help="earthquake start time (HH:MM:SS.CCC)") parser.add_argument("--azimuth", type=float, dest="azimuth", help="azimuth for rotation (degrees)") parser.add_argument("--dt", type=float, dest="commondt", help="common dt for the signals") parser.add_argument("--decimation-freq", type=float, dest="decifmax", help="maximum frequency for decimation") parser.add_argument("--bands", dest="bands", help="sequence of sample rates") parser.add_argument("--output-dir", dest="outdir", help="output directory for the outputs") parser.add_argument("--scores", dest="s_path", help="scores file") parser.add_argument("--metrics", dest="m_path", help="metrics file") parser.add_argument("--list", dest="filelist", help="list containing files to use") parser.add_argument("--input_dir", action="append", dest="indirs", help="input directories for the files in the list") parser.add_argument("--epicenter_x", type=float, dest="epicenter_x", help="epicenter coordinates") parser.add_argument("--epicenter_y", type=float, dest="epicenter_y", help="epicenter coordinates") args = parser.parse_args() # Parameters from the user params = {} # Figure out if we have a pair or timeseries or a list of files to use if args.filelist is not None and (args.obs_file is not None or args.syn_files is not None): print("[ERROR]: Specify either list or pair or files!") sys.exit(-1) if args.filelist is not None: # List of files is provided params["filelist"] = args.filelist if args.indirs is None: params["indir1"], params["indir2"] = get_in() else: if len(args.indirs) == 2: params["indir1"] = args.indirs[0] params["indir2"] = args.indirs[1] else: print("[ERROR]: Please specify 2 input directories!") sys.exit(-1) else: # A pair of files if args.obs_file is not None: len_obs = 1 else: len_obs = 0 if args.syn_files is not None: len_syn = len(args.syn_files) else: len_syn = 0 # we need two (and only two!) input files if len_obs + len_syn != 2: print("[ERROR]: Please specify 2 input files with obs_files " "or syn_files!") sys.exit(-1) params["obs_file"] = args.obs_file params["syn_files"] = args.syn_files # Ask user for any missing input parameters if args.outdir is None or args.s_path is None or args.m_path is None: params['outdir'], params['s_path'], params['m_path'] = get_out() else: params['outdir'] = args.outdir params['s_path'] = os.path.join(args.outdir, args.s_path) params['m_path'] = os.path.join(args.outdir, args.m_path) if args.bands is None: params['bands'] = get_bands() else: freqs = args.bands.replace(',', ' ').split() if len(freqs) < 2: print("[ERROR]: Invalid frequencies!") sys.exit(-1) try: freqs = [float(freq) for freq in freqs] except ValueError: print("[ERROR]: Invalid frequencies") for i in range(0, len(freqs)-1): if freqs[i] >= freqs[i+1]: print("[ERROR]: Invalid sequence of sample rates") params['bands'] = freqs if args.decifmax is None: params['decifmax'] = get_fmax() else: params['decifmax'] = args.decifmax if args.commondt is None: params['commondt'] = get_dt() else: params['commondt'] = args.commondt if args.azimuth is None: params['azimuth'] = get_azimuth() else: params['azimuth'] = args.azimuth if args.eq_time is None: params['eq_time'] = get_earthq() else: tokens = args.eq_time.split(':') if len(tokens) < 3: print("[ERROR]: Invalid time format!") sys.exit(-1) try: params['eq_time'] = [float(token) for token in tokens] except ValueError: print("[ERROR]: Invalid time format!") sys.exit(-1) if args.leading is None: params['leading'] = get_leading() else: params['leading'] = args.leading # Optional params['epi_x'] = args.epicenter_x params['epi_y'] = args.epicenter_y return params
def parse_arguments(): """ This function takes care of parsing the command-line arguments and asking the user for any missing parameters that we need """ parser = argparse.ArgumentParser(description="Processes a number of " "timeseries files and prepares them " "for plotting.") parser.add_argument("--obs", dest="obs_file", help="input file containing recorded data") parser.add_argument("--leading", type=float, dest="leading", help="leading time for the simulation (seconds)") parser.add_argument("--eq-time", dest="eq_time", help="earthquake start time (HH:MM:SS.CCC)") parser.add_argument("--azimuth", type=float, dest="azimuth", help="azimuth for rotation (degrees)") parser.add_argument("--dt", type=float, dest="commondt", help="common dt for the signals") parser.add_argument("--decimation-freq", type=float, dest="decifmax", help="maximum frequency for decimation") parser.add_argument("--bands", dest="bands", help="sequence of sample rates") parser.add_argument("--output-dir", dest="outdir", help="output directory for the outputs") parser.add_argument('input_files', nargs='*') args = parser.parse_args() # Input files files = args.input_files obs_file = args.obs_file if len(files) < 1 or len(files) == 1 and obs_file is None: print("[ERROR]: Please provide at least two timeseries to process!") sys.exit(-1) # Ask user for any missing input parameters params = {} if args.outdir is None: params['outdir'] = get_out() else: params['outdir'] = args.outdir if args.bands is None: params['bands'] = get_bands() else: freqs = args.bands.replace(',', ' ').split() if len(freqs) < 2: print("[ERROR]: Invalid frequencies!") sys.exit(-1) try: freqs = [float(freq) for freq in freqs] except ValueError: print("[ERROR]: Invalid frequencies") for i in range(0, len(freqs)-1): if freqs[i] >= freqs[i+1]: print("[ERROR]: Invalid sequence of sample rates") params['bands'] = freqs if args.decifmax is None: params['decifmax'] = get_fmax() else: params['decifmax'] = args.decifmax if args.commondt is None: params['commondt'] = get_dt() else: params['commondt'] = args.commondt if args.azimuth is None: params['azimuth'] = get_azimuth() else: params['azimuth'] = args.azimuth if args.eq_time is None: params['eq_time'] = get_earthq() else: tokens = args.eq_time.split(':') if len(tokens) < 3: print("[ERROR]: Invalid time format!") sys.exit(-1) try: params['eq_time'] = [float(token) for token in tokens] except ValueError: print("[ERROR]: Invalid time format!") sys.exit(-1) if args.leading is None: params['leading'] = get_leading() else: params['leading'] = args.leading return obs_file, files, params
def parse_arguments(): """ This function takes care of parsing the command-line arguments and asking the user for any missing parameters that we need """ parser = argparse.ArgumentParser(description="Processes a numer of " "timeseries files and prepares them " "for plotting.") parser.add_argument("--obs", dest="obs_file", help="input file containing recorded data") parser.add_argument("--leading", type=float, dest="leading", help="leading time for the simulation (seconds)") parser.add_argument("--eq-time", dest="eq_time", help="earthquake start time (HH:MM:SS.CCC)") parser.add_argument("--azimuth", type=float, dest="azimuth", help="azimuth for rotation (degrees)") parser.add_argument("--dt", type=float, dest="commondt", help="common dt for the signals") parser.add_argument("--decimation-freq", type=float, dest="decifmax", help="maximum frequency for decimation") parser.add_argument("--bands", dest="bands", help="sequence of sample rates") parser.add_argument("--output-dir", dest="outdir", help="output directory for the outputs") parser.add_argument('input_files', nargs='*') args = parser.parse_args() # Input files files = args.input_files obs_file = args.obs_file if len(files) < 1 or len(files) == 1 and obs_file is None: print("[ERROR]: Please provide at least two timeseries to process!") sys.exit(-1) # Ask user for any missing input parameters params = {} if args.outdir is None: params['outdir'] = get_out() else: params['outdir'] = args.outdir if args.bands is None: params['bands'] = get_bands() else: freqs = args.bands.replace(',', ' ').split() if len(freqs) < 2: print("[ERROR]: Invalid frequencies!") sys.exit(-1) try: freqs = [float(freq) for freq in freqs] except ValueError: print("[ERROR]: Invalid frequencies") for i in range(0, len(freqs)-1): if freqs[i] >= freqs[i+1]: print("[ERROR]: Invalid sequence of sample rates") params['bands'] = freqs if args.decifmax is None: params['decifmax'] = get_fmax() else: params['decifmax'] = args.decifmax if args.commondt is None: params['commondt'] = get_dt() else: params['commondt'] = args.commondt if args.azimuth is None: params['azimuth'] = get_azimuth() else: params['azimuth'] = args.azimuth if args.eq_time is None: params['eq_time'] = get_earthq() else: tokens = args.eq_time.split(':') if len(tokens) < 3: print("[ERROR]: Invalid time format!") sys.exit(-1) try: params['eq_time'] = [float(token) for token in tokens] except ValueError: print("[ERROR]: Invalid time format!") sys.exit(-1) if args.leading is None: params['leading'] = get_leading() else: params['leading'] = args.leading return obs_file, files, params