def main(): parser = argparse.ArgumentParser() parser.add_argument('-p', action='store', dest='params_file', required=False, help="parameter file", default=None) parser.add_argument('-f', action='store', dest='path_file', required=True, help="path file") parser.add_argument('-v', action='store_true', dest='verbose', help="verbose flag") args = parser.parse_args() # Little change to accommodate the full GCMT3D path file. if args.params_file is None: # Load process path file to get parameter file location try: params_file = smart_read_yaml(args.path_file)["process_param_file"] except KeyError: print("The given path file does not contain a parameter file " "destination.") return else: params_file = args.params_file proc = ProcASDF(args.path_file, params_file, verbose=args.verbose) proc.smart_run()
def test__create_process_path_obs(self): """Testing the creation of the observed processing yaml file.""" with tempfile.TemporaryDirectory() as tmp_dir: # Cmtfile path cmtfile = os.path.join(DATA_DIR, "CMTSOLUTION") # Initialize database skeleton class DB = DataBaseSkeleton(basedir=tmp_dir, cmt_fn=cmtfile, specfem_dir=self.specfem_dir) # Create database DB.create_all() # Read the yaml_file which should be created in the CMT directory process_dir = os.path.join(DATA_DIR, "ProcessObserved") # CMT filename in database cmt_filename = os.path.join(DB.Cdirs[0], "C" + DB.Cids[0]) # Create Processing path files create_process_path_obs(cmt_filename, process_dir) # Solution output path: process_paths = os.path.join(DB.Cdirs[0], "seismograms", "process_paths") # One solution path file: process_file = os.path.join(process_paths, "process_observed.040_100.yml") # Solution should be: input_asdf = os.path.join(DB.Cdirs[0], "seismograms", "obs", "raw_observed.h5") input_tag = "obs" output_asdf = os.path.join(DB.Cdirs[0], "seismograms", "processed_seismograms", "processed_observed.040_100.h5") output_tag = "040_100_obsd" process_param_file = os.path.join(process_dir, "proc_obsd.40_100.param.yml") d = smart_read_yaml(process_file, mpi_mode=False) # Assessing correctness of yaml file self.assertTrue(d["input_asdf"] == input_asdf) self.assertTrue(d["input_tag"] == input_tag) self.assertTrue(d["output_asdf"] == output_asdf) self.assertTrue(d["output_tag"] == output_tag) self.assertTrue(d["process_param_file"] == process_param_file)
def test__create_window_path(self): """Testing the creation of the window path yaml file.""" with tempfile.TemporaryDirectory() as tmp_dir: # Cmtfile path cmtfile = os.path.join(DATA_DIR, "CMTSOLUTION") # Initialize database skeleton class DB = DataBaseSkeleton(basedir=tmp_dir, cmt_fn=cmtfile, specfem_dir=self.specfem_dir) # Create database DB.create_all() # Read the yaml_file which should be created in the CMT directory window_process_dir = os.path.join(DATA_DIR, "CreateWindows") # CMT filename in database cmt_filename = os.path.join(DB.Cdirs[0], "C" + DB.Cids[0]) # Create Processing path files create_window_path(cmt_filename, window_process_dir, figure_mode=True) # Outputdir cmt_dir = DB.Cdirs[0] # Define observed ASDF obsd_asdf = os.path.join(cmt_dir, "seismograms", "processed_seismograms", "processed_observed.040_100.h5") obsd_tag = "040_100_obsd" # Synthetic ASDF synt_asdf = os.path.join(cmt_dir, "seismograms", "processed_seismograms", "processed_synthetic_CMT.040_100.h5") synt_tag = "040_100_synt" # Output file parameters output_file = os.path.join(cmt_dir, "window_data", "windows.040_100#surface_wave.json") figure_dir = os.path.join(cmt_dir, "window_data", "window_plots.040_100#surface_wave") # window paramfile window_param_file = os.path.join(window_process_dir, "window.40_100#surface_wave." "param.yml") # Output path file path_file = os.path.join(cmt_dir, "window_data", "window_paths", "windows.040_100#surface_wave.yml") # Read written dictionary d = smart_read_yaml(path_file, mpi_mode=False) print("Solution: ", synt_asdf) print("Loaded: ", d["synt_asdf"]) # Assessing correctness of yaml file self.assertTrue(d["obsd_asdf"] == obsd_asdf) self.assertTrue(d["obsd_tag"] == obsd_tag) self.assertTrue(d["synt_asdf"] == synt_asdf) self.assertTrue(d["synt_tag"] == synt_tag) self.assertTrue(d["figure_mode"]) self.assertTrue(d["figure_dir"] == figure_dir) self.assertTrue(d["output_file"] == output_file) self.assertTrue(d["window_param_file"] == window_param_file)