def test_no_adjoint_src_calculation_is_honored(adj_src): """ If no adjoint source is requested, it should not be returned/calculated. """ config = pyadjoint.Config(min_period=30.0, max_period=75.0, lnpt=15, transfunc_waterlevel=1.0E-10, water_threshold=0.02, ipower_costaper=10, min_cycle_in_window=3, taper_percentage=0.3, taper_type='hann', mt_nw=4, phase_step=1.5, use_cc_error=False, use_mt_error=False) obs, syn = pyadjoint.utils.get_example_data() obs = obs.select(component="Z")[0] syn = syn.select(component="Z")[0] window = [[2076., 2418.0]] a_src = pyadjoint.calculate_adjoint_source(adj_src_type=adj_src, observed=obs, synthetic=syn, config=config, window=window, adjoint_src=False, plot=False) # start, end = pyadjoint.utils.EXAMPLE_DATA_PDIFF # a_src = pyadjoint.calculate_adjoint_source( # adj_src, obs, syn, 20, 100, start, end, adjoint_src=False) assert a_src.adjoint_source is None
def load_adjoint_config(config): """ Load config into pyadjoint.Config :param param: :return: """ check_config_keywords(config) return pyadjoint.Config(**config)
def load_adjoint_config_yaml(filename): """ load yaml and setup pyadjoint.Config object """ with open(filename) as fh: data = yaml.load(fh) if data["min_period"] > data["max_period"]: raise ValueError("min_period is larger than max_period in config " "file: %s" % filename) return pyadjoint.Config(**data)
def test_normal_adjoint_source_calculation(adj_src): """ Make sure everything at least runs. Executed for every adjoint source type. """ config = pyadjoint.Config(min_period=30.0, max_period=75.0, lnpt=15, transfunc_waterlevel=1.0E-10, water_threshold=0.02, ipower_costaper=10, min_cycle_in_window=3, taper_percentage=0.3, taper_type='hann', mt_nw=4, phase_step=1.5, use_cc_error=False, use_mt_error=False) obs, syn = pyadjoint.utils.get_example_data() obs = obs.select(component="Z")[0] syn = syn.select(component="Z")[0] # start, end = pyadjoint.utils.EXAMPLE_DATA_PDIFF window = [[2076., 2418.0]] a_src = pyadjoint.calculate_adjoint_source(adj_src_type=adj_src, observed=obs, synthetic=syn, config=config, window=window, adjoint_src=True, plot=False) # a_src = pyadjoint.calculate_adjoint_source( # adj_src, obs, syn, 20, 100, start, end) assert a_src.adjoint_source.any() assert a_src.misfit >= 0.0 assert isinstance(a_src.adjoint_source, np.ndarray)
def load_adjoint_config(param): adj_src_type = param["adj_src_type"] param.pop("adj_src_type", None) config = pyadjoint.Config(**param) return config, adj_src_type
def write_adjoint_traces(misfit_type, misfit_parameters, filter_parameters, paths, obs_tag, syn_tag): """ Makes misfit measurements using observed and synthetic data; writes out misfit values and corresponding "adjoint sources" :param misfit_type: type of data misfit function, e.g. waveform_difference, multitaper_misfit :param misfit_parameters: dictionary passed directly to pyadjoint.Config :param paths.obs: ASDF observed data filename :param paths.syn: ASDF synthetic data filename :param paths.windows: JSON windows filename :param paths.adjoint_sources: adjoint_sources will be written to an ASDF file with this name :param paths.misfit: misfit values will be written a JSON file with this name :param obs_tag: observed data are read using this ASDF tag :param syn_tag: synthetic data are read using this ASDF tag """ from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.rank cwd = dirname(__file__) # read data fullpath = join(cwd, paths.obs) obs = pyasdf.ASDFDataSet(fullpath, compression=None, mode="a") event = obs.events[0] # read synthetics fullpath = join(cwd, paths.syn) syn = pyasdf.ASDFDataSet(fullpath, compression=None, mode="a") # read windows fullpath = join(cwd, paths.windows) windows = read_json_mpi(paths.windows, comm) # generate pyadjoint.Config objects config = pyadjoint.Config(**misfit_parameters) # wrapper is required for ASDF processing def wrapped_function(obs, syn): # TODO: modify pytomo3d to make the following # function call more readable? return pytomo3d.adjoint.calculate_and_process_adjsrc_on_stream( obs[obs_tag], syn[syn_tag], windows[obs._station_name], obs.StationXML, config, event, misfit_type, filter_parameters, figure_mode=False, figure_dir=None) adjoint_sources = obs.process_two_files_without_parallel_output( syn, wrapped_function) if rank == 0: # save as ASDF waveforms ds = pyasdf.ASDFDataSet(paths.adjoint_sources, mpi=False, mode="a") tag = 'processed_adjoint' add_adjoint_source_waveforms(ds, adjoint_sources, tag) del ds # write misfit pass