def test_plot_window_figure(tmpdir): reset_matplotlib() obs_tr = read(obsfile).select(channel="*R")[0] syn_tr = read(synfile).select(channel="*R")[0] config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml") config = wio.load_window_config_yaml(config_file) cat = read_events(quakeml) inv = read_inventory(staxml) from obspy.taup import TauPyModel model = TauPyModel(model='iasp91') arrivals = model.get_ray_paths(500, 140, phase_list=['Pdiff', 'SS']) print(arrivals) ws = WindowSelector(obs_tr, syn_tr, config, event=cat, station=inv) windows = ws.select_windows() assert len(windows) > 0 win.plot_window_figure(str(tmpdir), obs_tr.id, ws, True, figure_format="png")
def test_plot_window_figure(tmpdir): reset_matplotlib() obs_tr = read(obsfile).select(channel="*R")[0] syn_tr = read(synfile).select(channel="*R")[0] config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml") config = wio.load_window_config_yaml(config_file) cat = read_events(quakeml) inv = read_inventory(staxml) ws = WindowSelector(obs_tr, syn_tr, config, event=cat, station=inv) windows = ws.select_windows() assert len(windows) > 0 win.plot_window_figure(str(tmpdir), obs_tr.id, ws, True, figure_format="png")
def test_plot_window_figure(tmpdir): reset_matplotlib() obs_tr = read(obsfile).select(channel="*R")[0] syn_tr = read(synfile).select(channel="*R")[0] config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml") config = wio.load_window_config_yaml(config_file) cat = readEvents(quakeml) inv = read_inventory(staxml) ws = WindowSelector(obs_tr, syn_tr, config, event=cat, station=inv) windows = ws.select_windows() assert len(windows) > 0 win.plot_window_figure(str(tmpdir), obs_tr.id, ws, True, figure_format="png")
def _process(self, inputs): # Weighting function for the windows. This particular choice will tend # to favor lots of smaller windows if "interval_scheduling" is chosen # as overlap resolution strategy. ip = inputs["input"] param = ip["parameters"] config = pyflex.Config( min_period=param["min_period"], max_period=param["max_period"], stalta_waterlevel=param["stalta_waterlevel"], s2n_limit=param["s2n_limit"], snr_max_base=param["snr_max_base"], tshift_acceptance_level=param["tshift_acceptance_level"], tshift_reference=param["tshift_reference"], dlna_acceptance_level=param["dlna_acceptance_level"], dlna_reference=param["dlna_reference"], cc_acceptance_level=param["cc_acceptance_level"], earth_model=param["earth_model"], min_surface_wave_velocity=param["min_surface_wave_velocity"], max_time_before_first_arrival=param[ "max_time_before_first_arrival"], c_0=param["c_0"], c_1=param["c_1"], c_2=param["c_2"], c_3a=param["c_3a"], c_3b=param["c_3b"], c_4a=param["c_4a"], c_4b=param["c_4b"], check_global_data_quality=param["check_global_data_quality"], snr_integrate_base=param["snr_integrate_base"], noise_start_index=param["noise_start_index"], noise_end_index=param["noise_end_index"], signal_start_index=param["signal_start_index"], signal_end_index=param["signal_end_index"], window_signal_to_noise_type=param["window_signal_to_noise_type"], resolution_strategy=param["resolution_strategy"], window_weight_fct=weighting_function) ws = WindowSelector(observed=ip["data_trace"], synthetic=ip["synthetic_trace"], config=config, event=[_i for _i in obspy.readEvents(ip["quakeml"]) if _i.resource_id.id == ip["event_id"]][0], station=obspy.read_inventory( ip["stationxml"], format="stationxml")) windows = ws.select_windows() data = ip["data_trace"] station_id = "%s.%s" % (data.stats.network, data.stats.station) component = data.stats.channel[-1] # HACK! with io.BytesIO() as _: ws.plot(_) fig = plt.gcf() fig.suptitle("Component: %s" % component, fontsize=15, horizontalalignment="center", x=0.8, y=1) with io.BytesIO() as buf: fig.savefig(buf) buf.seek(0, 0) # Not Python 3 compatible but who cares. image_string = buf.read() plt.close(fig) image_type = "pyflex_windows" # Metadata for Alessandro! metadata = [{"type": "pyflex", "station_id": station_id, "component": component, "channel_id": win.channel_id, "starttime": str(win.absolute_starttime), "endtime": str(win.absolute_endtime), "max_cc_value": win.max_cc_value, "cc_shift": win.cc_shift, "dlnA": win.dlnA} for win in windows] self.parameters=param self.write( "image", ({"image_string": image_string, "component": component, "output_folder": ip["output_folder"]}, image_type, station_id),metadata=metadata) #control={'con:skip':True} # self.write( # "windows", { # "record_type": "pyflex_windows", # "output_folder": ip["output_folder"], # "windows": windows, # "station_id": station_id, # "component": component},metadata=metadata) if ip["misfit_type"] == "pyflex_and_time_frequency": ip["windows"] = [{ "starttime": win.absolute_starttime, "endtime": win.absolute_endtime} for win in windows] self.write("window_tapering", ip, metadata=metadata)