def test_station_to_seisan(self): from obspy.clients.fdsn import Client from obspy import UTCDateTime from eqcorrscan.utils.sfile_util import stationtoseisan t1 = UTCDateTime(2012, 3, 26) t2 = UTCDateTime(2012, 4, 26) client = Client('GEONET') bulk = [('NZ', 'FOZ', '*', '*', t1, t2), ('NZ', 'JCZ', '*', '*', t1, t2), ('NZ', 'WVZ', '*', '*', t1, t2)] inventory = client.get_stations_bulk(bulk, level="channel") for station in inventory[0]: sta_str = stationtoseisan(station) self.assertEqual(len(sta_str), 27) for station in inventory[0]: station.latitude = abs(station.latitude) station.longitude = abs(station.longitude) sta_str = stationtoseisan(station) self.assertEqual(len(sta_str), 27) with self.assertRaises(IOError): inventory = client.get_stations_bulk(bulk) for station in inventory[0]: sta_str = stationtoseisan(station)
def circle_map( stations: List[str] = None, client: Client = None, time: UTCDateTime = None, output: str = None, ): import warnings stations = stations or ["CMWZ", "BSWZ", "TCW", "BHW", "WEL"] client = client or Client("GEONET") time = time or UTCDateTime(2019, 12, 8) bulk = [("*", sta, "*", "*", UTCDateTime(0), UTCDateTime()) for sta in stations] with warnings.catch_warnings(): warnings.simplefilter( "ignore") # GeoNet doesn't pass xml version properly inv = client.get_stations_bulk(bulk, level="channel") # Select the correct time and just vertical channels inv = inv.select(time=time) # Take either EHZ or HHZ or SHZ or BNZ channels acceptable_channels = ("EHZ", "HHZ") for net in inv: for sta in net: sta.channels = [ chan for chan in sta.channels if chan.code in acceptable_channels ] CircleMap(inventory=inv).plot(output=output) return
def test_redirection(self): """ Tests the redirection of GET and POST requests. We redirect everything if not authentication is used. IRIS runs three services to test it: http://ds.iris.edu/files/redirect/307/station/1 http://ds.iris.edu/files/redirect/307/dataselect/1 http://ds.iris.edu/files/redirect/307/event/1 """ c = Client("IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1"}, user_agent=USER_AGENT) st = c.get_waveforms( network="IU", station="ANMO", location="00", channel="BHZ", starttime=UTCDateTime("2010-02-27T06:30:00.000"), endtime=UTCDateTime("2010-02-27T06:30:01.000")) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) inv = c.get_stations( starttime=UTCDateTime("2000-01-01"), endtime=UTCDateTime("2001-01-01"), network="IU", station="ANMO", level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks))) cat = c.get_events(starttime=UTCDateTime("2001-01-07T01:00:00"), endtime=UTCDateTime("2001-01-07T01:05:00"), catalog="ISC") # Just make sure something is being downloaded. self.assertTrue(bool(len(cat))) # Also test the bulk requests which are done using POST requests. bulk = (("TA", "A25A", "", "BHZ", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01")), ("TA", "A25A", "", "BHE", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01"))) st = c.get_waveforms_bulk(bulk, quality="B", longestonly=False) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) starttime = UTCDateTime(1990, 1, 1) endtime = UTCDateTime(1990, 1, 1) + 10 bulk = [ ["IU", "ANMO", "", "BHE", starttime, endtime], ["IU", "CCM", "", "BHZ", starttime, endtime], ] inv = c.get_stations_bulk(bulk, level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks)))
def setUpClass(cls): log = logging.getLogger(mag_calc.__name__) cls._log_handler = MockLoggingHandler(level='DEBUG') log.addHandler(cls._log_handler) cls.log_messages = cls._log_handler.messages client = Client("GEONET") cls.event = client.get_events(eventid="2019p498440")[0] origin_time = cls.event.preferred_origin().time bulk = [(p.waveform_id.network_code, p.waveform_id.station_code, p.waveform_id.location_code, p.waveform_id.channel_code, origin_time - 10, origin_time + 120) for p in cls.event.picks] cls.inventory = client.get_stations_bulk(bulk, level='response') cls.st = client.get_waveforms_bulk(bulk) cls.available_stations = len( {p.waveform_id.station_code for p in cls.event.picks})
def setUpClass(cls): starttime = UTCDateTime(2019, 8, 12, 10) endtime = UTCDateTime(2019, 8, 13) client = Client("GEONET") catalog = client.get_events(starttime=starttime, endtime=endtime, latitude=-44.5, longitude=167.9, maxradius=0.2) catalog.events.sort( key=lambda e: (e.preferred_origin() or e.origins[0]).time) StationInfo = namedtuple("StationInfo", ["network", "station", "location"]) picked_stations = [ StationInfo(p.waveform_id.network_code, p.waveform_id.station_code, p.waveform_id.location_code) for ev in catalog for p in ev.picks ] stations_to_download = [ sta for sta, _ in Counter(picked_stations).most_common(5) ] streams = [] for event in catalog[0:10]: # Just get the first 10 events print(event.preferred_origin().time) stream = Stream() for station in stations_to_download: print(station) try: stream += client.get_waveforms( network=station.network, station=station.station, location=station.location, channel="HH?", starttime=event.preferred_origin().time - 10, endtime=event.preferred_origin().time + 80) except IncompleteRead: print(f"Could not download {station.station}") streams.append(stream) picked_stations = set(picked_stations) inv_bulk = [(sta.network, sta.station, sta.location, "HH?", starttime, endtime) for sta in picked_stations] inventory = client.get_stations_bulk(inv_bulk, level="channel") cls.streams = streams cls.catalog = catalog cls.inventory = inventory
def main(): """Reads config.ini then downloads IRIS waveforms to build a .kml inventory and .mseed file from them. Finally saves images of each waveform plot""" # Set up initial variables dm = directory_manager() cm = config_manager() IRIS_client = Client("IRIS") cm.startup_updater() request_info = cm.obspy_request_info() dm.update_time(cm.time) dm.update_directory() dm.make_directory() cd = dm.current_directory base_fn = cm.time.isoformat().replace(":", "").replace(".", "") inv_fn = base_fn + ".kml" stream_fn = base_fn + ".mseed" dm_inv_fn = cd + "/" + inv_fn dm_stream_fn = cd + "/" + stream_fn # Send server requests for inventory and instrument traces print("Building Inventory...") inventory = IRIS_client.get_stations_bulk(request_info, level='response') print("Gathering Waveforms from IRIS server. This may take a while...") stream = IRIS_client.get_waveforms_bulk(request_info) print("Completed.") # Write data to file, create instrument waveform plots, # and save them in the appropriate directory print("Writing Files...") inventory.write(base_fn, format="KML") shutil.move(inv_fn, cd) stream.write(stream_fn, format="MSEED") shutil.move(stream_fn, cd) for x in range(len(stream)): trace = stream[x] fn = str(trace.id) + ".PNG" plot_fn = cd + "/" + fn trace.plot(outfile=fn, size=(1600, 500), format="PNG") shutil.move(fn, cd) cm.write_network_config() print("Completed. Seismology Time!")
def test_redirection_auth(self): """ Tests the redirection of GET and POST requests using authentication. By default these should not redirect and an exception is raised. """ # Clear the cache. Client._Client__service_discovery_cache.clear() # The error will already be raised during the initialization in most # cases. self.assertRaises( FDSNRedirectException, Client, "IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1" }, user="******", password="******", user_agent=USER_AGENT) # The force_redirect flag overwrites that behaviour. c_auth = Client( "IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1" }, user="******", password="******", user_agent=USER_AGENT, force_redirect=True) st = c_auth.get_waveforms( network="IU", station="ANMO", location="00", channel="BHZ", starttime=UTCDateTime("2010-02-27T06:30:00.000"), endtime=UTCDateTime("2010-02-27T06:30:01.000")) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) inv = c_auth.get_stations(starttime=UTCDateTime("2000-01-01"), endtime=UTCDateTime("2001-01-01"), network="IU", station="ANMO", level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks))) cat = c_auth.get_events(starttime=UTCDateTime("2001-01-07T01:00:00"), endtime=UTCDateTime("2001-01-07T01:05:00"), catalog="ISC") # Just make sure something is being downloaded. self.assertTrue(bool(len(cat))) # Also test the bulk requests which are done using POST requests. bulk = (("TA", "A25A", "", "BHZ", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01")), ("TA", "A25A", "", "BHE", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01"))) st = c_auth.get_waveforms_bulk(bulk, quality="B", longestonly=False) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) starttime = UTCDateTime(1990, 1, 1) endtime = UTCDateTime(1990, 1, 1) + 10 bulk = [ ["IU", "ANMO", "", "BHE", starttime, endtime], ["IU", "CCM", "", "BHZ", starttime, endtime], ] inv = c_auth.get_stations_bulk(bulk, level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks)))
def test_redirection(self): """ Tests the redirection of GET and POST requests. We redirect everything if not authentication is used. IRIS runs three services to test it: http://ds.iris.edu/files/redirect/307/station/1 http://ds.iris.edu/files/redirect/307/dataselect/1 http://ds.iris.edu/files/redirect/307/event/1 """ c = Client("IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1" }, user_agent=USER_AGENT) st = c.get_waveforms(network="IU", station="ANMO", location="00", channel="BHZ", starttime=UTCDateTime("2010-02-27T06:30:00.000"), endtime=UTCDateTime("2010-02-27T06:30:01.000")) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) inv = c.get_stations(starttime=UTCDateTime("2000-01-01"), endtime=UTCDateTime("2001-01-01"), network="IU", station="ANMO", level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks))) cat = c.get_events(starttime=UTCDateTime("2001-01-07T01:00:00"), endtime=UTCDateTime("2001-01-07T01:05:00"), catalog="ISC") # Just make sure something is being downloaded. self.assertTrue(bool(len(cat))) # Also test the bulk requests which are done using POST requests. bulk = (("TA", "A25A", "", "BHZ", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01")), ("TA", "A25A", "", "BHE", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01"))) st = c.get_waveforms_bulk(bulk, quality="B", longestonly=False) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) starttime = UTCDateTime(1990, 1, 1) endtime = UTCDateTime(1990, 1, 1) + 10 bulk = [ ["IU", "ANMO", "", "BHE", starttime, endtime], ["IU", "CCM", "", "BHZ", starttime, endtime], ] inv = c.get_stations_bulk(bulk, level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks)))
def test_redirection_auth(self): """ Tests the redirection of GET and POST requests using authentication. By default these should not redirect and an exception is raised. """ # Clear the cache. Client._Client__service_discovery_cache.clear() # The error will already be raised during the initialization in most # cases. self.assertRaises( FDSNRedirectException, Client, "IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1"}, user="******", password="******", user_agent=USER_AGENT) # The force_redirect flag overwrites that behaviour. c_auth = Client("IRIS", service_mappings={ "station": "http://ds.iris.edu/files/redirect/307/station/1", "dataselect": "http://ds.iris.edu/files/redirect/307/dataselect/1", "event": "http://ds.iris.edu/files/redirect/307/event/1"}, user="******", password="******", user_agent=USER_AGENT, force_redirect=True) st = c_auth.get_waveforms( network="IU", station="ANMO", location="00", channel="BHZ", starttime=UTCDateTime("2010-02-27T06:30:00.000"), endtime=UTCDateTime("2010-02-27T06:30:01.000")) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) inv = c_auth.get_stations( starttime=UTCDateTime("2000-01-01"), endtime=UTCDateTime("2001-01-01"), network="IU", station="ANMO", level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks))) cat = c_auth.get_events(starttime=UTCDateTime("2001-01-07T01:00:00"), endtime=UTCDateTime("2001-01-07T01:05:00"), catalog="ISC") # Just make sure something is being downloaded. self.assertTrue(bool(len(cat))) # Also test the bulk requests which are done using POST requests. bulk = (("TA", "A25A", "", "BHZ", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01")), ("TA", "A25A", "", "BHE", UTCDateTime("2010-03-25T00:00:00"), UTCDateTime("2010-03-25T00:00:01"))) st = c_auth.get_waveforms_bulk(bulk, quality="B", longestonly=False) # Just make sure something is being downloaded. self.assertTrue(bool(len(st))) starttime = UTCDateTime(1990, 1, 1) endtime = UTCDateTime(1990, 1, 1) + 10 bulk = [ ["IU", "ANMO", "", "BHE", starttime, endtime], ["IU", "CCM", "", "BHZ", starttime, endtime], ] inv = c_auth.get_stations_bulk(bulk, level="network") # Just make sure something is being downloaded. self.assertTrue(bool(len(inv.networks)))