Exemple #1
0
 def test_getWaveform(self):
     """
     Tests getWaveform method.
     """
     # example 1
     client = Client()
     start = UTCDateTime(2010, 1, 1)
     end = start + 1
     stream = client.getWaveform('BW', 'MANZ', '', 'EH*', start, end)
     self.assertEquals(len(stream), 3)
     for trace in stream:
         self.assertTrue(trace.stats.starttime <= start)
         self.assertTrue(trace.stats.endtime >= end)
         self.assertEquals(trace.stats.network, 'BW')
         self.assertEquals(trace.stats.station, 'MANZ')
         self.assertEquals(trace.stats.location, '')
         self.assertEquals(trace.stats.channel[0:2], 'EH')
     # example 2
     client = Client()
     start = UTCDateTime("2010-12-31T23:59:50.495000Z")
     end = start + 100
     stream = client.getWaveform('GE', 'APE', '', 'BHE', start, end)
     self.assertEquals(len(stream), 1)
     trace = stream[0]
     self.assertTrue(trace.stats.starttime <= start)
     self.assertTrue(trace.stats.endtime >= end)
     self.assertEquals(trace.stats.network, 'GE')
     self.assertEquals(trace.stats.station, 'APE')
     self.assertEquals(trace.stats.location, '')
     self.assertEquals(trace.stats.channel, 'BHE')
Exemple #2
0
    def test_getWaveformInstrumentChange(self):
        """
        Check results of getWaveform if instrumentation has been changed.

        Sensitivity change for GE.SNAA..BHZ at 2003-01-10T00:00:00
        """
        client = Client()
        # one instrument in given time span
        dt = UTCDateTime("2003-01-09T00:00:00")
        st = client.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 10,
                                metadata=True)
        self.assertEquals(len(st), 1)
        self.assertEquals(st[0].stats.paz.sensitivity, 596224500.0)
        # two instruments in given time span
        dt = UTCDateTime("2003-01-09T23:59:00")
        st = client.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 120,
                                metadata=True)
        # results into two traces
        self.assertEquals(len(st), 2)
        # with different PAZ
        st.sort()
        self.assertEquals(st[0].stats.paz.sensitivity, 596224500.0)
        self.assertEquals(st[1].stats.paz.sensitivity, 588000000.0)
        # one instrument in given time span
        dt = UTCDateTime("2003-01-10T01:00:00")
        st = client.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 10,
                                metadata=True)
        self.assertEquals(len(st), 1)
        self.assertEquals(st[0].stats.paz.sensitivity, 588000000.0)
