Example #1
0
def forward(rundir_or_config_path, event_names):

    if not event_names:
        return

    if op.isdir(rundir_or_config_path):
        rundir = rundir_or_config_path
        config = read_config(op.join(rundir, 'config.yaml'))

        problem, xs, misfits, _ = load_problem_info_and_data(
            rundir, subset='harvest')

        gms = problem.combine_misfits(misfits)
        ibest = num.argmin(gms)
        xbest = xs[ibest, :]

        ds = config.get_dataset(problem.base_source.name)
        problem.set_engine(config.engine_config.get_engine())

        for target in problem.targets:
            target.set_dataset(ds)

        payload = [(problem, xbest)]

    else:
        config = read_config(rundir_or_config_path)

        payload = []
        for event_name in event_names:
            ds = config.get_dataset(event_name)
            event = ds.get_event()
            problem = config.get_problem(event)
            xref = problem.preconstrain(
                problem.pack(problem.base_source))
            payload.append((problem, xref))

    all_trs = []
    events = []
    for (problem, x) in payload:
        ds.empty_cache()
        results = problem.evaluate(x)

        event = problem.get_source(x).pyrocko_event()
        events.append(event)

        for result in results:
            if isinstance(result, WaveformMisfitResult):
                result.filtered_obs.set_codes(location='ob')
                result.filtered_syn.set_codes(location='sy')
                all_trs.append(result.filtered_obs)
                all_trs.append(result.filtered_syn)

    markers = []
    for ev in events:
        markers.append(pmarker.EventMarker(ev))

    trace.snuffle(all_trs, markers=markers, stations=ds.get_stations())
Example #2
0
def forward(env, show='filtered'):
    payload = []
    if env.have_rundir():
        env.setup_modelling()
        history = env.get_history(subset='harvest')
        xbest = history.get_best_model()
        problem = env.get_problem()
        ds = env.get_dataset()
        payload.append((ds, problem, xbest))

    else:
        for event_name in env.get_selected_event_names():
            env.set_current_event_name(event_name)
            env.setup_modelling()
            problem = env.get_problem()
            ds = env.get_dataset()
            xref = problem.preconstrain(problem.get_reference_model())
            payload.append((ds, problem, xref))

    all_trs = []
    events = []
    stations = {}
    for (ds, problem, x) in payload:
        results = problem.evaluate(x)

        event = problem.get_source(x).pyrocko_event()
        events.append(event)

        for result in results:
            if isinstance(result, WaveformMisfitResult):
                if show == 'filtered':
                    result.filtered_obs.set_codes(location='ob')
                    result.filtered_syn.set_codes(location='sy')
                    all_trs.append(result.filtered_obs)
                    all_trs.append(result.filtered_syn)
                elif show == 'processed':
                    result.processed_obs.set_codes(location='ob')
                    result.processed_syn.set_codes(location='sy')
                    all_trs.append(result.processed_obs)
                    all_trs.append(result.processed_syn)
                else:
                    raise ValueError('Invalid argument for show: %s' % show)

        for station in ds.get_stations():
            stations[station.nsl()] = station

    markers = []
    for ev in events:
        markers.append(pmarker.EventMarker(ev))

    trace.snuffle(all_trs, markers=markers, stations=list(stations.values()))