def write_new_synt_asdf(self, file_prefix): new_synt_dict = self._sort_new_synt() for tag, win_array in new_synt_dict.iteritems(): filename = "%s.%s.h5" % (file_prefix, tag) if os.path.exists(filename): os.remove(filename) logger.info("Output file exists, removed: %s" % filename) else: logger.info("Output new synt asdf: %s" % filename) ds = ASDFDataSet(filename, mode='w') added_list = [] for window in win_array: synt_id = window.datalist['new_synt'].id # skip duplicate obsd location id. # for example, II.AAK.00.BHZ and II.AAK.10.BHZ will # be treated as different traces. But the synt and # new synt will be the same. So we only add one if synt_id in added_list: continue else: added_list.append(synt_id) ds.add_waveforms(window.datalist['new_synt'], tag=tag) # add stationxml _staxml_asdf = self._asdf_file_dict['synt'] ds_sta = ASDFDataSet(_staxml_asdf) self.__add_staxml_from_other_asdf(ds, ds_sta) ds.flush()
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"] postproc_param = param["process_config"] 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, adj_src_type) if self.mpi_mode and self.rank == 0: output_ds = ASDFDataSet(output_filename, mpi=False) if obsd_ds.events: output_ds.events = obsd_ds.events output_ds.flush() 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