def test_picker_summary(event, picker): mseed = event + '_short.mseed' st = obspy_read(mseed, details=True) print(st) picker_class = picker().__class__.__name__ picker_index = picker_class.index('Picker') picker_summary_class = picker_class[:picker_index] + 'Summary' for s in st[:2]: print("trace = ") print(s) print("") picket_summary_str = picker_summary_class + \ '(' + 'picker(),' + 's)' picker_summary = eval(picket_summary_str) res = [] res_deriv = [] if 'AICD' in picker_class: res, aic_deriv = picker_summary.cf._statistics() print("AICD Picker = ") print("AIC = {}".format(res)) print("AIC_deriv = {}".format(res_deriv)) if 'FB' in picker_class: res = picker_summary.cf._statistics() print("FB Picker = ") print("Each Band Stats = {}".format(res)) if 'KT' in picker_class: res = picker_summary.cf._statistics() print("KT Picker = ") print("kurtosis stats = {}".format(res)) assert len(res) > 0 print("") threshold = picker_summary.threshold() print('threshold = ', threshold) print("") assert len(threshold) > 0 print("") uncertanity = picker_summary.uncertainty() print('uncertainity = ', uncertanity) print("") assert len(uncertanity) >= 0 scnl, picks, trigger, snr = picker_summary.pick_ident() print('scbl = ', scnl) print('picks = ', picks) print('trigger = ', trigger) print('snr = ', snr) print("") assert len(picks) >= 0 assert len(trigger) >= 0 assert len(snr) >= 0 polarity = picker_summary.polarity() print('Polarity = ', polarity) print("")
def test_amplitude(self): """ Test calculating amplitudes """ plotit = True datafile = str(self.data_path / "20190519T060917_MONA.mseed") respfile = str(self.data_path / "SPOBS2_resp.json") stream = obspy_read(datafile, 'MSEED') wid = WaveformStreamID(network_code=stream[0].stats.network, station_code=stream[0].stats.station, channel_code=stream[0].stats.channel) Ppick = Pick(time=UTCDateTime('2019-05-19T06:09:48.83'), phase_hint='P', waveform_id=wid) Spick = Pick(time=UTCDateTime('2019-05-19T06:09:51.52'), phase_hint='S', waveform_id=wid) la = LocalAmplitude(stream, [Ppick, Spick], respfile, 'JSON_PZ') wood_calc, _ = la.get_iaml(method='wood_calc') wood_est, _ = la.get_iaml(method='wood_est') raw, _ = la.get_iaml(method='raw_disp') # Values obtained when response was mis-interpreted as nm/s # self.assertAlmostEqual(amp_wood_calc.generic_amplitude, 1097.55509106/1e9) # self.assertAlmostEqual(amp_wood_calc.period, 0.112) self.assertAlmostEqual(wood_calc.generic_amplitude * 1e9, 378.3697813) self.assertAlmostEqual(wood_calc.period, 0.12) self.assertAlmostEqual(wood_est.generic_amplitude * 1e9, 140.490154756) self.assertAlmostEqual(wood_est.period, 0.032) self.assertAlmostEqual(raw.generic_amplitude * 1e9, 460.35018097) self.assertAlmostEqual(raw.period, 0.112)
def streams(station_list, plot_folder, total_file): """ Plotting every possible stream waveform after retrieval and before any correction """ for _station in station_list: for _stream in _station.stream_list: _filename = str(_station.network) + "_" + \ str(_station.code) + "_" + str(_stream.code) + \ ".png" _output_file = os.path.join(plot_folder, _filename) _fig_x = 21 _fig_y = 7 _fig = plt.figure(figsize=(_fig_x,_fig_y)) _st = obspy_read(_stream.mseed_path) _st.plot(outfile=_output_file, fig=_fig) if not len(_station.stream_list) == 3: # plot blank figures in case of missing component # get all N, E, Z possible streams _N = [x for x in _station.stream_list if x.code[2] == 'N'] _E = [x for x in _station.stream_list if x.code[2] == 'E'] _Z = [x for x in _station.stream_list if x.code[2] == 'Z'] _fig_x = 21 _fig_y = 7 _fig = plt.figure(figsize=(_fig_x,_fig_y)) # first two digits of stream code _min_code = str(_station.stream_list[0].code[0:2]) if not _N: _filename = str(_station.network) + "_" + \ str(_station.code) + "_" + _min_code + "N" + \ ".png" _output_file = os.path.join(plot_folder, _filename) plt.savefig(_output_file) if not _E: _filename = str(_station.network) + "_" + \ str(_station.code) + "_" + _min_code + "E" + \ ".png" _output_file = os.path.join(plot_folder, _filename) plt.savefig(_output_file) if not _Z: _filename = str(_station.network) + "_" + \ str(_station.code) + "_" + _min_code + "Z" + \ ".png" _output_file = os.path.join(plot_folder, _filename) plt.savefig(_output_file) streams2one(plot_folder, total_file)
def test_picker_integration(event, picker): mseed = event + '_short.mseed' st = obspy_read(mseed) total_picks = [] for s in st[:2]: _, picks, _, _, _ = picker().picks(s) total_picks += picks assert len(total_picks)
def test_normalize_default(self): """ Calling normalize with defaults should behave like obspy normalize method """ fname = get_example_file('ELZ_1hr.msd') st0 = stream.read(fname) st1 = obspy_read(fname) st0.normalize() st1.normalize() for tr0, tr1 in zip(st0.traces, st1.traces): self.assertEqual(min(tr0.data), min(tr1.data)) self.assertEqual(max(tr0.data), max(tr1.data))
def read_miniseed(fn): """ Read a miniseed file into a :class:`mth5.timeseries.RunTS` object :param fn: full path to the miniseed file :type fn: string :return: :rtype: TYPE """ # obspy does not use Path objects for file names if isinstance(fn, Path): fn = fn.as_posix() obs_stream = obspy_read(fn) run_obj = RunTS() run_obj.from_obspy_stream(obs_stream) return run_obj
def loadMseed(station_list): """ Load mseed to memory """ for station in station_list: # temp copy of station's stream list _stream_list = list(station.stream_list) for stream in station.stream_list: try: _st = obspy_read(stream.mseed_path, format="MSEED") stream.data = _st[0] except: _stream_list.remove(stream) # make new stream list as station's stream list station.stream_list = list(_stream_list) return removeEmptyStations(station_list)
def test_amplitude(self): """ Test calculating amplitudes """ datafile = os.path.join(self.testing_path, "20190519T060917_MONA.mseed") respfile = os.path.join(self.testing_path, "SPOBS2_response.json") stream = obspy_read(datafile, 'MSEED') wid = WaveformStreamID(network_code=stream[0].stats.network, station_code=stream[0].stats.station, channel_code=stream[0].stats.channel) Ppick = Pick(time=UTCDateTime('2019-05-19T06:09:48.83'), phase_hint='P', waveform_id=wid) Spick = Pick(time=UTCDateTime('2019-05-19T06:09:51.52'), phase_hint='S', waveform_id=wid) obj = LocalAmplitude(stream, [Ppick, Spick], respfile, 'JSON_PZ') amp_wood_calc, _ = obj.get_iaml(plot=False, method='wood_calc') amp_wood_est, _ = obj.get_iaml(plot=False, method='wood_est') amp_raw, _ = obj.get_iaml(plot=False, method='raw_disp') self.assertAlmostEqual(amp_wood_calc.generic_amplitude, 1097.555091056036) self.assertAlmostEqual(amp_wood_calc.period, 0.112)
def read_data_trace(self, file_name): folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data') return obspy_read(os.path.join(folder, file_name))