Exemple #3
0
    def test_getWaveformInstrumentChange(self):
        """
        Check results of getWaveform 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.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 10,
                                metadata=True)
        self.assertEquals(len(st), 1)
        self.assertEquals(st[0].stats.paz.sensitivity, 596224500.0)
        # two instruments in given time span
        dt = UTCDateTime("2003-01-09T23:59:00")
        st = client.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 120,
                                metadata=True)
        # results into two traces
        self.assertEquals(len(st), 2)
        # with different PAZ
        st.sort()
        self.assertEquals(st[0].stats.paz.sensitivity, 596224500.0)
        self.assertEquals(st[1].stats.paz.sensitivity, 588000000.0)
        # one instrument in given time span
        dt = UTCDateTime("2003-01-10T01:00:00")
        st = client.getWaveform("GE", "SNAA", "", "BHZ", dt, dt + 10,
                                metadata=True)
        self.assertEquals(len(st), 1)
        self.assertEquals(st[0].stats.paz.sensitivity, 588000000.0)
Exemple #4
0
 def test_getWaveform(self):
     """
     Tests getWaveform method.
     """
     # example 1
     client = Client(user='******')
     start = UTCDateTime(2010, 1, 1)
     end = start + 1
     stream = client.getWaveform('BW', 'MANZ', '', 'EH*', start, end)
     self.assertEquals(len(stream), 3)
     for trace in stream:
         self.assertTrue(trace.stats.starttime <= start)
         self.assertTrue(trace.stats.endtime >= end)
         self.assertEquals(trace.stats.network, 'BW')
         self.assertEquals(trace.stats.station, 'MANZ')
         self.assertEquals(trace.stats.location, '')
         self.assertEquals(trace.stats.channel[0:2], 'EH')
     # example 2
     client = Client(user='******')
     start = UTCDateTime("2010-12-31T23:59:50.495000Z")
     end = start + 100
     stream = client.getWaveform('GE', 'APE', '', 'BHE', start, end)
     self.assertEquals(len(stream), 1)
     trace = stream[0]
     self.assertTrue(trace.stats.starttime <= start)
     self.assertTrue(trace.stats.endtime >= end)
     self.assertEquals(trace.stats.network, 'GE')
     self.assertEquals(trace.stats.station, 'APE')
     self.assertEquals(trace.stats.location, '')
     self.assertEquals(trace.stats.channel, 'BHE')
Exemple #5
0
 def test_issue311(self):
     """
     Testing issue #311.
     """
     client = Client("webdc.eu", 18001, user='******')
     t = UTCDateTime("2009-08-20 04:03:12")
     # 1
     st = client.getWaveform("BW",
                             "MANZ",
                             "",
                             "EH*",
                             t - 3,
                             t + 15,
                             metadata=False)
     self.assertEqual(len(st), 3)
     self.assertTrue('paz' not in st[0].stats)
     self.assertTrue('coordinates' not in st[0].stats)
     # 2
     st = client.getWaveform("BW",
                             "MANZ",
                             "",
                             "EH*",
                             t - 3,
                             t + 15,
                             metadata=True)
     self.assertEqual(len(st), 3)
     self.assertTrue('paz' in st[0].stats)
     self.assertTrue('coordinates' in st[0].stats)
Exemple #6
0
 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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #7
0
 def test_getWaveformWithDCIDKey(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.getWaveform("GE", "APE", "", "BHZ", start, end)
     stream2 = client2.getWaveform("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)
Exemple #8
0
 def test_getWaveformWithDCIDKey(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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #9
0
def stream_arklink_read(host="webdc.eu", port=18001, timeout=100,
                 start_time="2009-08-24 00:20:03", time_interval=30,
                 network_id="BW", station_id="RJOB", location_id="",
                 channel_id="EH*", get_paz=False):
    """ Arklink server client.

    For a detailed description of how it works refer to ObsPy website
    (obspy.org)

    """
    client = Client_arc(host, port, timeout)
    t = UTCDateTime(start_time)
    try:
        st = client.getWaveform(network_id, station_id, location_id, channel_id, \
                                t, t + time_interval)
        n_trace = len(st)

        if get_paz:
            paz = client.getPAZ(network_id, station_id, location_id, channel_id, \
                                t, t + time_interval)
            return st, paz, n_trace
        else:
            return st, n_trace
    except:
        print "An error occurred reading the data."
        st = []
        n_trace = 0
        paz = []
        if get_paz:
            return st, paz, n_trace
        else:
            return st, n_trace
Exemple #10
0
 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': 2516778600.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.getWaveform("BW", "RJOB", "", "EHZ", t, t + 30)
     poles_zeros = client.getPAZ("BW", "RJOB", "", "EHZ",
                                 t, t + 30).values()[0]
     self.assertEquals(paz['gain'], poles_zeros['gain'])
     self.assertEquals(paz['poles'], poles_zeros['poles'])
     self.assertEquals(paz['sensitivity'], poles_zeros['sensitivity'])
     self.assertEquals(paz['zeros'], poles_zeros['zeros'])
     self.assertEquals('BW', st[0].stats['network'])
     self.assertEquals('RJOB', st[0].stats['station'])
     self.assertEquals(200.0, st[0].stats['sampling_rate'])
     self.assertEquals(6001, st[0].stats['npts'])
     self.assertEquals('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:])
Exemple #11
0
 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': 2516778600.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.getWaveform("BW", "RJOB", "", "EHZ", t, t + 30)
     poles_zeros = client.getPAZ("BW", "RJOB", "", "EHZ",
                                 t, t + 30).values()[0]
     self.assertEquals(paz['gain'], poles_zeros['gain'])
     self.assertEquals(paz['poles'], poles_zeros['poles'])
     self.assertEquals(paz['sensitivity'], poles_zeros['sensitivity'])
     self.assertEquals(paz['zeros'], poles_zeros['zeros'])
     self.assertEquals('BW', st[0].stats['network'])
     self.assertEquals('RJOB', st[0].stats['station'])
     self.assertEquals(200.0, st[0].stats['sampling_rate'])
     self.assertEquals(6001, st[0].stats['npts'])
     self.assertEquals('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:])
Exemple #12
0
 def test_issue311(self):
     """
     Testing issue #311.
     """
     client = Client("webdc.eu", 18001, user='******')
     t = UTCDateTime("2009-08-20 04:03:12")
     # 1
     st = client.getWaveform("BW", "MANZ", "", "EH*", t - 3, t + 15,
                             metadata=False)
     self.assertEqual(len(st), 3)
     self.assertTrue('paz' not in st[0].stats)
     self.assertTrue('coordinates' not in st[0].stats)
     # 2
     st = client.getWaveform("BW", "MANZ", "", "EH*", t - 3, t + 15,
                             metadata=True)
     self.assertEqual(len(st), 3)
     self.assertTrue('paz' in st[0].stats)
     self.assertTrue('coordinates' in st[0].stats)
Exemple #13
0
 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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #14
0
def get_waveforms():
    events = get_events()
    client = ArcClient()
    wforms = Stream()
    for event in events:
        t = event.preferred_origin().time
        args = seed_id.split('.') + [t + 5 * 60, t + 14 * 60]
        wforms.extend(client.getWaveform(*args))
    wforms.decimate(int(round(wforms[0].stats.sampling_rate)) // 5,
                    no_filter=True)
    wforms.write(wavname, wavformat)
Exemple #15
0
 def test_getWaveformWithDCIDKeyFile(self):
     """
     """
     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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #16
0
 def test_getWaveformWithDefaultDCIDKeyFile(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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #17
0
 def test_delayedRequest(self):
     """
     """
     # initialize client with 0.1 delay
     client = Client(host='webdc.eu', port=18002, command_delay=0.1)
     start = UTCDateTime(2010, 1, 1)
     end = start + 100
     # getWaveform with 0.1 delay
     stream = client.getWaveform('GR', 'FUR', '', 'HHE', start, end)
     self.assertEquals(len(stream), 1)
     # getRouting with 0.1 delay
     results = client.getRouting('GR', 'FUR', start, end)
     self.assertTrue('GR...' in results)
Exemple #18
0
 def test_getWaveformWithDefaultDCIDKeyFile(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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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)
Exemple #19
0
 def test_getWaveformNoCompression(self):
     """
     Disabling compression during waveform request.
     """
     # initialize client
     client = Client()
     start = UTCDateTime(2011, 1, 1, 0, 0)
     end = start + 10
     stream = client.getWaveform('BW', 'MANZ', '', 'EH*', start, end,
                                 compressed=False)
     self.assertEquals(len(stream), 3)
     for trace in stream:
         self.assertEquals(trace.stats.network, 'BW')
         self.assertEquals(trace.stats.station, 'MANZ')
Exemple #20
0
 def test_issue372(self):
     """
     Test case for issue #372.
     """
     dt = UTCDateTime("20120529070000")
     client = Client()
     st = client.getWaveform("BS", "JMB", "", "BH*", dt, dt + 7200,
                             metadata=True)
     for tr in st:
         self.assertTrue('paz' in tr.stats)
         self.assertTrue('coordinates' in tr.stats)
         self.assertTrue('poles' in tr.stats.paz)
         self.assertTrue('zeros' in tr.stats.paz)
         self.assertTrue('latitude' in tr.stats.coordinates)
Exemple #21
0
 def test_issue372(self):
     """
     Test case for issue #372.
     """
     dt = UTCDateTime("20120729070000")
     client = Client(user='******')
     st = client.getWaveform("BS", "JMB", "", "BH*", dt, dt + 7200,
                             metadata=True)
     for tr in st:
         self.assertTrue('paz' in tr.stats)
         self.assertTrue('coordinates' in tr.stats)
         self.assertTrue('poles' in tr.stats.paz)
         self.assertTrue('zeros' in tr.stats.paz)
         self.assertTrue('latitude' in tr.stats.coordinates)
Exemple #22
0
 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.getWaveform('BW', 'MANZ', '', 'EH*', start, end,
                                 compressed=False)
     self.assertEquals(len(stream), 3)
     for trace in stream:
         self.assertEquals(trace.stats.network, 'BW')
         self.assertEquals(trace.stats.station, 'MANZ')
Exemple #23
0
 def test_getWaveformWithDCIDKeyFile(self):
     """
     """
     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.getWaveform('GE', 'APE', '', 'BHZ', start, end)
     stream2 = client2.getWaveform('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 get_waveforms():
    events = get_events()
    client = ArcClient(**client_kwargs)
    wforms = Stream()
    for i, event in enumerate(events):
        print('Fetch data for event no. %d' % (i + 1))
        t = event.preferred_origin().time
        for sta in stations:
            args = (net, sta, loc, cha, t - 10, t + 220)
            try:
                stream = client.getWaveform(*args)
            except:
                print('no data for %s' % (args,))
                continue
            sr = stream[0].stats.sampling_rate
            stream.decimate(int(sr) // 20, no_filter=True)
            for tr in stream:
                del tr.stats.mseed
            stream.merge()
            wforms.extend(stream)
    wforms.write(wavname, wavformat)
    return wforms
def get_waveforms():
    events = get_events()
    client = ArcClient(**client_kwargs)
    wforms = Stream()
    for i, event in enumerate(events):
        print('Fetch data for event no. %d' % (i + 1))
        t = event.preferred_origin().time
        for sta in stations:
            args = (net, sta, loc, cha, t - 10, t + 220)
            try:
                stream = client.getWaveform(*args)
            except:
                print('no data for %s' % (args, ))
                continue
            sr = stream[0].stats.sampling_rate
            stream.decimate(int(sr) // 20, no_filter=True)
            for tr in stream:
                del tr.stats.mseed
            stream.merge()
            wforms.extend(stream)
    wforms.write(wavname, wavformat)
    return wforms
Exemple #26
0
 def test_getWaveformNoRouting(self):
     """
     Tests routing parameter of getWaveform method.
     """
     # 1 - requesting BW data w/o routing on webdc.eu
     client = Client()
     start = UTCDateTime(2008, 1, 1)
     end = start + 1
     self.assertRaises(ArcLinkException, client.getWaveform, '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)
     start = UTCDateTime(2008, 1, 1)
     end = start + 1
     stream = client.getWaveform('BW', 'MANZ', '', 'EH*', start, end,
                                 route=False)
     for trace in stream:
         self.assertTrue(trace.stats.starttime <= start)
         self.assertTrue(trace.stats.endtime >= end)
         self.assertEquals(trace.stats.network, 'BW')
         self.assertEquals(trace.stats.station, 'MANZ')
         self.assertEquals(trace.stats.location, '')
         self.assertEquals(trace.stats.channel[0:2], 'EH')
Exemple #27
0
# Initialize ArcLink client
client= Client()

# Initialize data as emtpy list, set the corresponding stations
# Find available networks and stations on www.webdc.eu -> Query
# Global earthquake Sumatra
t = UTCDateTime(2004,12,26,01,00,00)
network = 'GR'
stations = ['FUR','BFO','BRG','BSEG','BUG']
channel = 'LHZ'

## Retrieve stations of network GR and immediately save waveforms
data = [] # initialize as empty list
for i, station in enumerate(stations):
    try:
        data.append(client.getWaveform(network, station, '', channel, t, t+1800))
        print "Retrieved data for station", station
    except:
        print "Cannot retrieve data for station", station


# Plot all the seismograms
m = len(stations)
plt.clf()
for i, st in enumerate(data):
    tr = st[0]
    plt.subplot(m,1,i+1) # python starts counting with 0
    plt.plot(tr.data)
    plt.title("%s %s" % (tr.stats.station,tr.stats.starttime))
plt.show()
from obspy.core import UTCDateTime
from obspy.arclink import Client

client = Client()
t = UTCDateTime("2008-04-17T16:00:00Z")
st = client.getWaveform("BW", "HROE", "", "EH*", t, t + 10*60)
print st
st.plot()

from obspy.neries import Client

client = Client()
events = client.getEvents(min_datetime="2008-10-10T08:05:00Z", max_datetime="2008-10-10T08:15:00Z")
print events

event = events[0]
print "origin time is", event['datetime']
print "magnitude is", event['magnitude']
print "longitude is", event['longitude']
print "latitude is", event['latitude']
print "depth is", event['depth']
Exemple #29
0
 def test_getWaveformWithMetadata(self):
     """
     """
     # initialize client
     client = Client(user='******')
     # example 1
     t = UTCDateTime("2010-08-01T12:00:00")
     st = client.getWaveform("BW", "RJOB", "", "EHZ", t, t + 60,
                             metadata=True)
     results = {
         'network': 'BW',
         '_format': 'MSEED',
         'paz': AttribDict({
             'normalization_factor': 60077000.0,
             'name': 'LMU:STS-2/N/g=1500',
             'sensitivity': 2516778600.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],
             'sensor_model': 'STS-2/N'}),
         'mseed': AttribDict({
             'record_length': 512,
             'encoding': 'STEIM1',
             'filesize': 30720L,
             'dataquality': 'D',
             'number_of_records': 60L,
             'byteorder': '>'}),
         'coordinates': AttribDict({
             'latitude': 47.737167,
             'elevation': 860.0,
             'longitude': 12.795714}),
         'delta': 0.005,
         'station': 'RJOB',
         'location': '',
         'starttime': UTCDateTime(2010, 8, 1, 12, 0),
         'endtime': UTCDateTime(2010, 8, 1, 12, 0, 6, 845000),
         'npts': 1370,
         'calib': 1.0,
         'sampling_rate': 200.0,
         'channel': 'EHZ'}
     self.assertEquals(st[0].stats, results)
     # example 2
     client = Client(user='******')
     st = client.getWaveform("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)],
             'sensor_model': 'STS-2/N'}),
         'mseed': AttribDict({
             'record_length': 512,
             'encoding': 'STEIM1',
             'filesize': 3584L,
             'dataquality': 'D',
             'number_of_records': 7L,
             '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'}
     self.assertEquals(st[0].stats, results)
from obspy.core import UTCDateTime
from obspy.arclink import Client

client = Client()
t = UTCDateTime("2008-04-17T16:00:00Z")
st = client.getWaveform("BW", "HROE", "", "EH*", t, t + 10 * 60)
print st
st.plot()

from obspy.neries import Client

client = Client()
events = client.getEvents(min_datetime="2008-10-10T08:05:00Z",
                          max_datetime="2008-10-10T08:15:00Z")
print events

event = events[0]
print "origin time is", event['datetime']
print "magnitude is", event['magnitude']
print "longitude is", event['longitude']
print "latitude is", event['latitude']
print "depth is", event['depth']
    'poles': [-6.2832 - 4.7124j, -6.2832 + 4.7124j]
}

client = Client(user="******")
t = UTCDateTime("2012-04-03T02:45:03")

stations = client.getStations(t, t + 300, "CH")
mags = []

for station in stations:
    station = station['code']
    try:
        st = client.getWaveform("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))
from obspy.arclink import Client
from obspy.signal import coincidenceTrigger
from math import log10
from numpy import median

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.getWaveform("CH", station, "", "[EH]HZ", t, t2,
                                 metadata=True)
    except:
        print station, "---"
        continue
    st += tmp

st.taper()
st.filter("bandpass", freqmin=1, freqmax=20)
triglist = coincidenceTrigger("recstalta", 10, 2, st, 4, sta=0.5, lta=10)
print len(triglist), "events triggered."

for trig in triglist:
    closest_sta = trig['stations'][0]
    tr = st.select(station=closest_sta)[0]
    trig['latitude'] = tr.stats.coordinates.latitude
    trig['longitude'] = tr.stats.coordinates.longitude
import numpy as np
import matplotlib.pyplot as plt
from obspy.core import UTCDateTime
from obspy.arclink import Client
from obspy.signal import cornFreq2Paz, seisSim

# Retrieve data via ArcLink
# please provide a valid email address for the keyword user
client = Client(user="******")
t = UTCDateTime("2009-08-24 00:20:03")
st = client.getWaveform("BW", "RJOB", "", "EHZ", t, t + 30)
paz = client.getPAZ("BW", "RJOB", "", "EHZ", t, t + 30)
paz = paz.values()[0]

# 1Hz instrument
one_hertz = cornFreq2Paz(1.0)
# Correct for frequency response of the instrument
res = seisSim(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")
plt.xlabel("Time [s]")
plt.ylabel("1Hz CornerFrequency")
Exemple #34
0
# Initialize ArcLink client
client = Client()

# Initialize data as emtpy list, set the corresponding stations
# Find available networks and stations on www.webdc.eu -> Query
# Global earthquake Sumatra
t = UTCDateTime(2004, 12, 26, 01, 00, 00)
network = 'GR'
stations = ['FUR', 'BFO', 'BRG', 'BSEG', 'BUG']
channel = 'LHZ'

## Retrieve stations of network GR and immediately save waveforms
data = []  # initialize as empty list
for i, station in enumerate(stations):
    try:
        data.append(
            client.getWaveform(network, station, '', channel, t, t + 1800))
        print "Retrieved data for station", station
    except:
        print "Cannot retrieve data for station", station

# Plot all the seismograms
m = len(stations)
plt.clf()
for i, st in enumerate(data):
    tr = st[0]
    plt.subplot(m, 1, i + 1)  # python starts counting with 0
    plt.plot(tr.data)
    plt.title("%s %s" % (tr.stats.station, tr.stats.starttime))
plt.show()
Exemple #35
0
from obspy.core import UTCDateTime
from obspy.core.util.geodetics import gps2DistAzimuth
from obspy.arclink import Client
from math import log10

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.getWaveform("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

epi_dist, az, baz = gps2DistAzimuth(event_lat, event_lon, sta_lat, sta_lon)
epi_dist = epi_dist / 1000

a = 0.018
Exemple #36
0
 def test_getWaveformWithMetadata(self):
     """
     """
     # initialize client
     client = Client()
     # example 1
     t = UTCDateTime("2010-08-01T12:00:00")
     st = client.getWaveform("BW", "RJOB", "", "EHZ", t, t + 60,
                             metadata=True)
     results = {
         'network': 'BW',
         '_format': 'MSEED',
         'paz': AttribDict({
             'normalization_factor': 60077000.0,
             'name': 'LMU:STS-2/N/g=1500',
             'sensitivity': 2516778600.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],
             'sensor_model': 'STS-2/N'}),
         'mseed': AttribDict({
             'record_length': 512,
             'encoding': 'STEIM1',
             'filesize': 30720L,
             'dataquality': 'D',
             'number_of_records': 60L,
             'byteorder': '>'}),
         'coordinates': AttribDict({
             'latitude': 47.737167,
             'elevation': 860.0,
             'longitude': 12.795714}),
         'delta': 0.005,
         'station': 'RJOB',
         'location': '',
         'starttime': UTCDateTime(2010, 8, 1, 12, 0),
         'npts': 1370,
         'calib': 1.0,
         'sampling_rate': 200.0,
         'channel': 'EHZ'}
     self.assertEquals(st[0].stats, results)
     # example 2
     client = Client()
     st = client.getWaveform("CZ", "VRAC", "", "BHZ", t, t + 60,
                             metadata=True)
     results = {
         'network': 'CZ',
         '_format': 'MSEED',
         'paz': AttribDict({
             'normalization_factor': 60077000.0,
             'name': 'GFZ: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)],
             'sensor_model': 'STS-2/N'}),
         'mseed': AttribDict({
             'record_length': 512,
             'encoding': 'STEIM1',
             'filesize': 3584L,
             'dataquality': 'D',
             'number_of_records': 7L,
             '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),
         'npts': 2401,
         'calib': 1.0,
         'sampling_rate': 40.0,
         'channel': 'BHZ'}
     self.assertEquals(st[0].stats, results)
import numpy as np
import matplotlib.pyplot as plt
from obspy.core import UTCDateTime
from obspy.arclink import Client
from obspy.signal import cornFreq2Paz, seisSim

# Retrieve data via ArcLink
# please provide a valid email address for the keyword user
client = Client(user="******")
# t = UTCDateTime("2009-08-24 00:20:03")
# st = client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t + 30)
# paz = client.getPAZ('BW', 'RJOB', '', 'EHZ', t)


t = UTCDateTime("2009-10-16 00:00:00")
st = client.getWaveform('', '', '', 'MHZ', t, t + 3600)
paz = client.getPAZ('', '', '', 'MHZ', t)


# 1Hz instrument
one_hertz = cornFreq2Paz(1.0)
# Correct for frequency response of the instrument
res = seisSim(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
Exemple #38
0
from obspy.core import UTCDateTime
from obspy.arclink import Client

start = UTCDateTime(2010, 1, 1)
end = start+30

from obspy.arclink import Client
client = Client('webdc.eu')
stream = client.getWaveform('CZ', 'PVCC', '', 'BH*', start, end, getPAZ=True, getCoordinates=True)
from obspy.core.util.geodetics import gps2DistAzimuth
from obspy.arclink import Client
from math import log10
from numpy import median

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 = ["LKBD", "SIMPL", "DIX"]
mags = []

for station in stations:
    st = client.getWaveform("CH", station, "", "[EH]H*", 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 = st[0].stats.coordinates.latitude
    sta_lon = st[0].stats.coordinates.longitude
    event_lat = 46.218
    event_lon = 7.706
from obspy.core import UTCDateTime
from obspy.arclink import Client
from obspy.signal.trigger import recSTALTA, triggerOnset
import matplotlib.pyplot as plt
import numpy as np

# Retrieve waveforms via ArcLink
client = Client(host="erde.geophysik.uni-muenchen.de", port=18001)
t = UTCDateTime("2009-08-24 00:19:45")
st = client.getWaveform('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 = recSTALTA(tr.data, int(2.5 * df), int(10. * df))
on_of = triggerOnset(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')
plt.show()
Exemple #41
0
from obspy.core import UTCDateTime
from obspy.arclink import Client

start = UTCDateTime(2010, 1, 1)
end = start + 30

from obspy.arclink import Client
client = Client('webdc.eu')
stream = client.getWaveform('CZ',
                            'PVCC',
                            '',
                            'BH*',
                            start,
                            end,
                            getPAZ=True,
                            getCoordinates=True)
Exemple #42
0
import numpy as np
import matplotlib.pyplot as plt
from obspy.core import UTCDateTime
from obspy.arclink import Client
from obspy.signal import cornFreq2Paz, seisSim

# Retrieve data via ArcLink
# please provide a valid email address for the keyword user
client = Client(user="******")
t = UTCDateTime("2009-08-24 00:20:03")
st = client.getWaveform('BW', 'RJOB', '', 'EHZ', t, t + 30)
paz = client.getPAZ('BW', 'RJOB', '', 'EHZ', t)
paz = paz.values()[0]

# 1Hz instrument
one_hertz = cornFreq2Paz(1.0)
# Correct for frequency response of the instrument
res = seisSim(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)
Exemple #43
0
cha = opts.cha
b = UTCDateTime(opts.b) + 5
e = UTCDateTime(opts.e)
jday1 = int(opts.b[-3:])
jday2 = int(opts.e[-3:])


print jday2 - jday1, "day(s) to search for.\n"



while jday1 <= jday2 :
   
    try:
        print "trying to download day", "%03d" % jday1, "..."
        st = client.getWaveform(net, sta, '*', cha, b,  b + 86390)
        st.merge(method=1, fill_value="interpolate")
        try:
            mkdir(sta)
        except:
            pass
        for tr in st :
            loc = str(tr.stats.location)
            chan = str(tr.stats.channel)
            #date = str(tr.stats.starttime).replace("-", ".")
            year = str(tr.stats.starttime.year)
            jday = str("%03d" % tr.stats.starttime.julday)
            filename = net+"."+sta+"."+loc+"."+chan+".D."+year+"."+jday
            tr.write(sta+"/"+filename, format=_format)
            print filename, "saved."
    except: