def getNetworks(user1, start, end): ''' Return dictionary of available networks via Arclink :type start: obspy.core.utcdatetime.UTCDateTime :param start: Start date and time :type end: obspy.core.utcdatetime.UTCDateTime :param end: End date and time ''' for i in range(3): Logfile.add(' ','Waiting for dictionary of available geofon networks(via Arclink) ....') try: L= [] client = Client(user = user1) #hs #client = Client(user = user1, timeout=20) #hs t = client.getNetworks(start,end) for index,i in enumerate(t.iterkeys()): z = i.split('.') L.append(z[0]) L = list(set(L)) break except: Logfile.exception('getGeofonNetworks') Logfile.exception('Retry access') L = [] continue #endfor return L
def test_get_stations_inconsistency(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result_origin = AttribDict({ 'remark': '', 'code': 'RWMO', 'elevation': 763.0, 'description': 'Wildenmoos, Bavaria, BW-Net', 'start': UTCDateTime(2006, 7, 4, 0, 0), 'restricted': False, 'archive_net': '', 'longitude': 12.729887, 'affiliation': 'BayernNetz', 'depth': None, 'place': 'Wildenmoos', 'country': ' BW-Net', 'latitude': 47.744171, 'end': None }) # OK: from origin node result = client.get_stations(start, end, 'BW', route=True) self.assertTrue(result_origin in result) # BUT: this one from a different node was modified and fails result = client.get_stations(start, end, 'BW') self.assertTrue(result_origin in result)
def getNetworkInventory(network, user1): ''' Retrieve all stations from one WEBDC network :type network: str :param network: name of network to search for station ''' inv = None isOk = False for i in range(5): try: client = Client(user=user1) #hs #client = Client(user=user1, timeout=100) #hs inv = client.getInventory(network, '*', '*', '*', restricted=None,permanent=None) isOk= True break except: return None #endfor if not isOk: return None # return _getFromCatalog(network) else: return inv
def test_get_inventory_stationgroup(self): """ Tests get_inventory method for StationGroup, issue #1756. """ client = Client(user='******') # 1 - defined @INGV with warnings.catch_warnings(record=True) as w: warnings.filterwarnings("always") result = client.get_inventory(network="_NFOTABOO", route=True) self.assertEqual(len(w), 1) self.assertEqual( str(w[0].message), "Routing was requested but parameter 'network' is '_NFOTABOO' " "and therefore routing is disabled.") self.assertIn('IV', result) self.assertIn('IV.ATBU', result) self.assertIn('IV.SSFR', result) # 2 - defined @NIEP result = client.get_inventory(network="_NFOVRANC", route=False) self.assertIn('RO', result) self.assertIn('RO.BISRR', result) self.assertIn('RO.VRI', result) # 3 - defined @ETH result = client.get_inventory(network="_NFOVALAIS", starttime=UTCDateTime(2017, 10, 16), endtime=UTCDateTime(2017, 10, 19)) self.assertIn('CH', result) self.assertIn('S', result) # self.assertIn('7H', result) This network does not appear to be # included in the _NFOVALAIS network anymore. Checked on 03/12/2018 # at http://eida.gfz-potsdam.de/webdc3/ self.assertIn('CH.AIGLE', result) self.assertIn('CH.VANNI', result) self.assertIn('S.ESION', result)
def test_saveWaveformCompressed(self): """ Tests saving compressed and not unpacked bzip2 files to disk. """ # initialize client client = Client(user="******") start = UTCDateTime(2008, 1, 1, 0, 0) end = start + 1 # MiniSEED with NamedTemporaryFile(suffix=".bz2") as tf: mseedfile = tf.name client.save_waveforms(mseedfile, "GE", "APE", "", "BHZ", start, end, unpack=False) # check if compressed with open(mseedfile, "rb") as fp: self.assertEqual(fp.read(2), b"BZ") # importing via read should work too read(mseedfile) # Full SEED with NamedTemporaryFile(suffix=".bz2") as tf: fseedfile = tf.name client.save_waveforms(fseedfile, "GE", "APE", "", "BHZ", start, end, format="FSEED", unpack=False) # check if compressed with open(fseedfile, "rb") as fp: self.assertEqual(fp.read(2), b"BZ") # importing via read should work too read(fseedfile)
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_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_getStations(self): """ """ # initialize client client = Client(user="******") # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_stations(start, end, "BW") self.assertTrue( AttribDict( { "remark": "", "code": "RWMO", "elevation": 763.0, "description": "Wildenmoos, Bavaria, BW-Net", "start": UTCDateTime(2006, 7, 4, 0, 0), "restricted": False, "archive_net": "", "longitude": 12.729887, "affiliation": "BayernNetz", "depth": None, "place": "Wildenmoos", "country": " BW-Net", "latitude": 47.744171, "end": None, } ) in result )
def getArclinkInst(station,usermail,pwdkeys): inst = 'no_instrument_available' #if station.loc == '': station.loc='--' sn = station.net+'.'+station.sta+'.'+station.loc+'.'+station.comp print 'SN ',sn client = Client(user=usermail,dcid_keys=pwdkeys) inv= client.getInventory(station.net, station.sta, station.loc, station.comp, instruments=True) print 'INV: ',inv try: stats = inv[sn] print 'STATS ',stats t= stats[0] z= t['paz'] inst = z['name'] inst = inst.replace(' ','_') except: inst = 'no_instrument_available' return inst
def test_get_paz(self): """ Test for the Client.get_paz function. As reference the EHZ channel of MANZ is taken, the result is compared to the entries of the local response file of the Bavarian network. """ # reference values zeros = [0j, 0j] poles = [ -3.700400e-02 + 3.701600e-02j, -3.700400e-02 - 3.701600e-02j, -2.513300e+02 + 0.000000e+00j, -1.310400e+02 - 4.672900e+02j, -1.310400e+02 + 4.672900e+02j ] normalization_factor = 6.0077e+07 sensitivity = 2.5168e+09 # initialize client client = Client('*****@*****.**', host='erde.geophysik.uni-muenchen.de', port=18001) # fetch poles and zeros dt = UTCDateTime(2009, 1, 1) paz = client.get_paz('BW', 'MANZ', '', 'EHZ', dt) # compare instrument self.assertEqual(normalization_factor, paz.normalization_factor) self.assertEqual(poles, paz.poles) self.assertEqual(zeros, paz.zeros) self.assertAlmostEqual(sensitivity / 1e9, paz.sensitivity / 1e9, 4) # PAZ over multiple channels should raise an exception self.assertRaises(ArcLinkException, client.get_paz, 'BW', 'MANZ', '', 'EH*', dt)
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_stations(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_stations(start, end, 'BW') self.assertTrue( AttribDict({ 'remark': '', 'code': 'RWMO', 'elevation': 763.0, 'description': 'Wildenmoos, Bavaria, BW-Net', 'start': UTCDateTime(2006, 7, 4, 0, 0), 'restricted': False, 'archive_net': '', 'longitude': 12.729887, 'affiliation': 'BayernNetz', 'depth': None, 'place': 'Wildenmoos', 'country': ' BW-Net', 'latitude': 47.744171, 'end': None }) in result)
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_stations(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_stations(start, end, 'BW') self.assertTrue( AttribDict({'remark': '', 'code': 'RWMO', 'elevation': 763.0, 'description': 'Wildenmoos, Bavaria, BW-Net', 'start': UTCDateTime(2006, 7, 4, 0, 0), 'restricted': False, 'archive_net': '', 'longitude': 12.729887, 'affiliation': 'BayernNetz', 'depth': None, 'place': 'Wildenmoos', 'country': 'BW-Net', 'latitude': 47.744171, 'end': None}) in result) # example 2 expected = AttribDict( {'code': 'WDD', 'description': 'Wied Dalam', 'affiliation': '', 'country': '', 'place': '', 'remark': '', 'restricted': False, 'archive_net': '', 'latitude': 35.8373, 'longitude': 14.5242, 'elevation': 44.0, 'depth': None, 'start': UTCDateTime(1995, 7, 6, 0, 0), 'end': None}) # routing default result = client.get_stations(start, end, 'MN') self.assertTrue(expected in result) # w/o routing result = client.get_stations(start, end, 'MN', route=False) self.assertTrue(expected in result) # w/ routing result = client.get_stations(start, end, 'MN', route=True) self.assertTrue(expected in result)
def test_get_inventory_stationgroup(self): """ Tests get_inventory method for StationGroup, issue #1756. """ client = Client(user='******') # 1 - defined @INGV with warnings.catch_warnings(record=True) as w: warnings.filterwarnings("always") result = client.get_inventory(network="_NFOTABOO", route=True) self.assertEqual(len(w), 1) self.assertEqual( str(w[0].message), "Routing was requested but parameter 'network' is '_NFOTABOO' " "and therefore routing is disabled.") self.assertIn('IV', result) self.assertIn('IV.ATBU', result) self.assertIn('IV.SSFR', result) # 2 - defined @NIEP result = client.get_inventory(network="_NFOVRANC", route=False) self.assertIn('RO', result) self.assertIn('RO.BISRR', result) self.assertIn('RO.VRI', result) # 3 - defined @ETH result = client.get_inventory( network="_NFOVALAIS", starttime=UTCDateTime(2017, 10, 16), endtime=UTCDateTime(2017, 10, 19)) self.assertIn('CH', result) self.assertIn('S', result) # self.assertIn('7H', result) This network does not appear to be # included in the _NFOVALAIS network anymore. Checked on 03/12/2018 # at http://eida.gfz-potsdam.de/webdc3/ self.assertIn('CH.AIGLE', result) self.assertIn('CH.VANNI', result) self.assertIn('S.ESION', result)
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_save_waveform_compressed(self): """ Tests saving compressed and not unpacked bzip2 files to disk. """ # initialize client client = Client(user='******') start = UTCDateTime(2008, 1, 1, 0, 0) end = start + 1 # MiniSEED with NamedTemporaryFile(suffix='.bz2') as tf: mseedfile = tf.name client.save_waveforms(mseedfile, 'GE', 'APE', '', 'BHZ', start, end, unpack=False) # check if compressed with open(mseedfile, 'rb') as fp: self.assertEqual(fp.read(2), b'BZ') # importing via read should work too read(mseedfile) # Full SEED with NamedTemporaryFile(suffix='.bz2') as tf: fseedfile = tf.name client.save_waveforms(fseedfile, 'GE', 'APE', '', 'BHZ', start, end, format="FSEED", unpack=False) # check if compressed with open(fseedfile, 'rb') as fp: self.assertEqual(fp.read(2), b'BZ') # importing via read should work too read(fseedfile)
def test_get_inventory_stationgroup(self): """ Tests get_inventory method for StationGroup, issue #1756. """ client = Client(user='******') # 1 - defined @INGV with warnings.catch_warnings(record=True) as w: warnings.filterwarnings("always") result = client.get_inventory(network="_NFOTABOO", route=True) self.assertEqual(len(w), 1) self.assertEqual( str(w[0].message), "Routing was requested but parameter 'network' is '_NFOTABOO' " "and therefore routing is disabled.") self.assertIn('IV', result) self.assertIn('IV.ATBU', result) self.assertIn('IV.SSFR', result) # 2 - defined @NIEP result = client.get_inventory(network="_NFOVRANC", route=False) self.assertIn('RO', result) self.assertIn('RO.BISRR', result) self.assertIn('RO.VRI', result) # 3 - defined @ETH result = client.get_inventory(network="_NFOVALAIS") self.assertIn('CH', result) self.assertIn('S', result) self.assertIn('7H', result) self.assertIn('CH.AIGLE', result) self.assertIn('CH.VANNI', result) self.assertIn('S.ESION', result)
def test_getPAZ(self): """ Test for the Client.get_paz function. As reference the EHZ channel of MANZ is taken, the result is compared to the entries of the local response file of the Bavarian network. """ # reference values zeros = [0j, 0j] poles = [ -3.700400e-02 + 3.701600e-02j, -3.700400e-02 - 3.701600e-02j, -2.513300e02 + 0.000000e00j, -1.310400e02 - 4.672900e02j, -1.310400e02 + 4.672900e02j, ] normalization_factor = 6.0077e07 sensitivity = 2.5168e09 # initialize client client = Client("erde.geophysik.uni-muenchen.de", 18001, user="******") # fetch poles and zeros dt = UTCDateTime(2009, 1, 1) paz = client.get_paz("BW", "MANZ", "", "EHZ", dt) # compare instrument self.assertEqual(normalization_factor, paz.normalization_factor) self.assertEqual(poles, paz.poles) self.assertEqual(zeros, paz.zeros) self.assertAlmostEqual(sensitivity / 1e9, paz.sensitivity / 1e9, 4) # PAZ over multiple channels should raise an exception self.assertRaises(ArcLinkException, client.get_paz, "BW", "MANZ", "", "EH*", dt)
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_networks(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_networks(start, end) self.assertIn('BW', result.keys()) self.assertEqual(result['BW']['code'], 'BW') self.assertEqual(result['BW']['description'], 'BayernNetz')
def test_get_inventory_twice(self): """ Requesting inventory data twice should not fail. """ client = Client(user='******') dt = UTCDateTime(2009, 1, 1) # station client.get_inventory('BW', 'MANZ', starttime=dt, endtime=dt + 1) client.get_inventory('BW', 'MANZ', starttime=dt, endtime=dt + 1) # network client.get_inventory('BW', starttime=dt, endtime=dt + 1) client.get_inventory('BW', starttime=dt, endtime=dt + 1)
def test_getNetworks(self): """ """ # initialize client client = Client(user="******") # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_networks(start, end) self.assertIn("BW", result.keys()) self.assertEqual(result["BW"]["code"], "BW") self.assertEqual(result["BW"]["description"], "BayernNetz")
def test_getInventoryTwice(self): """ Requesting inventory data twice should not fail. """ client = Client(user="******") dt = UTCDateTime(2009, 1, 1) # station client.get_inventory("BW", "MANZ", starttime=dt, endtime=dt + 1) client.get_inventory("BW", "MANZ", starttime=dt, endtime=dt + 1) # network client.get_inventory("BW", starttime=dt, endtime=dt + 1) client.get_inventory("BW", starttime=dt, endtime=dt + 1)
def test_getPAZ2(self): """ Test for the Client.get_paz function for erde.geophysik.uni-muenchen.de. """ poles = [-3.700400e-02 + 3.701600e-02j, -3.700400e-02 - 3.701600e-02j] dt = UTCDateTime(2009, 1, 1) client = Client("erde.geophysik.uni-muenchen.de", 18001, user="******") # fetch poles and zeros paz = client.get_paz("BW", "MANZ", "", "EHZ", dt) self.assertEqual(len(poles), 2) self.assertEqual(poles, paz["poles"][:2])
def test_get_paz2(self): """ Test for the Client.get_paz function for erde.geophysik.uni-muenchen.de. """ poles = [-3.700400e-02 + 3.701600e-02j, -3.700400e-02 - 3.701600e-02j] dt = UTCDateTime(2009, 1, 1) client = Client('*****@*****.**', host='erde.geophysik.uni-muenchen.de', port=18001) # fetch poles and zeros paz = client.get_paz('BW', 'MANZ', '', 'EHZ', dt) self.assertEqual(len(poles), 2) self.assertEqual(poles, paz['poles'][:2])
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_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_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_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_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_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_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_getInventory(self): """ Tests get_inventory method on various ArcLink nodes. """ client = Client(user="******") dt = UTCDateTime(2010, 1, 1) # 1 - GE network result = client.get_inventory("GE", "APE", starttime=dt, endtime=dt + 1) self.assertIn("GE", result) self.assertIn("GE.APE", result) # 2 - GE network result = client.get_inventory("GE", "APE", "", "BHE", starttime=dt, endtime=dt + 1, instruments=True) self.assertIn("GE", result) self.assertIn("GE.APE", result) self.assertIn("GE.APE..BHE", result) # only for instruments=True # 3 - BW network result = client.get_inventory("BW", "RJOB", starttime=dt, endtime=dt + 1) self.assertIn("BW", result) self.assertIn("BW.RJOB", result) # 4 - BW network result = client.get_inventory("BW", "MANZ", "", "EHE", starttime=dt, endtime=dt + 1, instruments=True) self.assertIn("BW", result) self.assertIn("BW.MANZ", result) self.assertIn("BW.MANZ..EHE", result) # 5 - unknown network 00 via webdc.eu:18002 self.assertRaises(ArcLinkException, client.get_inventory, "00", "", starttime=dt, endtime=dt + 1) # 6 - get channel gain without PAZ start = UTCDateTime("1970-01-01 00:00:00") end = UTCDateTime("2020-10-19 00:00:00") result = client.get_inventory("BW", "MANZ", "", "EHE", start, end) self.assertIn("BW", result) self.assertIn("BW.MANZ", result) self.assertIn("BW.MANZ..EHE", result) self.assertEqual(len(result["BW.MANZ..EHE"]), 2) self.assertIn("gain", result["BW.MANZ..EHE"][0]) self.assertNotIn("paz", result["BW.MANZ..EHE"][0]) # 7 - history of instruments # GE.SNAA sometimes needs a while therefore we use command_delay=0.1 client = Client(user="******", command_delay=0.1) result = client.get_inventory("GE", "SNAA", "", "BHZ", start, end, instruments=True) self.assertIn("GE", result) self.assertIn("GE.SNAA", result) self.assertIn("GE.SNAA..BHZ", result) self.assertEqual(len(result["GE.SNAA..BHZ"]), 4) # sort channel results channel = result["GE.SNAA..BHZ"] channel = sorted(channel, key=operator.itemgetter("starttime")) # check for required attributes self.assertEqual(channel[0].starttime, UTCDateTime("1997-03-03")) self.assertEqual(channel[0].endtime, UTCDateTime("1999-10-11")) self.assertEqual(channel[0].gain, 596224500.0) self.assertEqual(channel[1].starttime, UTCDateTime("1999-10-11")) self.assertEqual(channel[1].endtime, UTCDateTime("2003-01-10")) self.assertEqual(channel[1].gain, 596224500.0) self.assertEqual(channel[2].starttime, UTCDateTime("2003-01-10")) self.assertEqual(channel[2].endtime, UTCDateTime(2011, 1, 15, 9, 56)) self.assertEqual(channel[2].gain, 588000000.0)
def test_save_waveform_no_compression(self): """ Explicitly disable compression during waveform request and save it directly to disk. """ # initialize client client = Client(user='******') start = UTCDateTime(2010, 1, 1, 0, 0) end = start + 1 # MiniSEED with NamedTemporaryFile(suffix='.bz2') as tf: mseedfile = tf.name client.save_waveforms(mseedfile, 'GE', 'APE', '', 'BHZ', start, end, compressed=False) st = read(mseedfile) # MiniSEED may not start with Volume Index Control Headers (V) with open(mseedfile, 'rb') as fp: self.assertNotEqual(fp.read(8)[6:7], b"V") # ArcLink cuts on record base self.assertEqual(st[0].stats.network, 'GE') self.assertEqual(st[0].stats.station, 'APE') self.assertEqual(st[0].stats.location, '') self.assertEqual(st[0].stats.channel, 'BHZ') # Full SEED with NamedTemporaryFile(suffix='.bz2') as tf: fseedfile = tf.name client.save_waveforms(fseedfile, 'GE', 'APE', '', 'BHZ', start, end, format='FSEED') st = read(fseedfile) # Full SEED client.save_waveforms(fseedfile, 'BW', 'MANZ', '', 'EHZ', start, end, format='FSEED') # ArcLink cuts on record base self.assertEqual(st[0].stats.network, 'GE') self.assertEqual(st[0].stats.station, 'APE') self.assertEqual(st[0].stats.location, '') self.assertEqual(st[0].stats.channel, 'BHZ')
def ARC_available(input_dics, event, target_path, event_number): """ Check the availability of ArcLink stations """ print "Check the availability of ArcLink stations" client_arclink = Client_arclink(user='******', timeout=input_dics['arc_avai_timeout']) Sta_arc = [] try: inventories = client_arclink.getInventory( network=input_dics['net'], station=input_dics['sta'], location=input_dics['loc'], channel=input_dics['cha'], starttime=UTCDateTime(event['t1']), endtime=UTCDateTime(event['t2']), min_latitude=input_dics['mlat_rbb'], max_latitude=input_dics['Mlat_rbb'], min_longitude=input_dics['mlon_rbb'], max_longitude=input_dics['Mlon_rbb']) for inv_key in inventories.keys(): netsta = inv_key.split('.') if len(netsta) == 4: sta = '%s.%s' % (netsta[0], netsta[1]) if not inventories[sta]['depth']: inventories[sta]['depth'] = 0.0 Sta_arc.append([ netsta[0], netsta[1], netsta[2], netsta[3], inventories[sta]['latitude'], inventories[sta]['longitude'], inventories[sta]['elevation'], inventories[sta]['depth'] ]) except Exception as e: exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+') ee = 'arclink -- Event: %s --- %s\n' % (str(event_number + 1), e) exc_file.writelines(ee) exc_file.close() print 'ERROR: %s' % ee if len(Sta_arc) == 0: Sta_arc.append([]) Sta_arc.sort() return Sta_arc
def test_saveWaveformNoCompression(self): """ Explicitly disable compression during waveform request and save it directly to disk. """ # initialize client client = Client(user="******") start = UTCDateTime(2010, 1, 1, 0, 0) end = start + 1 # MiniSEED with NamedTemporaryFile(suffix=".bz2") as tf: mseedfile = tf.name client.save_waveforms(mseedfile, "GE", "APE", "", "BHZ", start, end, compressed=False) st = read(mseedfile) # MiniSEED may not start with Volume Index Control Headers (V) with open(mseedfile, "rb") as fp: self.assertNotEqual(fp.read(8)[6:7], b"V") # ArcLink cuts on record base self.assertEqual(st[0].stats.network, "GE") self.assertEqual(st[0].stats.station, "APE") self.assertEqual(st[0].stats.location, "") self.assertEqual(st[0].stats.channel, "BHZ") # Full SEED with NamedTemporaryFile(suffix=".bz2") as tf: fseedfile = tf.name client.save_waveforms(fseedfile, "GE", "APE", "", "BHZ", start, end, format="FSEED") st = read(fseedfile) # Full SEED client.save_waveforms(fseedfile, "BW", "MANZ", "", "EHZ", start, end, format="FSEED") # ArcLink cuts on record base self.assertEqual(st[0].stats.network, "GE") self.assertEqual(st[0].stats.station, "APE") self.assertEqual(st[0].stats.location, "") self.assertEqual(st[0].stats.channel, "BHZ")
def test_get_stations(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 result = client.get_stations(start, end, 'BW') self.assertTrue( AttribDict({'remark': '', 'code': 'RWMO', 'elevation': 763.0, 'description': 'Wildenmoos, Bavaria, BW-Net', 'start': UTCDateTime(2006, 7, 4, 0, 0), 'restricted': False, 'archive_net': '', 'longitude': 12.729887, 'affiliation': 'BayernNetz', 'depth': None, 'place': 'Wildenmoos', 'country': ' BW-Net', 'latitude': 47.744171, 'end': None}) in result)
def ARC_available(input_dics, event, target_path, event_number): """ Check the availability of ArcLink stations """ print "Check the availability of ArcLink stations" client_arclink = Client_arclink(user='******', timeout=input_dics['arc_avai_timeout']) Sta_arc = [] try: inventories = client_arclink.getInventory( network=input_dics['net'], station=input_dics['sta'], location=input_dics['loc'], channel=input_dics['cha'], starttime=UTCDateTime(event['t1']), endtime=UTCDateTime(event['t2']), min_latitude=input_dics['mlat_rbb'], max_latitude=input_dics['Mlat_rbb'], min_longitude=input_dics['mlon_rbb'], max_longitude=input_dics['Mlon_rbb']) for inv_key in inventories.keys(): netsta = inv_key.split('.') if len(netsta) == 4: sta = '%s.%s' % (netsta[0], netsta[1]) if not inventories[sta]['depth']: inventories[sta]['depth'] = 0.0 Sta_arc.append([netsta[0], netsta[1], netsta[2], netsta[3], inventories[sta]['latitude'], inventories[sta]['longitude'], inventories[sta]['elevation'], inventories[sta]['depth']]) except Exception as e: exc_file = open(os.path.join(target_path, 'info', 'exception'), 'a+') ee = 'arclink -- Event: %s --- %s\n' % (str(event_number+1), e) exc_file.writelines(ee) exc_file.close() print 'ERROR: %s' % ee if len(Sta_arc) == 0: Sta_arc.append([]) Sta_arc.sort() return Sta_arc
def test_getWaveformUnknownUser(self): """ Unknown user raises an ArcLinkException: DENIED. """ client = Client(host="webdc.eu", port=36000, user="******") # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 self.assertRaises(ArcLinkException, client.get_waveforms, 'GE', 'APE', '', 'BHZ', start, end)
def test_get_waveform_wrong_pattern(self): """ """ # initialize client client = Client(user='******') # example 1 start = UTCDateTime(2008, 1, 1) end = start + 1 self.assertRaises(ArcLinkException, client.get_waveforms, 'BW', 'MAN*', '', '*', start, end)
def test_getInventoryInstrumentChange(self): """ Check results of get_inventory 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") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv["GE.SNAA..BHZ"]), 1) # two instruments in given time span dt = UTCDateTime("2003-01-09T23:59:59") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv["GE.SNAA..BHZ"]), 2) # one instrument in given time span dt = UTCDateTime("2003-01-10T00:00:00") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv["GE.SNAA..BHZ"]), 1)
def test_get_waveform_no_password(self): """ No password raises a "EVPError: bad decrypt". """ client = Client(host="webdc.eu", port=36000, user="******", dcid_keys={'BIA': ''}) # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 self.assertRaises(EVPError, client.get_waveforms, 'GE', 'APE', '', 'BHZ', start, end)
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_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_get_inventory_instrument_change(self): """ Check results of get_inventory 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") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv['GE.SNAA..BHZ']), 1) # two instruments in given time span dt = UTCDateTime("2003-01-09T23:59:59") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv['GE.SNAA..BHZ']), 2) # one instrument in given time span dt = UTCDateTime("2003-01-10T00:00:00") inv = client.get_inventory("GE", "SNAA", "", "BHZ", dt, dt + 10, instruments=True, route=False) self.assertTrue(len(inv['GE.SNAA..BHZ']), 1)
def test_get_waveform_wrong_password(self): """ A wrong password password raises exception. """ client = Client(host="webdc.eu", port=36000, user="******", dcid_keys={'BIA': 'WrongPassword'}) # request data start = UTCDateTime(2010, 1, 1, 10, 0, 0) end = start + 100 self.assertRaises(Exception, client.get_waveforms, 'GE', 'APE', '', 'BHZ', start, end)
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