def setUp(self): # directory where the test files are located self.path = os.path.dirname(__file__) self.datapath = os.path.join(self.path, "data") self.client = Client(base_url="IRIS", user_agent=USER_AGENT) self.client_auth = \ Client(base_url="IRIS", user_agent=USER_AGENT, user="******", password="******")
def test_setting_service_provider_mappings(self, download_url_mock): """ Tests the setting of per service endpoints """ base_url = "http://example.com" # Replace all. download_url_mock.return_value = (404, None) # Some custom urls base_url_event = "http://other_url.com/beta/event_service/11" base_url_station = "http://some_url.com/beta2/stat_serv/7" base_url_ds = "http://new.com/beta3/waveforms/8" # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url, service_mappings={ "event": base_url_event, "station": base_url_station, "dataselect": base_url_ds, }) except FDSNException: pass expected_urls = sorted([ "%s/contributors" % base_url_event, "%s/catalogs" % base_url_event, "%s/application.wadl" % base_url_event, "%s/application.wadl" % base_url_station, "%s/application.wadl" % base_url_ds, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls) # Replace only two. The others keep the default mapping. download_url_mock.reset_mock() download_url_mock.return_value = (404, None) # Some custom urls base_url_station = "http://some_url.com/beta2/stat_serv/7" base_url_ds = "http://new.com/beta3/waveforms/8" # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url, service_mappings={ "station": base_url_station, "dataselect": base_url_ds, }) except FDSNException: pass expected_urls = sorted([ "%s/fdsnws/event/1/contributors" % base_url, "%s/fdsnws/event/1/catalogs" % base_url, "%s/fdsnws/event/1/application.wadl" % base_url, "%s/application.wadl" % base_url_station, "%s/application.wadl" % base_url_ds, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls)
def __init__(self, *args, **kwargs): """ setupClass() would be better suited for the task at hand but is not supported by Python 2.6. """ super(ClientTestCase, self).__init__(*args, **kwargs) # directory where the test files are located self.path = os.path.dirname(__file__) self.datapath = os.path.join(self.path, "data") self.client = Client(base_url="IRIS", user_agent=USER_AGENT) self.client_auth = \ Client(base_url="IRIS", user_agent=USER_AGENT, user="******", password="******")
def data_download(stations, starttime, endtime, event_name): print "\n========================================" print "event:", event_name print "time:", starttime, endtime waveforms_folder = "waveforms/" + event_name stationxml_folder = "stationxml/" + event_name c = Client("IRIS") if not os.path.exists(waveforms_folder): os.makedirs(waveforms_folder) if not os.path.exists(stationxml_folder): os.makedirs(stationxml_folder) for network, station in stations: ### First download waveforms. filename = os.path.join(waveforms_folder, "%s.%s.mseed" % (network, station)) if os.path.exists(filename): continue try: c.get_waveforms(network=network, station=station, location="*", channel="BH?", starttime=starttime, endtime=endtime, filename=filename) except Exception as e: print("Failed to download %s.%s due to %s" % (network, station, str(e))) continue print("Successfully downloaded %s." % filename) ### ### Then download stationxml file stationxml_filename = os.path.join(stationxml_folder, "%s.%s.xml" % (network, station)) if os.path.exists(stationxml_filename): continue try: c.get_stations(network=network, station=station, location="*", channel="BH?", starttime=starttime, endtime=endtime, filename=stationxml_filename, level="response") except Exception as e: print("Failed to download %s.%s StationXML due to %s" % (network, station, str(e))) continue print("Successfully downloaded %s." % stationxml_filename)
def fetchinventory(self): '''Get an obspy inventory containing all the station information''' self.client = Client( "IRIS") #eventuually change so that we can get data from elsewhere self.Iclient = iclient() if self.station != 'None': self.inventory = self.client.get_stations( network=self.network, station=self.station, level='channel', channel=self.channel, starttime=self.starttime, endtime=self.endtime, minlongitude=self.minlongitude, minlatitude=self.minlatitude, maxlongitude=self.maxlongitude, maxlatitude=self.maxlatitude) else: self.inventory = self.client.get_stations( network=self.network, station=None, level='channel', channel=self.channel, starttime=self.starttime, endtime=self.endtime, minlongitude=self.minlongitude, minlatitude=self.minlatitude, maxlongitude=self.maxlongitude, maxlatitude=self.maxlatitude)
def test_manually_deactivate_single_service(self): """ Test manually deactivating a single service. """ client = Client(base_url="IRIS", user_agent=USER_AGENT, service_mappings={"event": None}) self.assertEqual(sorted(client.services.keys()), ['dataselect', 'station'])
def get_events(self): """ Method to fetch updated list of events to use in plot. """ with self.lock: start = min([tr.stats.starttime for tr in self.stream]) end = max([tr.stats.endtime for tr in self.stream]) neries_emsc = Client("EMSC") events = neries_emsc.get_events(starttime=start, endtime=end, minmagnitude=self.args.events) return events
def get_IRIS_WebServices_Catalog(): '''Get the IRIS catalog and print the response''' client = Client('IRIS') starttime = obspy.core.utcdatetime.UTCDateTime('2014-01-01') endtime = obspy.core.utcdatetime.UTCDateTime('2014-05-25') catalog = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=4, catalog='ISC') print('catalog', catalog)
def _getTemData(templatekey, stakey, templateDir, formatout, removeResponse, prefilt, client, timeBeforeOrigin, timeAfterOrigin, loc, opType): HD = os.getcwd() # Get current directory client = Client(client) for temkey in templatekey.iterrows( ): # iterate through each template key row eventID = temkey[1]['NAME'] SK = stakey SK = SK[[not np.isnan(x) for x in SK.LAT]] try: oTime = obspy.core.UTCDateTime(temkey[1]['TIME']) # origin time except: detex.log(__name__, '%s is a bad entry in TIME column for event %s' % (temkey[1]['TIME'], temkey[1]['NAME']), level='error') raise Exception('%s is a bad entry in TIME column for event %s' % (temkey[1]['TIME'], temkey[1]['NAME'])) utcStart = oTime - timeBeforeOrigin # start time is event origin time minus timeBeforeOrigin utcEnd = oTime + timeAfterOrigin # end time is event origin time plus timeafterOrigin for sk in SK.iterrows(): # iterate through each row of station keys chans = sk[1]['CHANNELS'].replace('-', ',') net = sk[1]['NETWORK'] sta = sk[1]['STATION'] st = True UTCstr = '%04d-%03dT%02d-%02d-%02d' % (oTime.year, oTime.julday, oTime.hour, oTime.minute, oTime.second) sdir = os.path.join(HD, templateDir, eventID).replace(' ', '') svar = ('%s.%s.%s.pkl' % (net, sta, UTCstr)).replace(' ', '') if os.path.isfile(os.path.join( sdir, svar)): #IF file aready exits skip process #detex.log(__name__,'%s already exists'%svar) st = False if st != False: st = _tryDownloadData(net, sta, chans, loc, utcStart, utcEnd, client) if st != False: #_tryDownloadData can return false, second st check is needed if (temkey[0] + 1) % 25 == 0: detex.log( __name__, '%d events downloaded out of %d for Station %s' % (temkey[0] + 1, len(templatekey), sk[1].STATION), pri=True) if removeResponse == True: st = _removeInstrumentResposne(st, prefilt, opType) if st != False: if not os.path.isdir( sdir ): # Create Waveform sub directory if it does not exis os.makedirs(sdir) st.write(os.path.join(sdir, svar), formatout)
def _getConData(stakey, loc, ConDir, client, formatout, removeResponse, prefilt, secBuf, opType, multiPro, reverse): HD = os.getcwd() # Get current directory client = Client(client) if multiPro == True: #This is still broken sklist = [None] * len(stakey) for sk in stakey.iterrows(): sklist[sk[ 0]] = sk, HD, ConDir, removeResponse, prefilt, opType, formatout, secBuf, loc, client joblib.Parallel(n_jobs=len(sklist))( joblib.delayed(_getConDataStation)(i) for i in sklist) else: for sk in stakey.iterrows( ): # iterate through eaceh station in the current key _getConDataStation(sk, HD, ConDir, removeResponse, prefilt, opType, formatout, secBuf, loc, client, reverse)
def _get_client(client_name): try: this_client = Client(client_name) except utils.ERRORS as e: if "timeout" in str(e).lower(): extra = " (timeout)" else: extra = "" logger.warn("Failed to initialize client '%s'.%s" % (client_name, extra)) return client_name, None services = sorted([_i for _i in this_client.services.keys() if not _i.startswith("available")]) if "dataselect" not in services or "station" not in services: logger.info("Cannot use client '%s' as it does not have " "'dataselect' and/or 'station' services." % client_name) return client_name, None return client_name, this_client
def getSlowestStation(lat,lon,depth,calc): client = Client("IRIS") inventory = client.get_stations(latitude=lat, longitude=lon,maxradius=1.5) lats = [] lons = [] codes = [] for network in inventory.networks: for station in network.stations: lats.append(station.latitude) lons.append(station.longitude) codes.append(station.code) lats = np.array(lats) lons = np.array(lons) codes = np.array(codes) distances = [] times = [] for i in range(0,len(lats)): slat = lats[i] slon = lons[i] distance = locations2degrees(lat,lon,slat,slon) distances.append(distance) ptime,stime = calc.getTravelTimes(distance,depth) times.append(ptime) times = np.array(times) distances = np.array(distances) sortidx = np.argsort(distances) distances = distances[sortidx] times = times[sortidx] lats = lats[sortidx] lons = lons[sortidx] codes = codes[sortidx] distances = distances[0:4] times = times[0:4] + TELEMETRY_DELAY + PROCESSING_DELAY lats = lats[0:4] lons = lons[0:4] codes = codes[0:4] idx = times.argmax() sdict = {'lat':lats[idx],'lon':lons[idx],'time':times[idx],'code':codes[idx]} return sdict
def _download_bulk_waveforms( (event, networks, stations, start_times, end_times, download_path, event_xml_directory, recording_time, padding_time)): time.sleep(1) c = Client("IRIS") # Make directory. utils.mkdir_p(os.path.join(download_path, event)) filename = os.path.join(download_path, event, 'data.mseed') # Don't re-download files. if os.path.exists(filename): return # Find start time and end time. event_info = os.path.join(event_xml_directory, event + '.xml') tree = ET.parse(event_info) root = tree.getroot() for tag in root.iter(): if tag.tag == XML_STRING + 'time': time.start = obspy.UTCDateTime( tag.findall(XML_STRING + 'value')[0].text) - padding_time time.end = time.start + recording_time + 2 * padding_time break # Set up request. bulk = [] for x, y, s_time, e_time in zip(networks, stations, start_times, end_times): if time.start < s_time or time.start > e_time: continue bulk.append((x, y, '*', '*H*', time.start, time.end)) utils.print_ylw('Downloading %s...' % (event)) c.get_waveforms_bulk(bulk, filename=filename, quality='B')
def test_default_requested_urls(self, download_url_mock): """ Five request should be sent upon initializing a client. Test these. """ download_url_mock.return_value = (404, None) base_url = "http://example.com" # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url) except FDSNException: pass expected_urls = sorted([ "%s/fdsnws/event/1/contributors" % base_url, "%s/fdsnws/event/1/catalogs" % base_url, "%s/fdsnws/event/1/application.wadl" % base_url, "%s/fdsnws/station/1/application.wadl" % base_url, "%s/fdsnws/dataselect/1/application.wadl" % base_url, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls)
import numpy as np import obspy from obspy.fdsn import Client from obspy import UTCDateTime import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib as mpl import matplotlib.gridspec as gridspec from mpl_toolkits.basemap import Basemap from matplotlib import animation # # Set up time window and filter bands # client = Client("IRIS") origintime = UTCDateTime("2011-08-23T17:51:00.000") starttime = UTCDateTime("2011-08-23T17:57:00.000") endtime = starttime + 300 #starttime = origintime + 200 #endtime = starttime+500 #starttime = UTCDateTime("2013-05-24T05:54:49") #endtime = UTCDateTime("2013-05-24T06:29:49") netlist = "TA" stalist = "*" loclist = "" chanlist = "LHZ" #pre_filt = (0.001, 0.006, 0.2, 0.4) pre_filt = (0.001, 0.002, 0.2, 0.4) #fmin = 0.006 fmin = 0.002
def test_download_urls_for_custom_mapping(self, download_url_mock): """ Tests the downloading of data with custom mappings. """ base_url = "http://example.com" # More extensive mock setup simulation service discovery. def custom_side_effects(*args, **kwargs): if "version" in args[0]: return 200, "1.0.200" elif "event" in args[0]: with open( os.path.join(self.datapath, "2014-01-07_iris_event.wadl")) as fh: return 200, fh.read() elif "station" in args[0]: with open( os.path.join(self.datapath, "2014-01-07_iris_station.wadl")) as fh: return 200, fh.read() elif "dataselect" in args[0]: with open( os.path.join(self.datapath, "2014-01-07_iris_dataselect.wadl")) as fh: return 200, fh.read() return 404, None download_url_mock.side_effect = custom_side_effects # Some custom urls base_url_event = "http://other_url.com/beta/event_service/11" base_url_station = "http://some_url.com/beta2/station/7" base_url_ds = "http://new.com/beta3/dataselect/8" # An exception will be raised if not actual WADLs are returned. c = Client(base_url=base_url, service_mappings={ "event": base_url_event, "station": base_url_station, "dataselect": base_url_ds, }) # Test the dataselect downloading. download_url_mock.reset_mock() download_url_mock.side_effect = None download_url_mock.return_value = 404, None try: c.get_waveforms("A", "B", "C", "D", UTCDateTime() - 100, UTCDateTime()) except: pass self.assertTrue( base_url_ds in download_url_mock.call_args_list[0][0][0]) # Test the station downloading. download_url_mock.reset_mock() download_url_mock.side_effect = None download_url_mock.return_value = 404, None try: c.get_stations() except: pass self.assertTrue( base_url_station in download_url_mock.call_args_list[0][0][0]) # Test the event downloading. download_url_mock.reset_mock() download_url_mock.side_effect = None download_url_mock.return_value = 404, None try: c.get_events() except: pass self.assertTrue( base_url_event in download_url_mock.call_args_list[0][0][0])
@author: boland """ from obspy.fdsn.header import URL_MAPPINGS from obspy import UTCDateTime from obspy.fdsn import Client # create example start and end times for event search starttime = UTCDateTime('2014-01-01T00:00.000') endtime = UTCDateTime('2015-01-01T00:00.000') endtime = UTCDateTime('2014-02-01T00:00.000') # create list of possible servers to find earthquake events server_list = [] for key in sorted(URL_MAPPINGS.keys()): server_list.append(key) for server in server_list: print server client = Client(server) try: cat = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=4) #, catalog="ISC") print cat cat.plot() except: continue print "done"
def test_setting_service_major_version(self, download_url_mock): """ Test the setting of custom major versions. """ download_url_mock.return_value = (404, None) base_url = "http://example.com" # Passing an empty dictionary results in the default urls. major_versions = {} # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url, major_versions=major_versions) except FDSNException: pass expected_urls = sorted([ "%s/fdsnws/event/1/contributors" % base_url, "%s/fdsnws/event/1/catalogs" % base_url, "%s/fdsnws/event/1/application.wadl" % base_url, "%s/fdsnws/station/1/application.wadl" % base_url, "%s/fdsnws/dataselect/1/application.wadl" % base_url, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls) # Replace all download_url_mock.reset_mock() download_url_mock.return_value = (404, None) major_versions = {"event": 7, "station": 8, "dataselect": 9} # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url, major_versions=major_versions) except FDSNException: pass expected_urls = sorted([ "%s/fdsnws/event/7/contributors" % base_url, "%s/fdsnws/event/7/catalogs" % base_url, "%s/fdsnws/event/7/application.wadl" % base_url, "%s/fdsnws/station/8/application.wadl" % base_url, "%s/fdsnws/dataselect/9/application.wadl" % base_url, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls) # Replace only some download_url_mock.reset_mock() download_url_mock.return_value = (404, None) major_versions = {"event": 7, "station": 8} # An exception will be raised if not actual WADLs are returned. try: Client(base_url=base_url, major_versions=major_versions) except FDSNException: pass expected_urls = sorted([ "%s/fdsnws/event/7/contributors" % base_url, "%s/fdsnws/event/7/catalogs" % base_url, "%s/fdsnws/event/7/application.wadl" % base_url, "%s/fdsnws/station/8/application.wadl" % base_url, "%s/fdsnws/dataselect/1/application.wadl" % base_url, ]) got_urls = sorted( [_i[0][0] for _i in download_url_mock.call_args_list]) self.assertEqual(expected_urls, got_urls)
# IRIS Client is used for infrasound data requests # calling IRIS client will result in a Deprecation Warning and should be ignored # from obspy.iris import Client as IrisClient from time import time import matplotlib.pyplot as plt import numpy as np import os import scipy # # WS clients # irisClient = IrisClient(user_agent=msgLib.param(param, 'userAgent').userAgent) client = Client(user_agent=msgLib.param(param, 'userAgent').userAgent) action = "" # keep track of what you are doing # # RUN ARGUMENTS: # t0 = time() t1 = fileLib.timeIt("START", t0) print "\n" msgLib.message("START") inNetwork = getParam(args, 'net', msgLib, None) inStation = getParam(args, 'sta', msgLib, None) inLocation = staLib.getLocation(getParam(args, 'loc', msgLib, None)) inChannel = getParam(args, 'chan', msgLib,
'all_stations.xml' which contains a station level StationXML file. :copyright: Lion Krischer ([email protected]), 2014 :license: GNU Lesser General Public License, Version 3 (http://www.gnu.org/copyleft/lesser.html) """ import colorama from obspy.station import read_inventory from obspy.fdsn import Client import os output_dir = "StationXML" c = Client() inv = read_inventory("./all_stations.xml") def print_error(msg): print colorama.Fore.RED + msg + colorama.Fore.RESET def print_ok(msg): print colorama.Fore.GREEN + msg + colorama.Fore.RESET for network in inv.networks: for station in network.stations: output_filename = os.path.join(
# Testing ObsPy with FDSN web services # # see http://docs.obspy.org/packages/obspy.fdsn.html # List all FDSN locations (example from link above) ---------------------------- from obspy import UTCDateTime from obspy.fdsn import Client client = Client("IRIS") from obspy.fdsn.header import URL_MAPPINGS for key in sorted(URL_MAPPINGS.keys()): print("{0:<7} {1}".format(key, URL_MAPPINGS[key])) # Inventory (from link above) -------------------------------------------------- starttime = UTCDateTime("2002-01-01") endtime = UTCDateTime("2002-01-02") inventory = client.get_stations(network="IU", station="A*", starttime=starttime, endtime=endtime) print(inventory) # NCEDC channels request ------------------------------------------------------- client = Client("NCEDC")
def queryData(self): # code from IRIS client # Here we pull the data client = Client("IRIS") DupStations = [] DupLocations = [] DupChannels = [] self.st = Stream() self.STAWILD = False self.LOCWILD = False self.CHANWILD = False try: timeout = 300 socket.setdefaulttimeout(timeout) # this needs to have a get_waveform that queries data 1 hour at a time # data cant query right now if the data is too bulky # also needs to include a timeout exception for hourIndex in range( 0, self.hours): #this cant be days... has to be hours self.startTime1 = self.startTime + (hourIndex) * 1 * 60 * 60 self.endTime1 = self.startTime + (hourIndex + 1) * 1 * 60 * 60 requestArray = [(self.network,self.station,self.location, \ self.channel,self.startTime1,self.endTime1)] self.st1 = client.get_waveforms_bulk(requestArray) self.st += self.st1 print self.st print #self.st = client.get_waveforms_bulk(timeout=10,requestArray) for self.tr in self.st: #Here we remove the M data quality and go with D self.tr.stats.mseed['dataquality'] = 'D' if self.debug: if self.station == '*': self.STAWILD = True DupStations.append(self.tr.stats.station) elif self.station != '*': self.STAWILD = False if self.location == '*': self.LOCWILD = True DupLocations.append(self.tr.stats.location) elif self.location != '*': self.LOCWILD = False if self.channel == '*': self.CHANWILD = True DupChannels.append(self.tr.stats.channel) elif self.channel != '*': self.CHANWILD = False #except TimeoutError: #print 'Get waveform timeout, exiting...' #sys.exit(0) except: print 'Trouble getting data' sys.exit(0) # Takes duplicate stations out of list and # makes station, location, and channel into an array # for looping( probably easier way but it works) self.stations = list(set(DupStations)) if self.station != '*': self.stations.append(self.station) self.locations = list(set(DupLocations)) if self.location != '*': self.locations.append(self.location) self.channels = list(set(DupChannels)) if self.channel != '*': self.channels.append(self.channel) print print "Station(s) being pulled: " + str(self.stations) print "Location(s) being pulled: " + str(self.locations) print "Channel(s) being pulled: " + str(self.channels) # Now call code to store streams in mseed files self.storeMSEED()
from obspy import UTCDateTime from obspy.fdsn import Client # connect to an FDSN webservice client = Client("http://erde.geophysik.uni-muenchen.de:8080") # use origin time of devastating Japan earthquake start = UTCDateTime("2011-03-11 05:46:23") + 10 * 60 end = start + 70 * 60 # download waveform and station metadata of station FUR stream = client.get_waveforms(network="GR", station="FUR", location="", channel="BH*", starttime=start, endtime=end, attach_response=True) # do basic signal processing and plot the data! ----> stream.remove_response() stream.filter("bandpass", freqmin=0.01, freqmax=1) stream.plot()
from obspy.fdsn import Client from obspy import UTCDateTime import numpy as np import matplotlib.pyplot as plt import matplotlib.mlab as ml import scipy from scipy.interpolate import griddata client = Client() def getWave(network, station, number, channel, UTC, dur): """ Downloads miniseed datasets through the obspy.fdsn function. """ t = UTCDateTime(UTC) st = client.get_waveforms(network, station, number, channel, t, t + dur, attach_response=True) print st return st def preprocess(stream): """Carries out simple preprocessing of trace, by first merging the stream, removing instrumetn response, highpass filtering at 0.2 Hz then tapering""" stream.merge() stream.remove_response(output="vel") stream.filter('highpass',freq=0.02,corners=2,zerophase=True) stream.taper(max_percentage=0.01,type='cosine') return stream def spec_amp(stream): """This produces three 1d arrays constructed after splitting the noise trace
from obspy.fdsn import Client from plotting_tools import get_coordinates # ########################## INPUT req_client = "RESIF" starttime = None endtime = None network = "YV" station = "*" location = '*' channel = '*H*' file_name = 'list_stas_created.txt' # ########################## END INPUT client = Client(req_client) if starttime: starttime = UTCDateTime(starttime) if endtime: endtime = UTCDateTime(endtime) inv = client.get_stations(network=network, station=station, location=location, channel=channel, starttime=starttime, endtime=endtime, level='channel') content = inv.get_contents() chans = list(set(content['channels'])) chans.sort()
def download_data(params, station_list, with_waveforms, recording_time, padding_time): """ Still a work in progress (perhaps never finished). Sorts a text file obtained from IRIS (see manual), and parses out the STS and KS instruments (apparently the best ones). Then passes """ # Domain boundaries min_lat = -65 max_lat = 45 min_lon = -47.5 max_lon = 75 # Set up paths and such. lasif_data_path = os.path.join(params['lasif_path'], 'DOWNLOADED_DATA') iteration_xml_path = params['iteration_xml_path'] event_xml_directory = os.path.join(params['lasif_path'], 'EVENTS') event_list = params['event_list'] lasif_stations_path = os.path.join(params['lasif_path'], 'STATIONS', 'StationXML') # Set up station tuple and allowable instruments. station = namedtuple('station', ['network', 'station', 'location', 'sensor', 's_time', 'e_time']) # Read the data and parse out the important components. stations_list = pd.read_csv(station_list, delimiter='|') stations_list.fillna('00', inplace=True) # Filter based on domain boundaries stations_list = stations_list[stations_list.Latitude > min_lat] stations_list = stations_list[stations_list.Latitude < max_lat] stations_list = stations_list[stations_list.Longitude > min_lon] stations_list = stations_list[stations_list.Longitude < max_lon] stations_list = stations_list[stations_list.Location == '00'] stations_list['StartTime'] = \ stations_list['StartTime'].astype(obspy.UTCDateTime) stations_list['EndTime'] = \ stations_list['EndTime'].astype(obspy.UTCDateTime) # Number of events. num_events = len(os.listdir(event_xml_directory)) event_names = sorted([x[:-4] for x in os.listdir(event_xml_directory)]) # Event arrays. networks = stations_list.Network stations = stations_list.Station start_time = stations_list.StartTime end_time = stations_list.EndTime # Waveforms. pool = Pool(processes=NUM_THREADS) pool.map(_download_bulk_waveforms, zip( event_names, repeat(networks), repeat(stations), repeat(start_time), repeat(end_time), repeat(lasif_data_path), repeat(event_xml_directory), repeat(recording_time), repeat(padding_time))) if with_waveforms: return # Get stations. c = Client("IRIS") for x in stations_filt: station_filename = os.path.join( lasif_stations_path, 'station.%s_%s.xml' % (x.network, x.station)) if os.path.exists(station_filename): continue utils.print_ylw( "Downloading StationXML for: %s.%s" % (x.network, x.station)) try: c.get_stations( network=x.network, station=x.station, location="*", channel="*", level="response", filename=station_filename) except: utils.print_red("No data for %s" % (station_filename))
import sys import glob import argparse print 'Importing Obspy modules...' from obspy.fdsn import Client import obspy from obspy import read import obspy.signal import pylab as plt from obspy.taup.taup import getTravelTimes from obspy.core.util import locations2degrees from obspy.iris import Client as iclient from obspy import UTCDateTime IRISclient = iclient() FDSNclient = Client('IRIS') from collections import Counter print 'Done imports' parser = argparse.ArgumentParser() parser.add_argument('-params',action='store',dest='inputfile',help='Input the name of the paramter file if you want to use this to get data') parser.add_argument('-plot',action='store',default=False,dest='plotraypath',help='Append this if you want to produce a .pdf plot of the raypaths in your request. Give the full file path') parser.add_argument('-prep',action='store',dest='inputpath',help='The full file path to the data you want to prepare for a tomography project') parser.add_argument('-phase',action='store',dest='phase',help='The seismic phase you are intersted in: This determines which SAC files are accessed and what the final output is. Choose from S or P') parser.add_argument('-Tcheck',action='store_true',default=False,dest='tcheck',help='Append to check the data directory for timing problems, and report the suspect files')
# -*- coding: utf-8 -*- """ Created on Fri Jul 17 15:38:50 2015 @author: boland """ from obspy.fdsn import Client from obspy import UTCDateTime import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.basemap import Basemap import pickle client = Client("GEONET") starttime = UTCDateTime("2014-01-01") endtime = UTCDateTime("2015-01-01") inventory = client.get_stations(network="*", station="*", loc='*', channel="*Z", starttime=starttime, endtime=endtime, level="response") # save all response plots #inventory[0].plot_response(min_freq=1E-4, # channel="BHZ", # location="10",
def get_cat(data_center=None, **kwargs): ''' Function to get catalog data from different data center data_center - specify the data center i.e. 'IRIS' Other arguments you can use: :type starttime: :class:`~obspy.core.utcdatetime.UTCDateTime`, optional :param starttime: Limit to events on or after the specified start time. :type endtime: :class:`~obspy.core.utcdatetime.UTCDateTime`, optional :param endtime: Limit to events on or before the specified end time. :type minlatitude: float, optional :param minlatitude: Limit to events with a latitude larger than the specified minimum. :type maxlatitude: float, optional :param maxlatitude: Limit to events with a latitude smaller than the specified maximum. :type minlongitude: float, optional :param minlongitude: Limit to events with a longitude larger than the specified minimum. :type maxlongitude: float, optional :param maxlongitude: Limit to events with a longitude smaller than the specified maximum. :type latitude: float, optional :param latitude: Specify the latitude to be used for a radius search. :type longitude: float, optional :param longitude: Specify the longitude to the used for a radius search. :type minradius: float, optional :param minradius: Limit to events within the specified minimum number of degrees from the geographic point defined by the latitude and longitude parameters. :type maxradius: float, optional :param maxradius: Limit to events within the specified maximum number of degrees from the geographic point defined by the latitude and longitude parameters. :type mindepth: float, optional :param mindepth: Limit to events with depth more than the specified minimum. :type maxdepth: float, optional :param maxdepth: Limit to events with depth less than the specified maximum. :type minmagnitude: float, optional :param minmagnitude: Limit to events with a magnitude larger than the specified minimum. :type maxmagnitude: float, optional :param maxmagnitude: Limit to events with a magnitude smaller than the specified maximum. :type magnitudetype: str, optional :param magnitudetype: Specify a magnitude type to use for testing the minimum and maximum limits. :type includeallorigins: bool, optional :param includeallorigins: Specify if all origins for the event should be included, default is data center dependent but is suggested to be the preferred origin only. :type includeallmagnitudes: bool, optional :param includeallmagnitudes: Specify if all magnitudes for the event should be included, default is data center dependent but is suggested to be the preferred magnitude only. :type includearrivals: bool, optional :param includearrivals: Specify if phase arrivals should be included. :type eventid: str or int (dependent on data center), optional :param eventid: Select a specific event by ID; event identifiers are data center specific. :type limit: int, optional :param limit: Limit the results to the specified number of events. :type offset: int, optional :param offset: Return results starting at the event count specified, starting at 1. :type orderby: str, optional :param orderby: Order the result by time or magnitude with the following possibilities: * time: order by origin descending time * time-asc: order by origin ascending time * magnitude: order by descending magnitude * magnitude-asc: order by ascending magnitude :type catalog: str, optional :param catalog: Limit to events from a specified catalog :type contributor: str, optional :param contributor: Limit to events contributed by a specified contributor. :type updatedafter: :class:`~obspy.core.utcdatetime.UTCDateTime`, optional :param updatedafter: Limit to events updated after the specified time. :type filename: str or open file-like object :param filename: If given, the downloaded data will be saved there instead of being parse to an ObsPy object. Thus it will contain the raw data from the webservices. ''' #get the catalog if data_center is None: data_center = 'USGS' client = Client(data_center) sio = StringIO() #save the catalog into a StringIO object cat = client.get_events(filename=sio, **kwargs) #specify the entries you want to replace with (the inconsistent ones) in the following dictionary rep = { "quarry_blast": "quarry blast", "quarry": "quarry blast", "quarry blast_blast": "quarry blast" } #replace the multiple entries, and save the modified entries into StringIO object rep = dict((re.escape(k), v) for k, v in rep.iteritems()) pattern = re.compile("|".join(rep.keys())) sio.seek(0) sio2 = StringIO() sio2.write(pattern.sub(lambda m: rep[re.escape(m.group(0))], sio.buf)) #read the catalog from this StringIO object sio2.seek(0) cat = readEvents(sio2) return cat
timelimit = utc("2005-01-01T00:00:00").timestamp # set time limit and all events before this limit will be erased # if reset_catalogue = True database_name = '/storage/MASTERS/CONFIGURATIONS/S_NETWORK/INPUT/DATABASES/timeline.db' # enter the information for catalogue 1 search minlat, maxlat, minlon, maxlon = (-40.0, -12.5, 113.0, 154.0) event_list = [] for c in client_list: print "Processing events from the {} catalogue ... \n".format(c) try: client = Client(c) catalogue = client.get_events(starttime=t1, endtime=t2, minlatitude=minlat, maxlatitude=maxlat, minlongitude=minlon, maxlongitude=maxlon) for i in catalogue: event_list.append(i) except Exception as error: print error print event_list