def get_waveforms(): events = get_events()[::-1] client = Client('GFZ') stream_raw = Stream() stream = RFStream() coords = inventory.get_coordinates(seedid[:-1] + 'Z') for i, event in enumerate(events): t = event.preferred_origin().time args = seedid.split('.') + [t + 4.9 * 60, t + 14.1 * 60] s = client.get_waveforms(*args) s.trim(t+5*60, t+14*60) s.decimate(int(round(s[0].stats.sampling_rate)) // 5, no_filter=True) stream_raw.extend(s) if i in (0, 2, 4): s = s.copy() stats = rfstats(station=coords, event=event, dist_range=(20, 95)) if stats is None: continue s.trim(stats.onset - 25, stats.onset + 75) stats = obj2stats(station=coords, event=event) s = RFStream(s) for tr in s: tr.stats.update(stats) stream.extend(s) stream_raw.write(wavname, 'MSEED') stream.write(wavname2, 'SAC')
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 get_all_mags(eventid): """Get all magnitudes for a given event ID. Args: eventid (str): ComCat Event ID. Returns: dict: Dictionary where keys are "magsrc-magtype" and values are magnitude value. """ row = {} msg = '' client = Client('USGS') try: obsevent = client.get_events(eventid=eventid).events[0] except Exception as e: msg = 'Failed to download event %s, error "%s".' % (eventid, str(e)) for mag in obsevent.magnitudes: magvalue = mag.mag magtype = mag.magnitude_type magsrc = get_mag_src(mag) colname = '%s-%s' % (magsrc, magtype) if colname in row: continue row[colname] = magvalue return (row, msg)
def fdsn_bulk_request(target_path, req_cli, input_dics): """ send bulk request to FDSN :param target_path: :param req_cli: :param input_dics: :return: """ print('\n[INFO] sending bulk request to: %s' % req_cli) client_fdsn = Client_fdsn(base_url=req_cli, user=input_dics['username_fdsn'], password=input_dics['password_fdsn']) bulk_list_fio = open(os.path.join(target_path, 'info', 'bulkdata_list_%s' % req_cli), 'rb') bulk_list = pickle.load(bulk_list_fio) bulk_smgrs = client_fdsn.get_waveforms_bulk(bulk_list) print('[INFO] saving the retrieved waveforms from %s...' % req_cli) for bulk_st in bulk_smgrs: bulk_st.write(os.path.join(target_path, 'raw', '%s.%s.%s.%s' % (bulk_st.stats['network'], bulk_st.stats['station'], bulk_st.stats['location'], bulk_st.stats['channel'])), 'MSEED')
def test_rectangular_geo_queries(self): client = FDSNClient(self.live_server_url) # lat = 48.995167 # lon = 11.519922 # This works. self.assertEqual( len(client.get_stations( minlatitude=48, maxlatitude=49, minlongitude=11, maxlongitude=12).get_contents()["stations"]), 1) # Make sure one border does not include the point at a time. with self.assertRaises(FDSNException): client.get_stations(minlatitude=48.996, maxlatitude=49, minlongitude=11, maxlongitude=12) with self.assertRaises(FDSNException): client.get_stations(minlatitude=48, maxlatitude=48.5, minlongitude=11, maxlongitude=12) with self.assertRaises(FDSNException): client.get_stations(minlatitude=48, maxlatitude=49, minlongitude=11.6, maxlongitude=12) with self.assertRaises(FDSNException): client.get_stations(minlatitude=48, maxlatitude=49, minlongitude=11, maxlongitude=11.4)
def test_level_argument(self): client = FDSNClient(self.live_server_url) inv = client.get_stations(level="channel") c = inv.get_contents() self.assertEqual(len(c["networks"]), 1) self.assertEqual(len(c["stations"]), 1) self.assertEqual(len(c["channels"]), 3) inv = client.get_stations(level="station") c = inv.get_contents() self.assertEqual(len(c["networks"]), 1) self.assertEqual(len(c["stations"]), 1) self.assertEqual(len(c["channels"]), 0) inv = client.get_stations(level="network") c = inv.get_contents() self.assertEqual(len(c["networks"]), 1) self.assertEqual(len(c["stations"]), 0) self.assertEqual(len(c["channels"]), 0) inv = client.get_stations(level="response") c = inv.get_contents() self.assertEqual(len(c["networks"]), 1) self.assertEqual(len(c["stations"]), 1) self.assertEqual(len(c["channels"]), 3) for channel in inv[0][0]: self.assertIsNotNone(channel.response)
def download(self, s): client = Client("IRIS") starttime = obspy.UTCDateTime("2010-01-01") endtime = obspy.UTCDateTime("2015-01-02") # for s in stations: # Try and download, don't worry if no data is available. try: stream = client.get_stations(network=s.net, station=s.sta, starttime=starttime, endtime=endtime, level="channel") fname = os.path.join("STATION_XML_META", "station.{}_{}.meta.xml".format(s.net, s.sta)) stream.write(fname, format='STATIONXML') except Exception as e: print e pass try: stream = client.get_stations(network=s.net, station=s.sta, starttime=starttime, endtime=endtime, level="response") fname = os.path.join("STATION_XML_META", "station.{}_{}.response.xml".format(s.net, s.sta)) stream.write(fname, format='STATIONXML') print 'Finished downloading {}.{}'.format(s.net, s.sta) except Exception as e: print e pass
def FDSN_bulk_request(i, add_event, input_dics): """ Send bulk request to FDSN """ print "\nSending bulk request to FDSN: %s" % input_dics["fdsn_base_url"] client_fdsn = Client_fdsn( base_url=input_dics["fdsn_base_url"], user=input_dics["fdsn_user"], password=input_dics["fdsn_pass"] ) bulk_list_fio = open(os.path.join(add_event[i], "info", "bulkdata_list")) bulk_list = pickle.load(bulk_list_fio) bulk_smgrs = client_fdsn.get_waveforms_bulk(bulk_list) print "Saving the retrieved waveforms...", for bulk_st in bulk_smgrs: bulk_st.write( os.path.join( add_event[i], "BH_RAW", "%s.%s.%s.%s" % ( bulk_st.stats["network"], bulk_st.stats["station"], bulk_st.stats["location"], bulk_st.stats["channel"], ), ), "MSEED", )
def create_nodes_from_fdsn(self, base_url, network_code, station_codes, channel_codes, location_codes, country_code="", node_prefix=""): ''' Creates WebObs Nodes architecture and configuration files from FDSN Web Service (fdsnws) :type base_url: str :param base_url: A string representing the FDSN provider URL. :type network_code: str :param network_code: A string representing the FDSN network code. :type station_codes: str :param station_codes: A string representing the FDSN station(s) (wildcard accepted). :type channel_codes: str :param channel_codes: A string representing the FDSN channel(s) (wildcard accepted). :type location_codes: str :param location_codes: A string representing the FDSN location code(s) (wildcard accepted). :type country_code: str, optional :param country_code: A string representing the country code. :type node_prefix: str, optional :param node_prefix: A string representing the node prefix. ''' # Connect to FDSN web service and retrieve inventory fdsn_client = Client(base_url=base_url) inventory = fdsn_client.get_stations(network=network_code, station=station_codes, channel=channel_codes, location=location_codes, level="response") for network in inventory.networks: print("Processing %s network" % (network.code)) for station in network.stations: print("|--Processing %s station" % (station.code)) # Create node name and path node_name = "%s%s%s" % (country_code, node_prefix, station.code) node_path = "%s/%s" % (self.output_dir, node_name) # Create file tree and files if not os.path.exists(node_path): os.makedirs(node_path) os.makedirs("%s/DOCUMENTS/THUMBNAILS" % (node_path)) os.makedirs("%s/FEATURES" % (node_path)) os.makedirs("%s/INTERVENTIONS" % (node_path)) os.makedirs("%s/PHOTOS/THUMBNAILS" % (node_path)) os.makedirs("%s/SCHEMAS/THUMBNAILS" % (node_path)) open("%s/acces.txt" % (node_path), 'a').close() open("%s/info.txt" % (node_path), 'a').close() open("%s/installation.txt" % (node_path), 'a').close() open("%s/%s.kml" % (node_path, node_name), 'a').close() open("%s/FEATURES/sensor.txt" % (node_path), 'a').close() open("%s/INTERVENTIONS/%s_Projet.txt" % (node_path, node_name), 'a').close() self.create_clb_file(node_path=node_path, node_name=node_name, network_code=network.code, station=station)
def inv4stream(stream, network, client_name): start = stream[0].stats.starttime end = stream[0].stats.endtime client = Client(client_name) inv = client.get_stations(network=network, starttime=start, endtime=end) return inv
def test_download_various_methods(self): """Will download data from server and store in various databases, then create templates using the various methods.""" import obspy if int(obspy.__version__.split('.')[0]) >= 1: from obspy.clients.fdsn import Client from obspy import read_events else: from obspy.fdsn import Client from obspy import readEvents as read_events from obspy.core.event import Catalog from obspy import UTCDateTime from eqcorrscan.utils.sfile_util import eventtosfile import os import shutil client = Client('GEONET') # get the events catalog = Catalog() data_stream = client._download('http://quakeml.geonet.org.nz/' + 'quakeml/1.2/2016p008194') data_stream.seek(0, 0) catalog += read_events(data_stream, format="quakeml") data_stream.close() # Select 3 channels to use and download sta_chans = [(pick.waveform_id.station_code, pick.waveform_id.channel_code) for pick in catalog[0].picks[0:3]] t1 = UTCDateTime(catalog[0].origins[0].time.date) t2 = t1 + 86400 bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2) for sta_chan in sta_chans] continuous_st = client.get_waveforms_bulk(bulk) continuous_st.merge(fill_value=0) # Test multi_template_gen templates = multi_template_gen(catalog, continuous_st, length=3) self.assertEqual(len(templates), 1) # Test without an event templates = multi_template_gen(Catalog(), continuous_st, length=3) self.assertEqual(len(templates), 0) # Test from contbase method sfile = eventtosfile(catalog[0], 'TEST', 'L', '.', 'None', overwrite=True) os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y')) os.makedirs(catalog[0].origins[0].time.date. strftime('Y%Y' + os.sep + 'R%j.01')) for tr in continuous_st: tr.write(catalog[0].origins[0].time.date. strftime('Y%Y' + os.sep + 'R%j.01') + os.sep + tr.stats.station + '.' + tr.stats.network + '.' + tr.stats.location + '.' + tr.stats.channel + tr.stats.starttime.strftime('%Y.%j'), format='MSEED') template = from_contbase(sfile, contbase_list=[('.', 'Yyyyy/Rjjj.01', 'NZ')], lowcut=1.0, highcut=5.0, samp_rate=20, filt_order=4, length=3, prepick=0.5, swin='all') shutil.rmtree(continuous_st[0].stats.starttime.strftime('Y%Y'))
def test_query_data(self): # query using ObsPy t1 = UTCDateTime("2005-10-06T07:21:59.850000") t2 = UTCDateTime("2005-10-06T07:24:59.845000") client = FDSNClient(self.live_server_url) got = client.get_waveforms("", "RJOB", "", "Z", t1, t2)[0] expected = read(FILES[0])[0] np.testing.assert_equal(got.data, expected.data) self.assertEqual(got, expected)
def getCatData(date, opt): """ Download data from IRIS or Earthworm waveserver with padding and filter it. This is a specialized version getData() for catalog events, pulling a smaller amount of time around a known event. date: UTCDateTime of known catalog event opt: Options object describing station/run parameters Returns ObsPy stream objects, one for cutting and the other for triggering """ nets = opt.network.split(',') stas = opt.station.split(',') locs = opt.location.split(',') chas = opt.channel.split(',') if opt.server == "IRIS": client = Client("IRIS") else: client = EWClient(opt.server, opt.port) st = Stream() for n in range(len(stas)): try: stmp = client.get_waveforms(nets[n], stas[n], locs[n], chas[n], date - opt.atrig, date + 3*opt.atrig) stmp = stmp.filter("bandpass", freqmin=opt.fmin, freqmax=opt.fmax, corners=2, zerophase=True) stmp = stmp.merge(method=1, fill_value='interpolate') except (obspy.fdsn.header.FDSNException): try: # try again stmp = client.get_waveforms(nets[n], stas[n], locs[n], chas[n], date - opt.atrig, date + 3*opt.atrig) stmp = stmp.filter("bandpass", freqmin=opt.fmin, freqmax=opt.fmax, corners=2, zerophase=True) stmp = stmp.merge(method=1, fill_value='interpolate') except (obspy.fdsn.header.FDSNException): print('No data found for {0}.{1}'.format(stas[n],nets[n])) trtmp = Trace() trtmp.stats.sampling_rate = opt.samprate trtmp.stats.station = stas[n] stmp = Stream().extend([trtmp.copy()]) # Resample to ensure all traces are same length if stmp[0].stats.sampling_rate != opt.samprate: stmp = stmp.resample(opt.samprate) st.extend(stmp.copy()) st = st.trim(starttime=date-opt.atrig, endtime=date+3*opt.atrig, pad=True, fill_value=0) stC = st.copy() return st, stC
def _download_bulk(stations, event): click.secho("Downloading: {}".format(event.name)) client = Client("IRIS") # Remove duplicate stations. For some reasons NARS breaks obspy. bulk_req = [(s.net, s.sta, '*', 'BHE,BHN,BHZ') for s in stations] bulk_req = [s + (event.start, event.end) for s in set(bulk_req) if "NARS" not in s] filename = os.path.join("RAW_DATA", "{}.mseed".format(event.name)) client.get_waveforms_bulk(bulk_req, filename=filename)
def get_channel_orientation(t0, net, st0, loc, duration, channel): """ Get the station channel orientation. Returns azimuth and dip angle. """ client = Client('IRIS') st0 = client.get_stations(starttime=t0, endtime=t0+duration*60, network=net, station=st0, channel=channel, level='channel') return st0[0][0].channels[0].azimuth, st0[0][0].channels[0].dip
def get_events(): try: return read_events(evname) except Exception: pass client = Client() events = client.get_events(starttime=t1, endtime=t2, latitude=lat, longitude=lon, minradius=30, maxradius=90, minmagnitude=6., maxmagnitude=6.5) events.write(evname, 'QUAKEML') return events
def test_dist_mat_km(self): """Test spacial clustering.""" from eqcorrscan.utils.clustering import dist_mat_km from obspy.clients.fdsn import Client from obspy import UTCDateTime client = Client("IRIS") starttime = UTCDateTime("2002-01-01") endtime = UTCDateTime("2002-01-02") cat = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=6, catalog="ISC") dist_mat = dist_mat_km(cat) self.assertEqual(len(dist_mat), len(cat))
def find_event(st, timebefore=5, timeafter=5, service="IRIS"): ''' Uses the selected webservice to search for an event matching the stream's starttime plus/minus the specified time window. If multiple streams match, lists them. Parameters ---------- st : ObsPy Stream object Stream of SAC format seismograms for the event in question timebefore : float Time in seconds before stream start time from which to search catalog for events timeafter : float Time insseconds after stream start time up to which to search catalog for events service : String Web service to use to search for events. Same options as for obspy.fdsn.Client. Default is IRIS. Returns ------- event : ObsPy Event object Downloaded information for the event, if found. ''' webservice = Client(service) try: cat = webservice.get_events(starttime=st[0].stats.starttime - timebefore, endtime=st[0].stats.starttime + timeafter, minmagnitude=st[0].stats.sac.mag - 1.0, maxmagnitude=st[0].stats.sac.mag + 1.0) except FDSNException: print "No event found for stream startttime. Try adjusting time window." return except AttributeError: print "No stats.sac dictionary, attempting search based on time window alone..." try: cat = webservice.get_events(starttime=st[0].stats.starttime - timebefore, endtime=st[0].stats.starttime + timeafter) except FDSNException: print "No event found for stream startttime. Try adjusting time window." return if len(cat) > 1: print "Multiple events found for stream starttime. Try adjusting time window." print cat return event = cat[0] print event return event
def get_inventory(): try: return read_inventory(invname) except Exception: pass client = Client('GFZ') net, sta, loc, cha = seedid.split('.') inv = client.get_stations(starttime=t1, endtime=t2, network=net, station=sta, location=loc, channel=cha, level='channel') # latitude=lat, longitude=lon, maxradius=10) inv.write(invname, 'STATIONXML') return inv
def test_query_mapping(self): t1 = UTCDateTime(2010, 3, 25, 0, 0) t2 = t1 + 30 client = FDSNClient(self.live_server_url) # 1 - direct query fails self.assertRaises(FDSNException, client.get_waveforms, "TA", "*", "*", "BHE", t1, t2) # 2 - query use mapping works st = client.get_waveforms("XX", "YY", "00", "ZZZ", t1, t2) self.assertEqual(len(st), 1) # 3 - TA.A25A..BHZ and TA.A25A..BHN shouldn't be affected at all st = client.get_waveforms("TA", "A25A", "", "BH?", t1, t2) self.assertEqual(len(st), 2)
def test_space_time_cluster(self): """Test clustering in space and time.""" from eqcorrscan.utils.clustering import space_time_cluster from obspy.clients.fdsn import Client from obspy import UTCDateTime client = Client("IRIS") starttime = UTCDateTime("2002-01-01") endtime = UTCDateTime("2002-01-02") cat = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=6, catalog="ISC") groups = space_time_cluster(catalog=cat, t_thresh=86400, d_thresh=1000) self.assertEqual(len([ev for group in groups for ev in group]), len(cat))
def get_seismometer_data(t0, net, st0, loc, ch, duration): """ Download data from the IRIS datacenter and output with the instrument response removed and calibrated. Return a station object. """ client = Client("IRIS") st = client.get_waveforms(net, st0, loc, ch, t0, t0+timedelta(minutes=duration), attach_response=True) st.detrend(type='linear') st.detrend(type='constant') st.taper(max_percentage=0.01) st.remove_response(output='DISP') return st
def get_station_location(t0, net, st0, loc): """ Get the station latitude, longitude, and elevation. Given a time, duration, loc code, and station network/name, get station information from IRIS. Return a list containing the lat, lon, and elevation. """ client = Client('IRIS') st0 = client.get_stations(starttime=t0, endtime=t0+timedelta(seconds=60), network=net, station=st0, level='station') slat = st0[0][0].latitude slon = st0[0][0].longitude selev = st0[0][0].elevation return [slat, slon, selev]
def test_sim_WA(self): """Test feeding both PAZ and seedresp.""" from eqcorrscan.utils.mag_calc import _sim_WA from obspy.core.util import NamedTemporaryFile from obspy import UTCDateTime from obspy.clients.fdsn import Client from obspy.clients.iris import Client as OldIris_Client t1 = UTCDateTime("2010-09-3T16:30:00.000") t2 = UTCDateTime("2010-09-3T17:00:00.000") fdsn_client = Client('IRIS') st = fdsn_client.get_waveforms(network='NZ', station='BFZ', location='10', channel='HHZ', starttime=t1, endtime=t2, attach_response=True) tr = st[0] PAZ = {'poles': [-4.440 + 4.440j, -4.440 - 4.440j, -1.083 + 0.0j], 'zeros': [0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0], 'sensitivity': 0.4, 'gain': 60077000.0} tr_safe = tr.copy() # Test with PAZ _sim_WA(trace=tr, PAZ=PAZ, seedresp=None, water_level=10) tr = tr_safe.copy() # Test without PAZ or seedresp _sim_WA(trace=tr, PAZ=None, seedresp=None, water_level=10) tr = tr_safe.copy() with NamedTemporaryFile() as tf: respf = tf.name old_iris_client = OldIris_Client() # fetch RESP information from "old" IRIS web service, see obspy.fdsn # for accessing the new IRIS FDSN web services old_iris_client.resp('NZ', 'BFZ', '10', 'HHZ', t1, t2, filename=respf) date = t1 seedresp = {'filename': respf, # RESP filename 'date': date, 'network': tr.stats.network, 'station': tr.stats.station, 'channel': tr.stats.channel, 'location': tr.stats.location, # Units to return response in ('DIS', 'VEL' or ACC) 'units': 'DIS' } _sim_WA(trace=tr, PAZ=None, seedresp=seedresp, water_level=10)
def download_waveform(stations, starttime, endtime, outputdir=None, client=None): """ download wavefrom data from IRIS data center :param stations: list of stations, should be list of station ids, for example, "II.AAK.00.BHZ". Parts could be replaced by "*", for example, "II.AAK.*.BH*" """ if client is None: client = Client("IRIS") if starttime > endtime: raise ValueError("Starttime(%s) is larger than endtime(%s)" % (starttime, endtime)) if not os.path.exists(outputdir): raise ValueError("Outputdir not exists: %s" % outputdir) _status = {} for station_id in stations: error_code = "None" network, station, location, channel = _parse_station_id(station_id) if outputdir is not None: filename = os.path.join(outputdir, "%s.mseed" % station_id) if os.path.exists(filename): os.remove(filename) else: filename = None try: st = client.get_waveforms( network=network, station=station, location=location, channel=channel, starttime=starttime, endtime=endtime) if len(st) == 0: error_code = "stream empty" if filename is not None and len(st) > 0: st.write(filename, format="MSEED") except Exception as e: error_code = "Failed to download waveform '%s' due to: %s" \ % (station_id, str(e)) print(error_code) _status[station_id] = error_code return {"stream": st, "status": _status}
def get_data_from_iris(t0, net, st0, loc, ch, duration): """ Download data for a station from IRIS. Download data from the IRIS datacenter and output with the instrument response removed and calibrated. A filter is also placed. Return a station object. """ client = Client('IRIS') st = client.get_waveforms(net, st0, loc, ch, t0, t0+duration*60, attach_response=True) st.detrend(type='demean') st.detrend(type='linear') st.taper(max_percentage=0.05) st.remove_response(output='DISP') st.filter('highpass', freq=0.01, corners=4, zerophase=True) return st
def test_download_write(self): """ Function to download quakeML files from a range of datacenters and \ attempt to write miniseed files """ import os from eqcorrscan.utils import sfile_util import obspy if int(obspy.__version__.split('.')[0]) >= 1: from obspy.clients.fdsn import Client from obspy import read_events from obspy.clients.fdsn.header import FDSNException else: from obspy.fdsn import Client from obspy import readEvents as read_events from obspy.fdsn.header import FDSNException import warnings event_list = [('GEONET', '2016p008122'), ('NCEDC', '72572665'), ('USGS', 'nc72597260')] for event_info in event_list: client = Client(event_info[0]) if event_info[0] == 'GEONET': try: data_stream = client.\ _download('http://quakeml.geonet.org.nz/' + 'quakeml/1.2/' + event_info[1]) data_stream.seek(0, 0) event = read_events(data_stream, format="quakeml") data_stream.close() except FDSNException: warnings.warn('FDSNException') continue else: try: event = client.get_events(eventid=event_info[1], includearrivals=True) except FDSNException: warnings.warn('FDSNException') continue test_Sfile_name = sfile_util.eventtosfile(event, 'test', 'L', '.', 'null', overwrite=True) os.remove(test_Sfile_name) return True
def _download(stations, event): click.secho("Downloading: {}".format(event.name)) stream = obspy.Stream() client = Client("IRIS") for s in stations: req = (s.net, s.sta, '*', 'BH*', event.start, event.end) # Try and download, don't worry if no data is available. try: stream += client.get_waveforms(*req) print "Retrieved {}.{}".format(s.net, s.sta) except FDSNException as e: print "Could not retrieve {}.{}".format(s.net, s.sta) pass fname = os.path.join("RAW_DATA", "{}.mseed".format(event.name)) stream.write(fname, format='mseed')
def main(): # 2. Get your events in an obspy Catalog object. Be sure to include the # arrivals, so that hypoDD has something to work on, as waveform # cross-correlation has not been implemented yet. client = Client("http://rdsa.knmi.nl") mycat = client.get_events( minmagnitude=0.0, minlatitude=52.6, minlongitude=6.0, maxlatitude=53.8, maxlongitude=7.5, starttime=UTCDateTime("2015-01-01T00:00:00"), includearrivals=True) # 3. Initialize a hypoDD object. The working directory should contain the # binaries for ph2dt and hypoDD. You need the client argument to download # station metadata and waveforms* (*not implemented yet) myhypoDD=HypoDDObject(mycat,client,"./work") # 4. Set values for ph2dt and hypoDD parameters (see manual for details), if # you don't want to use the default hypoDDutil values (you probably don't) myhypoDD.ph2dt_control.maxsep = 7.5 myhypoDD.hypoDD_control.dist = 300 # and so on. You can give values for all parameters, or for none. # 5. Prepare the control files and input files myhypoDD.prepare_all() # 6. Run ph2dt with the current configuration myhypoDD.run_ph2dt() # 7. Run hypoDD with the current configuration myhypoDD.run_hypoDD() # 8. Get the output in the form of a list of clusters (in the hypoDD sense) # a cluster is a catalog with some metadata, like whether hypoDD succeeded # with these events or how well connected* the cluster is (*not implemented # yet) clusters=myhypoDD.get_results() for cluster in clusters: print "hypoDD cluster ID: {}".format(cluster.hypoDD_id) print "cluster was relocated successfully: {}".format( cluster.successful_relocation ) print cluster.catalog print
def download_stationxml(stations, starttime, endtime, outputdir=None, client=None, level="response"): if client is None: client = Client("IRIS") if starttime > endtime: raise ValueError("Starttime(%s) is larger than endtime(%s)" % (starttime, endtime)) if not os.path.exists(outputdir): raise ValueError("Outputdir not exists: %s" % outputdir) _status = {} for station_id in stations: error_code = "None" network, station, location, channel = _parse_station_id(station_id) if outputdir is not None: filename = os.path.join(outputdir, "%s.xml" % station_id) if os.path.exists(filename): os.remove(filename) else: filename = None try: inv = client.get_stations( network=network, station=station, location=location, channel=channel, starttime=starttime, endtime=endtime, level=level) if len(inv) == 0: error_code = "Inventory Empty" if filename is not None and len(inv) > 0: inv.write(filename, format="STATIONXML") except Exception as e: error_code = "Failed to download StationXML '%s' due to: %s" \ % (station_id, str(e)) print(error_code) _status[station_id] = error_code return {"inventory": inv, "status": _status}
def set_event_data_center(self, data_center): """ Set the data center used for events """ if data_center != self.event_data_center or not self.event_client: # Use the station client if they're the same, otherwise create a client if data_center == self.station_data_center and self.station_client: client = self.station_client else: LOGGER.info("Creating ObsPy client for %s", data_center) client = Client(data_center) # Verify that this client supports events if 'event' not in client.services: LOGGER.error("The %s data center does not provide an event service" % data_center) return # Update settings self.event_data_center = data_center self.event_client = client
def setUpClass(cls) -> None: cls.testing_path = os.path.abspath( os.path.dirname(__file__)) + os.path.sep + "db" if not os.path.isdir(cls.testing_path): os.makedirs(cls.testing_path) cls.template_bank = TemplateBank(cls.testing_path) cls.listener = CatalogListener(client=Client("GEONET"), catalog=Catalog(), catalog_lookup_kwargs=dict( latitude=-45., longitude=178., maxradius=3.0), template_bank=cls.template_bank, interval=5) cls.trigger_func = partial(magnitude_rate_trigger_func, magnitude_threshold=4, rate_threshold=20, rate_bin=0.5)
def GeoNetFDSNrequest(date1, date2, net, sta, loc, cmp): """ Request waveform and meta data from GeoNet's FDSN webservices. """ #GeoNet's FDSN web servers arc_client = Client('http://service.geonet.org.nz') nrt_client = Client('http://beta-service-nrt.geonet.org.nz') time1 = UTCDateTime(date1) time2 = UTCDateTime(date2) try: st = nrt_client.get_waveforms(net, sta, loc, cmp, time1, time2, attach_response=True) inv = nrt_client.get_stations(network=net, station=sta, starttime=time1, endtime=time2) except FDSNNoDataException: st = arc_client.get_waveforms(net, sta, loc, cmp, time1, time2, attach_response=True) inv = arc_client.get_stations(network=net, station=sta, starttime=time1, endtime=time2) return (st, inv)
def set_station_data_center(self, data_center): """ Set the data center used for stations """ if data_center != self.station_data_center or not self.station_client: # Use the event client if they're the same, otherwise create a client if data_center == self.event_data_center and self.event_client: client = self.event_client else: LOGGER.info("Creating ObsPy client for %s", data_center) client = Client(data_center) # Verify that this client supports station and dataselect for service in ('station', 'dataselect',): if service not in client.services: LOGGER.error("The %s data center does not provide a %s service" % (data_center, service)) return # Update settings self.station_data_center = data_center self.station_client = client
def obspy_download_parallel(data_center, startday, endday, sta_file, out_path, cores=1): set_folders(out_path, startday, endday) sta_list = load_stations(sta_file) with open('download.log', 'a') as f: f.write('>>> ' + str(time.localtime(time.time())) + '\n') f.write('The number of stations is: ' + str(len(sta_list)) + '\n') day = startday while day <= endday: t_b = time.time() with open('download.log', 'a') as f: f.write('Day: ' + str(day) + '\n') print(day) starttime = day endtime = day + 86400 client = Client(data_center) if cores == 1: for i in range(len(sta_list)): sta = sta_list[i] print(sta) net_name = sta[0] sta_name = sta[1] chan_name = sta[2] obspy_download(client, net_name, sta_name, chan_name, starttime, endtime, out_path) else: pass t_e = time.time() with open('download.log', 'a') as f: f.write('Using time: ' + str(t_e - t_b) + '\n') day = day + 86400 return None
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 get_test_data(): """ Generate a set of waveforms from GeoNet for use in subspace testing :return: List of cut templates with no filters applied :rtype: list """ from obspy import UTCDateTime from eqcorrscan.utils.catalog_utils import filter_picks from eqcorrscan.utils.clustering import space_cluster from obspy.clients.fdsn import Client client = Client("GEONET") cat = client.get_events(minlatitude=-40.98, maxlatitude=-40.85, minlongitude=175.4, maxlongitude=175.5, starttime=UTCDateTime(2016, 5, 11), endtime=UTCDateTime(2016, 5, 13)) cat = filter_picks(catalog=cat, top_n_picks=5) stachans = list( set([(pick.waveform_id.station_code, pick.waveform_id.channel_code) for event in cat for pick in event.picks])) clusters = space_cluster(catalog=cat, d_thresh=2, show=False) cluster = sorted(clusters, key=lambda c: len(c))[-1] client = Client('GEONET') design_set = [] bulk_info = [] for event in cluster: t1 = event.origins[0].time + 5 t2 = t1 + 15.1 for station, channel in stachans: bulk_info.append(('NZ', station, '*', channel[0:2] + '?', t1, t2)) st = client.get_waveforms_bulk(bulk=bulk_info) for event in cluster: t1 = event.origins[0].time + 5 t2 = t1 + 15 design_set.append(st.copy().trim(t1, t2)) t1 = UTCDateTime(2016, 5, 11, 19) t2 = UTCDateTime(2016, 5, 11, 20) bulk_info = [('NZ', stachan[0], '*', stachan[1][0:2] + '?', t1, t2) for stachan in stachans] st = client.get_waveforms_bulk(bulk_info) st.merge().detrend('simple').trim(starttime=t1, endtime=t2) return design_set, st
class IRISWrapper(AnxcorDatabase): def __init__(self): super().__init__() self.client = Client("IRIS") self.station_list = ['S01', 'S02'] #,'S03','S04','S05'] self.pre_filter = (0.003, 0.005, 40.0, 45.0) def get_waveforms(self, starttime=0, endtime=0, station=0, network=0, **kwargs): traces = [] stream = self.client.get_waveforms(network, station, "*", "H*", starttime, endtime, attach_response=True) stream = anxcor_utils.remove_response(stream, output='DISP', pre_filt=self.pre_filter) for trace in stream: data = trace.data[:-1] header = { 'delta': trace.stats.delta, 'station': trace.stats.station, 'starttime': trace.stats.starttime, 'channel': trace.stats.channel, 'network': trace.stats.network } traces.append(Trace(data, header=header)) return Stream(traces=traces) def get_stations(self): station_list = [] for station in self.station_list: station_list.append('YB.{}'.format(station)) return station_list
def test_no_wildcards(self): t1 = UTCDateTime(2010, 3, 25, 0, 0) t2 = t1 + 30 client = FDSNClient(self.live_server_url) # network st = client.get_waveforms("TA", "*", "*", "*", t1, t2) self.assertEqual(len(st), 19) for id_ in ["T", "A", "X"]: self.assertRaises(FDSNException, client.get_waveforms, id_, "*", "*", "*", t1, t2) # station st = client.get_waveforms("*", "A25A", "*", "*", t1, t2) self.assertEqual(len(st), 19) for id_ in ["A2", "25", "5A"]: self.assertRaises(FDSNException, client.get_waveforms, "*", id_, "*", "*", t1, t2) # location st = client.get_waveforms("*", "*", "", "*", t1, t2) self.assertEqual(len(st), 19) # Jane does not distinguish between location ids with an empty # string or one or more spaces. # This is according to # http://www.fdsn.org/message-center/thread/108/ st = client.get_waveforms("*", "*", " ", "*", t1, t2) self.assertEqual(len(st), 19) st = client.get_waveforms("*", "*", " ", "*", t1, t2) self.assertEqual(len(st), 19) st = client.get_waveforms("*", "*", "--", "*", t1, t2) self.assertEqual(len(st), 19) for id_ in ["00", "XX", "X"]: self.assertRaises(FDSNException, client.get_waveforms, "*", "*", id_, "*", t1, t2) # channel st = client.get_waveforms("*", "*", "*", "BHZ", t1, t2) self.assertEqual(len(st), 1) for id_ in ["B", "Z", "H"]: self.assertRaises(FDSNException, client.get_waveforms, "*", "*", "*", id_, t1, t2)
def setUpClass(cls) -> None: cls.test_path = (os.path.abspath(os.path.dirname(__file__)) + os.path.sep + "db") if os.path.isdir(cls.test_path): shutil.rmtree(cls.test_path) os.makedirs(cls.test_path) logging.debug("Making the bank") cls.bank = TemplateBank(base_path=cls.test_path, event_name_structure="{event_id_short}", template_name_structure="{event_id_short}") cls.client = Client("GEONET") logging.debug("Downloading the catalog") catalog = cls.client.get_events(starttime=UTCDateTime(2019, 6, 21), endtime=UTCDateTime(2019, 6, 23), latitude=-38.8, longitude=175.8, maxradius=0.2) cls.catalog = remove_unreferenced( filter_picks(catalog=catalog, top_n_picks=5)) cls.bank.put_events(cls.catalog)
def _process(self, filename): #self.log('reading inputs from %s' % filename) client = Client() stations_list = [] stations_names = set() with open(filename, 'r') as f: i = 1 for station in f.readlines(): if i % self.bulksize != 0: network, station_name = station.split() stations_names.add((network, station_name)) # station_name = station.strip() stations_list.append((network, station_name, "", self.channel, self.t_start, self.t_finish)) i += 1 else: self._get_waveforms(client, stations_list, stations_names) stations_list = [] stations_names = set() i = 1 if stations_list: self._get_waveforms(client, stations_list, stations_names)
def askIRIS(datadir, client, stas, comps, locs, starttime, endtime, ncpu): if not isinstance(comps, list): comps = [comps] if not isinstance(locs, list): locs = [locs] # --- initate client and request fdsn_client = Client(client) Nday = endtime.toordinal() - starttime.toordinal() if Nday == 1: starttimes = [starttime] endtimes = [endtime] elif Nday > 1: starttimes = [starttime + t for t in np.arange(Nday + 1) * 24 * 3600] endtimes = [starttime + t for t in np.arange(1, Nday + 2) * 24 * 3600] elif Nday <= 0: print("bad time period...") exit() # --- flattening of request to pool distribution times = list(zip(starttimes, endtimes)) requests = [(fdsn_client, datadir, k, sta, comp, loc, time) for k in stas.keys() \ for sta in stas[k] for comp in comps for loc in locs for time in times] print('find {} requests..'.format(len(requests))) # --- loop pool = Pool(ncpu) logs = pool.starmap(request2IRIS, requests) pool.close() pool.join() print('request terminated') # TODO: write a better way to pass logs try: summary = '\n'.join(logs) return summary except: return 'ok'
def test_reactor_spin_up(self): rt_client = RealTimeClient(server_url="link.geonet.org.nz") reactor = Reactor(client=Client("GEONET"), rt_client=rt_client, listener=self.listener, trigger_func=self.trigger_func, template_database=self.template_bank, template_lookup_kwargs=dict(), real_time_tribe_kwargs=dict(threshold=8, threshold_type="MAD", trig_int=2), plot_kwargs=dict(), listener_kwargs=dict(make_templates=False)) trigger_event = Event(origins=[ Origin(time=UTCDateTime(2019, 1, 1), latitude=-45., longitude=178.0, depth=10000.) ], magnitudes=[Magnitude(mag=7.4)]) reactor.background_spin_up(triggering_event=trigger_event) time.sleep(10) reactor.stop()
async def save_day_plot(self, stream): starttime = stream[0].stats.starttime endtime = stream[0].stats.endtime print("Plotting day plot for stream with starttime:", starttime) image_file_name = 'day_' + str(starttime.datetime.day) + IMAGE_FILE_FORMAT image_file_path = self.directory / image_file_name try: client = Client("IRIS") cat = StreamPlotter.get_japan_earthquakes(client, starttime, endtime) cat += StreamPlotter.get_global_earthquakes(client, starttime, endtime) stream.plot( size=IMAGE_SIZE_DAY_PLOT, dpi=OUTFILE_DPI, type="dayplot", outfile=image_file_path, events=cat, vertical_scaling_range=500, ) except Exception as e: print("Failed to plot day plot.", e)
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)
def setUp(self) -> None: if not os.path.isdir(self.testing_path): os.makedirs(self.testing_path) self.template_bank = TemplateBank(self.testing_path) self.listener = CatalogListener(client=Client("GEONET"), catalog=Catalog(), catalog_lookup_kwargs=dict( latitude=-45., longitude=178., maxradius=3.0), template_bank=self.template_bank, interval=5) self.trigger_func = partial(magnitude_rate_trigger_func, magnitude_threshold=4, rate_threshold=20, rate_bin=0.5) config = Config() config.rt_match_filter.rt_client_url = "link.geonet.org.nz" config.rt_match_filter.rt_client_type = "seedlink" config.rt_match_filter.threshold = 8 config.rt_match_filter.threshold_type = "MAD" config.rt_match_filter.trig_int = 2 config.rt_match_filter.plot = False self.config = config
def _get_geonet_pubids(publicids, parallel=True): """ Get GeoNet events while they haven't included get_events in fdsn. :type publicids: list :param publicids: List of public id numbers for events wanted. :returns: Catalog of events :rtype: obspy.core.event.Catalog """ import obspy if int(obspy.__version__.split('.')[0]) > 0: from obspy.clients.fdsn import Client else: from obspy.fdsn import Client from obspy.core.event import Catalog from multiprocessing import Pool, cpu_count client = Client('GEONET') catalog = Catalog() # Multi-process this bad-boy if not parallel: for publicid in publicids: catalog += _inner_get_event(publicid=publicid, client=client) else: pool = Pool(processes=cpu_count()) results = [ pool.apply_async(_inner_get_event, args=(publicid, client)) for publicid in publicids ] pool.close() cat_list = [p.get() for p in results] pool.join() for ev in cat_list: catalog += ev return catalog
def setUpClass(cls): client = Client("GEONET") event1 = client.get_events(eventid="2016p912302")[0] event2 = client.get_events(eventid="3470170")[0] shared_chans = {p1.waveform_id.get_seed_string() for p1 in event1.picks}.intersection( {p2.waveform_id.get_seed_string() for p2 in event2.picks}) bulk = [(p.waveform_id.network_code, p.waveform_id.station_code, p.waveform_id.location_code, p.waveform_id.channel_code, p.time - 20, p.time + 60) for p in event1.picks if p.waveform_id.get_seed_string() in shared_chans] st1 = client.get_waveforms_bulk(bulk) st1 = st1.detrend().filter("bandpass", freqmin=2, freqmax=20) bulk = [(p.waveform_id.network_code, p.waveform_id.station_code, p.waveform_id.location_code, p.waveform_id.channel_code, p.time - 20, p.time + 60) for p in event2.picks if p.waveform_id.get_seed_string() in shared_chans] st2 = client.get_waveforms_bulk(bulk) st2 = st2.detrend().filter("bandpass", freqmin=2, freqmax=20) cls.event1 = event1 cls.event2 = event2 cls.st1 = st1 cls.st2 = st2
# - ArcLink (EIDA, ...) # - Earthworm # - SeedLink (near-realtime servers) # - NERIES/NERA/seismicportal.eu # - NEIC # - SeisHub (local seismological database) # # This introduction shows how to use the FDSN webservice client. The FDSN webservice definition is by now the default web service implemented by many data centers world wide. Clients for other protocols work similar to the FDSN client. # # #### Waveform Data # + from obspy import UTCDateTime from obspy.clients.fdsn import Client client = Client("IRIS") t = UTCDateTime("2011-03-11T05:46:23") # Tohoku st = client.get_waveforms("II", "PFO", "*", "LHZ", t + 10 * 60, t + 30 * 60) print(st) st.plot() # - # - again, waveform data is returned as a Stream object # - for all custom processing workflows it does not matter if the data originates from a local file or from a web service # # #### Event Metadata # # The FDSN client can also be used to request event metadata: t = UTCDateTime("2011-03-11T05:46:23") # Tohoku catalog = client.get_events(starttime=t - 100,
#!/bin/env python from obspy.core import trace from obspy import read from obspy.clients.fdsn import Client from obspy import UTCDateTime from obspy.geodetics.base import locations2degrees from obspy.geodetics.base import gps2dist_azimuth from obspy.taup import TauPyModel client = Client("IRIS") # this is a deep earthquake in bolivia t = UTCDateTime("2017-02-21T14:09:04") eventTime = UTCDateTime("2017-02-21T14:09:04") eventLat=-19.281 eventLon=-63.905 eventDepth = 597. inventory = client.get_stations(network="IU", station="*", starttime=t) model = TauPyModel(model="iasp91") # to plot up all the stations... #inventory.plot() # to get the station coordinates station_coordinates = [] for network in inventory: for station in network: station_coordinates.append((network.code, station.code, station.latitude, station.longitude,
import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader import cartopy.feature as cfeature import matplotlib.font_manager import cartopy as cart # Importing and applying font mpl.rc('font', family='serif') mpl.rc('font', serif='Times') mpl.rc('text', usetex=True) mpl.rc('font', size=18) net = 'IU' fig = plt.figure(1, figsize=(14, 12)) stime = UTCDateTime('2019-001T00:00:00') etime = UTCDateTime('2019-010T00:00:00') client = Client('IRIS') for idx2, tidetype in enumerate(['semidiurnal', 'diurnal']): stas = glob.glob(net + '*_' + tidetype) stas = [sta.split('_')[1] for sta in stas] amps_good, amps_goodstd, lens_good = {}, {}, {} for sta in stas: filename = glob.glob(net + '*' + sta + '*' + tidetype)[0] print(filename) results = [] with open(filename) as f: next(f) for line in f: line = line.rstrip() line = line.replace(' ', '')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu May 9 17:13:10 2019 @author: vidale """ from obspy import UTCDateTime from obspy.clients.fdsn import Client import matplotlib.pyplot as plt import os plt.style.use('ggplot') plt.rcParams['figure.figsize'] = 12, 8 client = Client('USGS') # client = Client('SCEDC') os.environ['PATH'] += os.pathsep + '/usr/local/bin' os.chdir('/Users/vidale/Documents/Research/BasinsLA/New_py') min_mag = 3.5 min_lat = 33.75 max_lat = 34.2 min_lon = -118.5 max_lon = -117.75 t1 = UTCDateTime("1996-01-01T00:00:00") t2 = UTCDateTime("2022-01-01T00:00:00") fname_cat = 'LAB.quakeml2' cat = client.get_events(starttime=t1, endtime=t2,
def getData(tstart, tend, opt): """ Download data from files in a folder, from IRIS, or a Earthworm waveserver A note on SAC/miniSEED files: as this makes no assumptions about the naming scheme of your data files, please ensure that your headers contain the correct SCNL information! tstart: UTCDateTime of beginning of period of interest tend: UTCDateTime of end of period of interest opt: Options object describing station/run parameters Returns ObsPy stream objects, one for cutting and the other for triggering """ nets = opt.network.split(',') stas = opt.station.split(',') locs = opt.location.split(',') chas = opt.channel.split(',') st = Stream() if opt.server == 'file': # Generate list of files if opt.server == 'file': flist = list(itertools.chain.from_iterable(glob.iglob(os.path.join( root,opt.filepattern)) for root, dirs, files in os.walk(opt.searchdir))) # Determine which subset of files to load based on start and end times and # station name; we'll fully deal with stations below flist_sub = [] for f in flist: # Load header only stmp = obspy.read(f, headonly=True) # Check if station is contained in the stas list if stmp[0].stats.station in stas: # Check if contains either start or end time ststart = stmp[0].stats.starttime stend = stmp[-1].stats.endtime if (ststart<=tstart and tstart<=stend) or (ststart<=tend and tend<=stend) or (tstart<=stend and ststart<=tend): flist_sub.append(f) # Fully load data from file stmp = Stream() for f in flist_sub: tmp = obspy.read(f, starttime=tstart, endtime=tend+opt.maxdt) if len(tmp) > 0: stmp = stmp.extend(tmp) # Filter and merge stmp = stmp.filter('bandpass', freqmin=opt.fmin, freqmax=opt.fmax, corners=2, zerophase=True) stmp = stmp.taper(0.05,type='hann',max_length=opt.mintrig) for m in range(len(stmp)): if stmp[m].stats.sampling_rate != opt.samprate: stmp[m] = stmp[m].resample(opt.samprate) stmp = stmp.merge(method=1, fill_value=0) # Only grab stations/channels that we want and in order netlist = [] stalist = [] chalist = [] loclist = [] for s in stmp: stalist.append(s.stats.station) chalist.append(s.stats.channel) netlist.append(s.stats.network) loclist.append(s.stats.location) # Find match of SCNL in header or fill empty for n in range(len(stas)): for m in range(len(stalist)): if (stas[n] in stalist[m] and chas[n] in chalist[m] and nets[n] in netlist[m] and locs[n] in loclist[m]): st = st.append(stmp[m]) if len(st) == n: print("Couldn't find "+stas[n]+'.'+chas[n]+'.'+nets[n]+'.'+locs[n]) trtmp = Trace() trtmp.stats.sampling_rate = opt.samprate trtmp.stats.station = stas[n] st = st.append(trtmp.copy()) else: if '.' not in opt.server: client = Client(opt.server) else: client = EWClient(opt.server, opt.port) for n in range(len(stas)): try: stmp = client.get_waveforms(nets[n], stas[n], locs[n], chas[n], tstart, tend+opt.maxdt) for m in range(len(stmp)): stmp[m].data = np.where(stmp[m].data == -2**31, 0, stmp[m].data) # replace -2**31 (Winston NaN token) w 0 stmp = stmp.filter('bandpass', freqmin=opt.fmin, freqmax=opt.fmax, corners=2, zerophase=True) stmp = stmp.taper(0.05,type='hann',max_length=opt.mintrig) for m in range(len(stmp)): if stmp[m].stats.sampling_rate != opt.samprate: stmp[m] = stmp[m].resample(opt.samprate) stmp = stmp.merge(method=1, fill_value=0) except (obspy.clients.fdsn.header.FDSNException): try: # try again stmp = client.get_waveforms(nets[n], stas[n], locs[n], chas[n], tstart, tend+opt.maxdt) for m in range(len(stmp)): stmp[m].data = np.where(stmp[m].data == -2**31, 0, stmp[m].data) # replace -2**31 (Winston NaN token) w 0 stmp = stmp.filter('bandpass', freqmin=opt.fmin, freqmax=opt.fmax, corners=2, zerophase=True) stmp = stmp.taper(0.05,type='hann',max_length=opt.mintrig) for m in range(len(stmp)): if stmp[m].stats.sampling_rate != opt.samprate: stmp[m] = stmp[m].resample(opt.samprate) stmp = stmp.merge(method=1, fill_value=0) except (obspy.clients.fdsn.header.FDSNException): print('No data found for {0}.{1}'.format(stas[n],nets[n])) trtmp = Trace() trtmp.stats.sampling_rate = opt.samprate trtmp.stats.station = stas[n] stmp = Stream().extend([trtmp.copy()]) # Last check for length; catches problem with empty waveserver if len(stmp) != 1: print('No data found for {0}.{1}'.format(stas[n],nets[n])) trtmp = Trace() trtmp.stats.sampling_rate = opt.samprate trtmp.stats.station = stas[n] stmp = Stream().extend([trtmp.copy()]) st.extend(stmp.copy()) # Edit 'start' time if using offset option if opt.maxdt: dts = np.fromstring(opt.offset, sep=',') for n, tr in enumerate(st): tr.stats.starttime = tr.stats.starttime-dts[n] st = st.trim(starttime=tstart, endtime=tend, pad=True, fill_value=0) stC = st.copy() return st, stC