def test_get_waveform(self): """ Tests get_waveforms method. """ # example 1 client = Client(user='******') start = UTCDateTime(2010, 1, 1) end = start + 1 stream = client.get_waveforms('BW', 'MANZ', '', 'EH*', start, end) self.assertEqual(len(stream), 3) for trace in stream: self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, 'BW') self.assertEqual(trace.stats.station, 'MANZ') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel[0:2], 'EH') # example 2 client = Client(user='******') start = UTCDateTime("2010-12-31T23:59:50.495000Z") end = start + 100 stream = client.get_waveforms('GE', 'APE', '', 'BHE', start, end) self.assertEqual(len(stream), 1) trace = stream[0] self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, 'GE') self.assertEqual(trace.stats.station, 'APE') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel, 'BHE')
def test_get_waveform(self): """ Tests get_waveforms method. """ # example 1 client = Client(user='******') start = UTCDateTime(2010, 1, 1) end = start + 1 stream = client.get_waveforms('BW', 'MANZ', '', 'EH*', start, end) self.assertEqual(len(stream), 3) for trace in stream: self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, 'BW') self.assertEqual(trace.stats.station, 'MANZ') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel[0:2], 'EH') # example 2 client = Client(user='******') start = UTCDateTime("2010-12-31T23:59:50.495000Z") end = start + 100 stream = client.get_waveforms('GE', 'APE', '', 'BHE', start, end) # seems the response of the server has changed, it contains two traces # with an overlap now but the data is consistent and a cleanup merge # works stream.merge(-1) self.assertEqual(len(stream), 1) trace = stream[0] self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, 'GE') self.assertEqual(trace.stats.station, 'APE') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel, 'BHE')
def test_get_waveform_instrument_change(self): """ Check results of get_waveforms if instrumentation has been changed. Sensitivity change for GE.SNAA..BHZ at 2003-01-10T00:00:00 """ client = Client(user='******') # one instrument in given time span dt = UTCDateTime("2003-01-09T00:00:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 10, metadata=True) self.assertEqual(len(st), 1) self.assertEqual(st[0].stats.paz.sensitivity, 596224500.0) # two instruments in given time span dt = UTCDateTime("2003-01-09T23:59:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 120, metadata=True) # results into two traces self.assertEqual(len(st), 2) # with different PAZ st.sort() self.assertEqual(st[0].stats.paz.sensitivity, 596224500.0) self.assertEqual(st[1].stats.paz.sensitivity, 588000000.0) # one instrument in given time span dt = UTCDateTime("2003-01-10T01:00:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 10, metadata=True) self.assertEqual(len(st), 1) self.assertEqual(st[0].stats.paz.sensitivity, 588000000.0)
def test_issue_311(self): """ Testing issue #311. """ client = Client('*****@*****.**', host='webdc.eu', port=18001) t = UTCDateTime("2009-08-20 04:03:12") # 1 st = client.get_waveforms("BW", "MANZ", "", "EH*", t - 3, t + 15, metadata=False) self.assertEqual(len(st), 3) self.assertNotIn('paz', st[0].stats) self.assertNotIn('coordinates', st[0].stats) # 2 st = client.get_waveforms("BW", "MANZ", "", "EH*", t - 3, t + 15, metadata=True) self.assertEqual(len(st), 3) self.assertIn('paz', st[0].stats) self.assertIn('coordinates', st[0].stats)
def test_get_waveform_with_default_dcid_key_file(self): """ Use $HOME/dcidpasswords.txt. """ dcidfile = DCID_KEY_FILE fh = open(dcidfile, 'wt') fh.write('TEST=XYZ\r\nBIA=OfH9ekhi\r\n') fh.close() try: # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******") # public server client2 = Client(host="webdc.eu", port=18001, user="******") finally: # clean up dcid file os.remove(dcidfile) # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats)
def test_getWaveformInstrumentChange(self): """ Check results of get_waveforms if instrumentation has been changed. Sensitivity change for GE.SNAA..BHZ at 2003-01-10T00:00:00 """ client = Client(user="******") # one instrument in given time span dt = UTCDateTime("2003-01-09T00:00:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 10, metadata=True) self.assertEqual(len(st), 1) self.assertEqual(st[0].stats.paz.sensitivity, 596224500.0) # two instruments in given time span dt = UTCDateTime("2003-01-09T23:59:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 120, metadata=True) # results into two traces self.assertEqual(len(st), 2) # with different PAZ st.sort() self.assertEqual(st[0].stats.paz.sensitivity, 596224500.0) self.assertEqual(st[1].stats.paz.sensitivity, 588000000.0) # one instrument in given time span dt = UTCDateTime("2003-01-10T01:00:00") st = client.get_waveforms("GE", "SNAA", "", "BHZ", dt, dt + 10, metadata=True) self.assertEqual(len(st), 1) self.assertEqual(st[0].stats.paz.sensitivity, 588000000.0)
def test_getWaveform(self): """ Tests get_waveforms method. """ # example 1 client = Client(user="******") start = UTCDateTime(2010, 1, 1) end = start + 1 stream = client.get_waveforms("BW", "MANZ", "", "EH*", start, end) self.assertEqual(len(stream), 3) for trace in stream: self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, "BW") self.assertEqual(trace.stats.station, "MANZ") self.assertEqual(trace.stats.location, "") self.assertEqual(trace.stats.channel[0:2], "EH") # example 2 client = Client(user="******") start = UTCDateTime("2010-12-31T23:59:50.495000Z") end = start + 100 stream = client.get_waveforms("GE", "APE", "", "BHE", start, end) self.assertEqual(len(stream), 1) trace = stream[0] self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, "GE") self.assertEqual(trace.stats.station, "APE") self.assertEqual(trace.stats.location, "") self.assertEqual(trace.stats.channel, "BHE")
def test_getWaveformWithDCIDKeyFile(self): """ Tests various DCID key file formats (with space or equal sign). Also checks if empty lines or comment lines are ignored. """ # 1 - using = sign between username and password with NamedTemporaryFile() as tf: dcidfile = tf.name with open(dcidfile, 'wt') as fh: fh.write('#Comment\n\n\nTEST=XYZ\r\nBIA=OfH9ekhi\r\n') # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******", dcid_key_file=dcidfile) # public server client2 = Client(host="webdc.eu", port=18001, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats) # 2 - using space between username and password with NamedTemporaryFile() as tf: dcidfile = tf.name with open(dcidfile, 'wt') as fh: fh.write('TEST XYZ\r\nBIA OfH9ekhi\r\n') # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******", dcid_key_file=dcidfile) # public server client2 = Client(host="webdc.eu", port=18001, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats)
def test_issue311(self): """ Testing issue #311. """ client = Client("webdc.eu", 18001, user="******") t = UTCDateTime("2009-08-20 04:03:12") # 1 st = client.get_waveforms("BW", "MANZ", "", "EH*", t - 3, t + 15, metadata=False) self.assertEqual(len(st), 3) self.assertNotIn("paz", st[0].stats) self.assertNotIn("coordinates", st[0].stats) # 2 st = client.get_waveforms("BW", "MANZ", "", "EH*", t - 3, t + 15, metadata=True) self.assertEqual(len(st), 3) self.assertIn("paz", st[0].stats) self.assertIn("coordinates", st[0].stats)
def test_get_waveform_with_dcid_key(self): """ """ # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******", dcid_keys={'BIA': 'OfH9ekhi'}) # public server client2 = Client(host="webdc.eu", port=18001, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats)
def test_get_waveform_with_dcid_key_file(self): """ Tests various DCID key file formats (with space or equal sign). Also checks if empty lines or comment lines are ignored. """ # 1 - using = sign between username and password with NamedTemporaryFile() as tf: dcidfile = tf.name with open(dcidfile, 'wt') as fh: fh.write('#Comment\n\n\nTEST=XYZ\r\nBIA=OfH9ekhi\r\n') # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******", dcid_key_file=dcidfile) # public server client2 = Client(host="webdc.eu", port=18001, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats) # 2 - using space between username and password with NamedTemporaryFile() as tf: dcidfile = tf.name with open(dcidfile, 'wt') as fh: fh.write('TEST XYZ\r\nBIA OfH9ekhi\r\n') # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******", dcid_key_file=dcidfile) # public server client2 = Client(host="webdc.eu", port=18001, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats)
def test_getWaveformNoCompression(self): """ Disabling compression during waveform request. """ # initialize client client = Client(user="******") start = UTCDateTime(2011, 1, 1, 0, 0) end = start + 10 stream = client.get_waveforms("BW", "MANZ", "", "EH*", start, end, compressed=False) self.assertEqual(len(stream), 3) for trace in stream: self.assertEqual(trace.stats.network, "BW") self.assertEqual(trace.stats.station, "MANZ")
def test_get_waveform_with_default_dcid_key_file(self): """ Use $HOME/dcidpasswords.txt. """ dcidfile = DCID_KEY_FILE fh = open(dcidfile, 'wt') fh.write('TEST=XYZ\r\nBIA=OfH9ekhi\r\n') fh.close() # test server for encryption client1 = Client(host="webdc.eu", port=36000, user="******") # public server client2 = Client(host="webdc.eu", port=18001, user="******") # clean up dcid file os.remove(dcidfile) # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 stream1 = client1.get_waveforms('GE', 'APE', '', 'BHZ', start, end) stream2 = client2.get_waveforms('GE', 'APE', '', 'BHZ', start, end) # compare results np.testing.assert_array_equal(stream1[0].data, stream2[0].data) self.assertEqual(stream1[0].stats, stream2[0].stats)
def test_issue372(self): """ Test case for issue #372. """ dt = UTCDateTime("20120729070000") client = Client(user="******") st = client.get_waveforms("BS", "JMB", "", "BH*", dt, dt + 7200, metadata=True) for tr in st: self.assertIn("paz", tr.stats) self.assertIn("coordinates", tr.stats) self.assertIn("poles", tr.stats.paz) self.assertIn("zeros", tr.stats.paz) self.assertIn("latitude", tr.stats.coordinates)
def test_delayedRequest(self): """ """ # initialize client with 0.1 delay client = Client(host="webdc.eu", port=18002, command_delay=0.1, user="******") start = UTCDateTime(2010, 1, 1) end = start + 100 # get_waveforms with 0.1 delay stream = client.get_waveforms("GR", "FUR", "", "HHE", start, end) self.assertEqual(len(stream), 1) # get_routing with 0.1 delay results = client.get_routing("GR", "FUR", start, end) self.assertIn("GR...", results)
def test_get_waveform_no_compression(self): """ Disabling compression during waveform request. """ # initialize client client = Client(user='******') start = UTCDateTime(2011, 1, 1, 0, 0) end = start + 10 stream = client.get_waveforms('BW', 'MANZ', '', 'EH*', start, end, compressed=False) self.assertEqual(len(stream), 3) for trace in stream: self.assertEqual(trace.stats.network, 'BW') self.assertEqual(trace.stats.station, 'MANZ')
def test_delayed_request(self): """ """ # initialize client with 0.1 delay client = Client(host='webdc.eu', port=18002, command_delay=0.1, user='******') start = UTCDateTime(2010, 1, 1) end = start + 100 # get_waveforms with 0.1 delay stream = client.get_waveforms('GR', 'FUR', '', 'HHE', start, end) self.assertEqual(len(stream), 1) # get_routing with 0.1 delay results = client.get_routing('GR', 'FUR', start, end) self.assertIn('GR...', results)
def get_OVPF_arclink_data(net, sta, locid, cha, starttime, endtime): # serveur de données OVPF # pitonmanuel 195.83.188.22 client = Client(host="195.83.188.22", port="18001", user="******", institution="OVPF") try: st = client.get_waveforms(net, sta, locid, cha, starttime, endtime) return st except: return None
def test_issue_372(self): """ Test case for issue #372. """ dt = UTCDateTime("20120729070000") client = Client(user='******') st = client.get_waveforms("BS", "JMB", "", "BH*", dt, dt + 7200, metadata=True) for tr in st: self.assertIn('paz', tr.stats) self.assertIn('coordinates', tr.stats) self.assertIn('poles', tr.stats.paz) self.assertIn('zeros', tr.stats.paz) self.assertIn('latitude', tr.stats.coordinates)
def test_getWaveformNoRouting(self): """ Tests routing parameter of get_waveforms method. """ # 1 - requesting BW data w/o routing on webdc.eu client = Client(user="******") start = UTCDateTime(2008, 1, 1) end = start + 1 self.assertRaises(ArcLinkException, client.get_waveforms, "BW", "MANZ", "", "EH*", start, end, route=False) # 2 - requesting BW data w/o routing directly from BW ArcLink node client = Client(host="erde.geophysik.uni-muenchen.de", port=18001, user="******") start = UTCDateTime(2008, 1, 1) end = start + 1 stream = client.get_waveforms("BW", "MANZ", "", "EH*", start, end, route=False) for trace in stream: self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, "BW") self.assertEqual(trace.stats.station, "MANZ") self.assertEqual(trace.stats.location, "") self.assertEqual(trace.stats.channel[0:2], "EH")
def test_srl(self): """ Tests if example in ObsPy paper submitted to the Electronic Seismologist section of SRL is still working. The test shouldn't be changed because the reference gets wrong. """ paz = { 'gain': 60077000.0, 'poles': [(-0.037004000000000002 + 0.037016j), (-0.037004000000000002 - 0.037016j), (-251.33000000000001 + 0j), (-131.03999999999999 - 467.29000000000002j), (-131.03999999999999 + 467.29000000000002j)], 'sensitivity': 2516800000.0, 'zeros': [0j, 0j] } dat1 = np.array([288, 300, 292, 285, 265, 287, 279, 250, 278, 278]) dat2 = np.array([445, 432, 425, 400, 397, 471, 426, 390, 450, 442]) # Retrieve data via ArcLink client = Client('*****@*****.**', host='webdc.eu', port=18001) t = UTCDateTime("2009-08-24 00:20:03") st = client.get_waveforms("BW", "RJOB", "", "EHZ", t, t + 30) # original but deprecated call # poles_zeros = list(client.get_paz("BW", "RJOB", "", "EHZ", # t, t+30).values())[0] poles_zeros = client.get_paz("BW", "RJOB", "", "EHZ", t) self.assertEqual(paz['gain'], poles_zeros['gain']) self.assertEqual(paz['poles'], poles_zeros['poles']) self.assertEqual(paz['sensitivity'], poles_zeros['sensitivity']) self.assertEqual(paz['zeros'], poles_zeros['zeros']) self.assertEqual('BW', st[0].stats['network']) self.assertEqual('RJOB', st[0].stats['station']) self.assertEqual(200.0, st[0].stats['sampling_rate']) self.assertEqual(6001, st[0].stats['npts']) self.assertEqual('2009-08-24T00:20:03.000000Z', str(st[0].stats['starttime'])) np.testing.assert_array_equal(dat1, st[0].data[:10]) np.testing.assert_array_equal(dat2, st[0].data[-10:])
def test_SRL(self): """ Tests if example in ObsPy paper submitted to the Electronic Seismologist section of SRL is still working. The test shouldn't be changed because the reference gets wrong. """ paz = { "gain": 60077000.0, "poles": [ (-0.037004000000000002 + 0.037016j), (-0.037004000000000002 - 0.037016j), (-251.33000000000001 + 0j), (-131.03999999999999 - 467.29000000000002j), (-131.03999999999999 + 467.29000000000002j), ], "sensitivity": 2516800000.0, "zeros": [0j, 0j], } dat1 = np.array([288, 300, 292, 285, 265, 287, 279, 250, 278, 278]) dat2 = np.array([445, 432, 425, 400, 397, 471, 426, 390, 450, 442]) # Retrieve data via ArcLink client = Client(host="webdc.eu", port=18001, user="******") t = UTCDateTime("2009-08-24 00:20:03") st = client.get_waveforms("BW", "RJOB", "", "EHZ", t, t + 30) # original but deprecated call # poles_zeros = list(client.get_paz("BW", "RJOB", "", "EHZ", # t, t+30).values())[0] poles_zeros = client.get_paz("BW", "RJOB", "", "EHZ", t) self.assertEqual(paz["gain"], poles_zeros["gain"]) self.assertEqual(paz["poles"], poles_zeros["poles"]) self.assertEqual(paz["sensitivity"], poles_zeros["sensitivity"]) self.assertEqual(paz["zeros"], poles_zeros["zeros"]) self.assertEqual("BW", st[0].stats["network"]) self.assertEqual("RJOB", st[0].stats["station"]) self.assertEqual(200.0, st[0].stats["sampling_rate"]) self.assertEqual(6001, st[0].stats["npts"]) self.assertEqual("2009-08-24T00:20:03.000000Z", str(st[0].stats["starttime"])) np.testing.assert_array_equal(dat1, st[0].data[:10]) np.testing.assert_array_equal(dat2, st[0].data[-10:])
def test_get_waveform_no_routing(self): """ Tests routing parameter of get_waveforms method. """ # 1 - requesting BW data w/o routing on webdc.eu client = Client(user='******') start = UTCDateTime(2008, 1, 1) end = start + 1 self.assertRaises(ArcLinkException, client.get_waveforms, 'BW', 'MANZ', '', 'EH*', start, end, route=False) # 2 - requesting BW data w/o routing directly from BW ArcLink node client = Client(host='erde.geophysik.uni-muenchen.de', port=18001, user='******') start = UTCDateTime(2008, 1, 1) end = start + 1 stream = client.get_waveforms('BW', 'MANZ', '', 'EH*', start, end, route=False) for trace in stream: self.assertLessEqual(trace.stats.starttime, start) self.assertGreaterEqual(trace.stats.endtime, end) self.assertEqual(trace.stats.network, 'BW') self.assertEqual(trace.stats.station, 'MANZ') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel[0:2], 'EH')
def test_getWaveformNoRouting(self): """ Tests routing parameter of get_waveforms method. """ # 1 - requesting BW data w/o routing on webdc.eu client = Client(user='******') start = UTCDateTime(2008, 1, 1) end = start + 1 self.assertRaises(ArcLinkException, client.get_waveforms, 'BW', 'MANZ', '', 'EH*', start, end, route=False) # 2 - requesting BW data w/o routing directly from BW ArcLink node client = Client(host='erde.geophysik.uni-muenchen.de', port=18001, user='******') start = UTCDateTime(2008, 1, 1) end = start + 1 stream = client.get_waveforms('BW', 'MANZ', '', 'EH*', start, end, route=False) for trace in stream: self.assertTrue(trace.stats.starttime <= start) self.assertTrue(trace.stats.endtime >= end) self.assertEqual(trace.stats.network, 'BW') self.assertEqual(trace.stats.station, 'MANZ') self.assertEqual(trace.stats.location, '') self.assertEqual(trace.stats.channel[0:2], 'EH')
from __future__ import print_function from math import log10 from obspy.clients.arclink import Client from obspy.core import UTCDateTime from obspy.geodetics import gps2dist_azimuth paz_wa = {'sensitivity': 2800, 'zeros': [0j], 'gain': 1, 'poles': [-6.2832 - 4.7124j, -6.2832 + 4.7124j]} client = Client(user="******") t = UTCDateTime("2012-04-03T02:45:03") st = client.get_waveforms("CH", "LKBD", "", "EH*", t - 300, t + 300, metadata=True) st.simulate(paz_remove="self", paz_simulate=paz_wa, water_level=10) st.trim(t, t + 50) tr_n = st.select(component="N")[0] ampl_n = max(abs(tr_n.data)) tr_e = st.select(component="E")[0] ampl_e = max(abs(tr_e.data)) ampl = max(ampl_n, ampl_e) sta_lat = 46.38703 sta_lon = 7.62714 event_lat = 46.218 event_lon = 7.706
import numpy as np import matplotlib.pyplot as plt import obspy from obspy.clients.arclink import Client from obspy.signal.invsim import corn_freq_2_paz, simulate_seismometer # Retrieve data via ArcLink # please provide a valid email address for the keyword user client = Client(user="******") t = obspy.UTCDateTime("2009-08-24 00:20:03") st = client.get_waveforms('BW', 'RJOB', '', 'EHZ', t, t + 30) paz = client.get_paz('BW', 'RJOB', '', 'EHZ', t) # 1Hz instrument one_hertz = corn_freq_2_paz(1.0) # Correct for frequency response of the instrument res = simulate_seismometer(st[0].data.astype('float32'), st[0].stats.sampling_rate, paz, inst_sim=one_hertz) # Correct for overall sensitivity res = res / paz['sensitivity'] # Plot the seismograms sec = np.arange(len(res)) / st[0].stats.sampling_rate plt.subplot(211) plt.plot(sec, st[0].data, 'k') plt.title("%s %s" % (st[0].stats.station, t)) plt.ylabel('STS-2') plt.subplot(212)
from obspy.signal.trigger import coincidence_trigger client = Client(user="******") t = UTCDateTime("2012-04-03T01:00:00") t2 = t + 4 * 3600 stations = ["AIGLE", "SENIN", "DIX", "LAUCH", "MMK", "SIMPL"] st = Stream() for station in stations: try: tmp = client.get_waveforms("CH", station, "", "[EH]HZ", t, t2, metadata=True) except: print(station, "---") continue st += tmp st.taper() st.filter("bandpass", freqmin=1, freqmax=20) triglist = coincidence_trigger("recstalta", 10, 2, st, 4, sta=0.5, lta=10) print(len(triglist), "events triggered.") for trig in triglist: closest_sta = trig['stations'][0]
from obspy import UTCDateTime from obspy.geodetics import gps2dist_azimuth paz_wa = {"sensitivity": 2800, "zeros": [0j], "gain": 1, "poles": [-6.2832 - 4.7124j, -6.2832 + 4.7124j]} client = Client(user="******") t = UTCDateTime("2012-04-03T02:45:03") stations = client.get_stations(t, t + 300, "CH") mags = [] for station in stations: station = station["code"] try: st = client.get_waveforms("CH", station, "", "[EH]H[ZNE]", t - 300, t + 300, metadata=True) assert len(st) == 3 except: print(station, "---") continue st.simulate(paz_remove="self", paz_simulate=paz_wa, water_level=10) st.trim(t, t + 50) tr_n = st.select(component="N")[0] ampl_n = max(abs(tr_n.data)) tr_e = st.select(component="E")[0] ampl_e = max(abs(tr_e.data)) ampl = max(ampl_n, ampl_e) sta_lat = st[0].stats.coordinates.latitude
import matplotlib.pyplot as plt import obspy from obspy.clients.arclink import Client from obspy.signal.trigger import recursive_STALTA, trigger_onset # Retrieve waveforms via ArcLink client = Client(host="erde.geophysik.uni-muenchen.de", port=18001, user="******") t = obspy.UTCDateTime("2009-08-24 00:19:45") st = client.get_waveforms('BW', 'RTSH', '', 'EHZ', t, t + 50) # For convenience tr = st[0] # only one trace in mseed volume df = tr.stats.sampling_rate # Characteristic function and trigger onsets cft = recursive_STALTA(tr.data, int(2.5 * df), int(10. * df)) on_of = trigger_onset(cft, 3.5, 0.5) # Plotting the results ax = plt.subplot(211) plt.plot(tr.data, 'k') ymin, ymax = ax.get_ylim() plt.vlines(on_of[:, 0], ymin, ymax, color='r', linewidth=2) plt.vlines(on_of[:, 1], ymin, ymax, color='b', linewidth=2) plt.subplot(212, sharex=ax) plt.plot(cft, 'k') plt.hlines([3.5, 0.5], 0, len(cft), color=['r', 'b'], linestyle='--') plt.axis('tight')
def test_get_waveform_with_metadata(self): """ """ # initialize client client = Client(user='******') # example 1 t = UTCDateTime("2010-08-01T12:00:00") st = client.get_waveforms("BW", "RJOB", "", "EHZ", t, t + 60, metadata=True) results = { 'network': 'BW', '_format': 'MSEED', 'paz': AttribDict({ 'normalization_factor': 60077000.0, 'name': 'RJOB.2007.351.HZ', 'sensitivity': 2516800000.0, 'normalization_frequency': 1.0, 'sensor_manufacturer': 'Streckeisen', 'sensitivity_unit': 'M/S', 'sensitivity_frequency': 0.02, 'poles': [(-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j)], 'gain': 60077000.0, 'zeros': [0j, 0j], 'response_type': 'A', 'sensor_model': 'STS-2'}), 'mseed': AttribDict({ 'record_length': 512, 'encoding': 'STEIM1', 'filesize': 30720, 'dataquality': 'D', 'number_of_records': 4, 'byteorder': '>'}), 'coordinates': AttribDict({ 'latitude': 47.737167, 'elevation': 860.0, 'longitude': 12.795714}), 'sampling_rate': 200.0, 'station': 'RJOB', 'location': '', 'starttime': UTCDateTime(2010, 8, 1, 12, 0), 'delta': 0.005, 'calib': 1.0, 'npts': 1370, 'endtime': UTCDateTime(2010, 8, 1, 12, 0, 6, 845000), 'channel': 'EHZ'} results['processing'] = st[0].stats['processing'] self.assertEqual(st[0].stats, results) # example 2 client = Client(user='******') st = client.get_waveforms("CZ", "VRAC", "", "BHZ", t, t + 60, metadata=True) results = { 'network': 'CZ', '_format': 'MSEED', 'paz': AttribDict({ 'normalization_factor': 60077000.0, 'name': 'GFZ:CZ1980:STS-2/N/g=20000', 'sensitivity': 8200000000.0, 'normalization_frequency': 1.0, 'sensor_manufacturer': 'Streckeisen', 'sensitivity_unit': 'M/S', 'sensitivity_frequency': 0.02, 'zeros': [0j, 0j], 'gain': 60077000.0, 'poles': [(-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j)], 'response_type': 'A', 'sensor_model': 'STS-2/N'}), 'mseed': AttribDict({ 'record_length': 512, 'encoding': 'STEIM1', 'filesize': 3584, 'dataquality': 'D', 'number_of_records': 7, 'byteorder': '>'}), 'coordinates': AttribDict({ 'latitude': 49.3084, 'elevation': 470.0, 'longitude': 16.5933}), 'delta': 0.025, 'station': 'VRAC', 'location': '', 'starttime': UTCDateTime(2010, 8, 1, 11, 59, 59, 993400), 'endtime': UTCDateTime(2010, 8, 1, 12, 0, 59, 993400), 'npts': 2401, 'calib': 1.0, 'sampling_rate': 40.0, 'channel': 'BHZ'} results['processing'] = st[0].stats['processing'] self.assertEqual(st[0].stats, results)
import cartopy.crs as ccrs from cartopy.geodesic import Geodesic import shapely from obspy.core import read from obspy.clients.fdsn import Client client = Client("IRIS") lon = 106.65 eqlon = 159.61 lat = 35.08 eqlat = -4.23 rad = locations2degrees(lat, lon, eqlat, eqlon) t = UTCDateTime("2014-04-13T12:36:20") st = client.get_waveforms("HV", "UWB", "*", "*Z", t, t + 60 * 45) st.plot() #st.write("japan.mseed", format="MSEED") #%% def main(): # estimate the epicentral distance. This is one of your free parameters: Delta = 42 # in degrees # estimate the origin time of the earthquake; your other free parameter: t0 = UTCDateTime("2014-04-13T12:36:20") maxamp = readandplotseismogram("japan.mseed") computeandplottts(Delta, t0, maxamp) # tighten up the axes, and sh1w: plt.axis('tight')
def test_get_waveform_with_metadata(self): """ """ # initialize client client = Client(user='******') # example 1 t = UTCDateTime("2010-08-01T12:00:00") st = client.get_waveforms("BW", "RJOB", "", "EHZ", t, t + 60, metadata=True) results = { 'network': 'BW', '_format': 'MSEED', 'paz': AttribDict({ 'normalization_factor': 60077000.0, 'name': 'RJOB.2007.351.HZ', 'sensitivity': 2516800000.0, 'normalization_frequency': 1.0, 'sensor_manufacturer': 'Streckeisen', 'sensitivity_unit': 'M/S', 'sensitivity_frequency': 0.02, 'poles': [(-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j)], 'gain': 60077000.0, 'zeros': [0j, 0j], 'response_type': 'A', 'sensor_model': 'STS-2' }), 'mseed': AttribDict({ 'record_length': 512, 'encoding': 'STEIM1', 'filesize': 30720, 'dataquality': 'D', 'number_of_records': 60, 'byteorder': '>' }), 'coordinates': AttribDict({ 'latitude': 47.737167, 'elevation': 860.0, 'longitude': 12.795714 }), 'sampling_rate': 200.0, 'station': 'RJOB', 'location': '', 'starttime': UTCDateTime(2010, 8, 1, 12, 0), 'delta': 0.005, 'calib': 1.0, 'npts': 1370, 'endtime': UTCDateTime(2010, 8, 1, 12, 0, 6, 845000), 'channel': 'EHZ' } results['processing'] = st[0].stats['processing'] self.assertEqual(st[0].stats, results) # example 2 client = Client(user='******') st = client.get_waveforms("CZ", "VRAC", "", "BHZ", t, t + 60, metadata=True) results = { 'network': 'CZ', '_format': 'MSEED', 'paz': AttribDict({ 'normalization_factor': 60077000.0, 'name': 'GFZ:CZ1980:STS-2/N/g=20000', 'sensitivity': 8200000000.0, 'normalization_frequency': 1.0, 'sensor_manufacturer': 'Streckeisen', 'sensitivity_unit': 'M/S', 'sensitivity_frequency': 0.02, 'zeros': [0j, 0j], 'gain': 60077000.0, 'poles': [(-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j)], 'response_type': 'A', 'sensor_model': 'STS-2/N' }), 'mseed': AttribDict({ 'record_length': 512, 'encoding': 'STEIM1', 'filesize': 3584, 'dataquality': 'D', 'number_of_records': 7, 'byteorder': '>' }), 'coordinates': AttribDict({ 'latitude': 49.3084, 'elevation': 470.0, 'longitude': 16.5933 }), 'delta': 0.025, 'station': 'VRAC', 'location': '', 'starttime': UTCDateTime(2010, 8, 1, 11, 59, 59, 993400), 'endtime': UTCDateTime(2010, 8, 1, 12, 0, 59, 993400), 'npts': 2401, 'calib': 1.0, 'sampling_rate': 40.0, 'channel': 'BHZ' } results['processing'] = st[0].stats['processing'] self.assertEqual(st[0].stats, results)
def test_getWaveformWithMetadata(self): """ """ # initialize client client = Client(user="******") # example 1 t = UTCDateTime("2010-08-01T12:00:00") st = client.get_waveforms("BW", "RJOB", "", "EHZ", t, t + 60, metadata=True) results = { "network": "BW", "_format": "MSEED", "paz": AttribDict( { "normalization_factor": 60077000.0, "name": "RJOB.2007.351.HZ", "sensitivity": 2516800000.0, "normalization_frequency": 1.0, "sensor_manufacturer": "Streckeisen", "sensitivity_unit": "M/S", "sensitivity_frequency": 0.02, "poles": [ (-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j), ], "gain": 60077000.0, "zeros": [0j, 0j], "response_type": "A", "sensor_model": "STS-2", } ), "mseed": AttribDict( { "record_length": 512, "encoding": "STEIM1", "filesize": 30720, "dataquality": "D", "number_of_records": 60, "byteorder": ">", } ), "coordinates": AttribDict({"latitude": 47.737167, "elevation": 860.0, "longitude": 12.795714}), "sampling_rate": 200.0, "station": "RJOB", "location": "", "starttime": UTCDateTime(2010, 8, 1, 12, 0), "delta": 0.005, "calib": 1.0, "npts": 1370, "endtime": UTCDateTime(2010, 8, 1, 12, 0, 6, 845000), "channel": "EHZ", } results["processing"] = st[0].stats["processing"] self.assertEqual(st[0].stats, results) # example 2 client = Client(user="******") st = client.get_waveforms("CZ", "VRAC", "", "BHZ", t, t + 60, metadata=True) results = { "network": "CZ", "_format": "MSEED", "paz": AttribDict( { "normalization_factor": 60077000.0, "name": "GFZ:CZ1980:STS-2/N/g=20000", "sensitivity": 8200000000.0, "normalization_frequency": 1.0, "sensor_manufacturer": "Streckeisen", "sensitivity_unit": "M/S", "sensitivity_frequency": 0.02, "zeros": [0j, 0j], "gain": 60077000.0, "poles": [ (-0.037004 + 0.037016j), (-0.037004 - 0.037016j), (-251.33 + 0j), (-131.04 - 467.29j), (-131.04 + 467.29j), ], "response_type": "A", "sensor_model": "STS-2/N", } ), "mseed": AttribDict( { "record_length": 512, "encoding": "STEIM1", "filesize": 3584, "dataquality": "D", "number_of_records": 7, "byteorder": ">", } ), "coordinates": AttribDict({"latitude": 49.3084, "elevation": 470.0, "longitude": 16.5933}), "delta": 0.025, "station": "VRAC", "location": "", "starttime": UTCDateTime(2010, 8, 1, 11, 59, 59, 993400), "endtime": UTCDateTime(2010, 8, 1, 12, 0, 59, 993400), "npts": 2401, "calib": 1.0, "sampling_rate": 40.0, "channel": "BHZ", } results["processing"] = st[0].stats["processing"] self.assertEqual(st[0].stats, results)
import numpy as np import matplotlib.pyplot as plt import obspy from obspy.clients.arclink import Client from obspy.signal.invsim import corn_freq_2_paz, simulate_seismometer # Retrieve data via ArcLink # please provide a valid email address for the keyword user client = Client(user="******") t = obspy.UTCDateTime("2009-08-24 00:20:03") st = client.get_waveforms('BW', 'RJOB', '', 'EHZ', t, t + 30) paz = client.get_paz('BW', 'RJOB', '', 'EHZ', t) # 1Hz instrument one_hertz = corn_freq_2_paz(1.0) # Correct for frequency response of the instrument res = simulate_seismometer(st[0].data.astype('float32'), st[0].stats.sampling_rate, paz, inst_sim=one_hertz) # Correct for overall sensitivity res = res / paz['sensitivity'] # Plot the seismograms sec = np.arange(len(res)) / st[0].stats.sampling_rate plt.subplot(211) plt.plot(sec, st[0].data, 'k') plt.title("%s %s" % (st[0].stats.station, t)) plt.ylabel('STS-2') plt.subplot(212) plt.plot(sec, res, 'k')