def _core(self, path, param): """ Core function that handles one pair of asdf file(observed and synthetic), windows and configuration for adjoint source :param path: path information, path of observed asdf, synthetic asdf, windows files, observed tag, synthetic tag, output adjoint file, figure mode and figure directory :type path: dict :param param: parameter information for constructing adjoint source :type param: dict :return: """ adjoint_param = param["adjoint_config"] obsd_file = path["obsd_asdf"] synt_file = path["synt_asdf"] obsd_tag = path["obsd_tag"] synt_tag = path["synt_tag"] window_file = path["window_file"] output_filename = path["output_file"] self.check_input_file(obsd_file) self.check_input_file(synt_file) self.check_input_file(window_file) self.check_output_file(output_filename) obsd_ds = self.load_asdf(obsd_file, mode="r") synt_ds = self.load_asdf(synt_file, mode="r") windows = self.load_windows(window_file) adj_src_type = adjoint_param["adj_src_type"] adjoint_param.pop("adj_src_type", None) config = load_adjoint_config(adjoint_param, adj_src_type) if self.mpi_mode and self.rank == 0: output_ds = ASDFDataSet(output_filename, mpi=False) if output_ds.events: output_ds.events = obsd_ds.events del output_ds if self.mpi_mode: self.comm.barrier() measure_adj_func = \ partial(measure_adjoint_wrapper, config=config, obsd_tag=obsd_tag, synt_tag=synt_tag, windows=windows, adj_src_type=adj_src_type) results = obsd_ds.process_two_files(synt_ds, measure_adj_func) if self.rank == 0: print("output filename: %s" % output_filename) write_measurements(results, output_filename)
def _core(self, path, param): """ Core function that handles one pair of asdf file(observed and synthetic), windows and configuration for adjoint source :param path: path information, path of observed asdf, synthetic asdf, windows files, observed tag, synthetic tag, output adjoint file, figure mode and figure directory :type path: dict :param param: parameter information for constructing adjoint source :type param: dict :return: """ adjoint_param = param[0] postproc_param = param[1] self._validate_path(path) self._validate_param(adjoint_param) self.print_info(path, extra_info="Path information") self.print_info(adjoint_param, extra_info="Adjoint parameter information") self.print_info(postproc_param, extra_info="Postprocess parameter information") obsd_file = path["obsd_asdf"] synt_file = path["synt_asdf"] window_file = path["window_file"] output_filename = path["output_file"] self.check_input_file(obsd_file) self.check_input_file(synt_file) self.check_input_file(window_file) self.check_output_file(output_filename) obsd_ds = self.load_asdf(obsd_file, mode="r") obsd_tag = path["obsd_tag"] synt_ds = self.load_asdf(synt_file, mode="r") synt_tag = path["synt_tag"] figure_mode = path["figure_mode"] figure_dir = path["figure_dir"] event = obsd_ds.events[0] windows = self.load_windows(window_file) adj_src_type = adjoint_param["adj_src_type"] adjoint_param.pop("adj_src_type", None) config = load_adjoint_config(adjoint_param) if self.mpi_mode and self.rank == 0: output_ds = ASDFDataSet(output_filename, mpi=False) if output_ds.events: output_ds.events = obsd_ds.events del output_ds if self.mpi_mode: self.comm.barrier() adjsrc_func = \ partial(adjoint_wrapper, config=config, obsd_tag=obsd_tag, synt_tag=synt_tag, windows=windows, event=event, adj_src_type=adj_src_type, postproc_param=postproc_param, figure_mode=figure_mode, figure_dir=figure_dir) results = obsd_ds.process_two_files(synt_ds, adjsrc_func, output_filename) return results