本文整理汇总了Python中obspy.clients.fdsn.Client.get_waveforms方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_waveforms方法的具体用法?Python Client.get_waveforms怎么用?Python Client.get_waveforms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.clients.fdsn.Client
的用法示例。
在下文中一共展示了Client.get_waveforms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCatData
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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
示例2: test_query_mapping
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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)
示例3: get_waveforms
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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')
示例4: test_redirection
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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)))
示例5: test_query_data
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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)
示例6: get_seismometer_data
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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
示例7: download_waveform
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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}
示例8: test_sim_WA
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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)
示例9: get_data_from_iris
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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
示例10: _download
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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')
示例11: test_no_wildcards
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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)
示例12: data_request
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
#.........这里部分代码省略.........
clat = center['latitude']
clon = center['longitude']
if azimuth:
print("Looking for events in the azimuth range of %f to %f" % (azimuth[0], azimuth[1]) )
center_az = gps2dist_azimuth(clat, clon, elat, elon)[1]
if center_az > azimuth[1] and center_az < azimuth[0]:
print("Geometrical center of Array out of azimuth bounds, \ncheking if single stations fit")
array_fits = False
elif baz:
print("Looking for events in the back azimuth range of %f to %f" %(baz[0], baz[1]))
center_baz = gps2dist_azimuth(clat, clon, elat, elon)[2]
if center_baz > baz[1] and center_baz < baz[0]:
print("Geometrical center of Array out of back azimuth bounds, \ncheking if single stations fit")
array_fits = False
# If array fits to azimuth/back azimuth or no azimuth/back azimuth is given
no_of_stations = 0
if array_fits:
for station in network:
epidist = locations2degrees(station.latitude,station.longitude,elat,elon)
arrivaltime = m.get_travel_times(source_depth_in_km=depth, distance_in_degree=epidist,
phase_list=Plist)
P_arrival_time = arrivaltime[0]
Ptime = P_arrival_time.time
tstart = UTCDateTime(event.origins[0].time + Ptime - t_before_first_arrival * 60)
tend = UTCDateTime(event.origins[0].time + Ptime + t_after_first_arrival * 60)
try:
streamreq = client.get_waveforms(network=network.code, station=station.code, location='*', channel=channels, starttime=tstart, endtime=tend, attach_response=True)
no_of_stations += 1
print("Downloaded data for %i of %i available stations!" % (no_of_stations, network.selected_number_of_stations), end='\r' )
sys.stdout.flush()
stream += streamreq
try:
if inventory_used:
inventory_used += client.get_stations(network=net, station=scode, level="station", starttime=station_stime, endtime=station_etime,
minlatitude=station_minlat, maxlatitude=station_maxlat, minlongitude=station_minlon, maxlongitude=station_maxlon,
latitude=station_radialcenterlat, longitude=station_radialcenterlon, minradius=station_minrad, maxradius=station_maxrad)
except:
inventory_used = client.get_stations(network=net, station=scode, level="station", starttime=station_stime, endtime=station_etime,
minlatitude=station_minlat, maxlatitude=station_maxlat, minlongitude=station_minlon, maxlongitude=station_maxlon,
latitude=station_radialcenterlat, longitude=station_radialcenterlon, minradius=station_minrad, maxradius=station_maxrad)
except:
continue
# If not checking each station individually.
else:
for station in network:
epidist = locations2degrees(station.latitude,station.longitude,elat,elon)
arrivaltime = m.get_travel_times(source_depth_in_km=depth, distance_in_degree=epidist,
phase_list=Plist)
P_arrival_time = arrivaltime[0]
Ptime = P_arrival_time.time
tstart = UTCDateTime(event.origins[0].time + Ptime - t_before_first_arrival * 60)
tend = UTCDateTime(event.origins[0].time + Ptime + t_after_first_arrival * 60)
示例13: FDSN_Client
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
import matplotlib.pyplot as plt
import obspy
from obspy.core.util import NamedTemporaryFile
from obspy.clients.fdsn import Client as FDSN_Client
from obspy.clients.iris import Client as OldIris_Client
# MW 7.1 Darfield earthquake, New Zealand
t1 = obspy.UTCDateTime("2010-09-3T16:30:00.000")
t2 = obspy.UTCDateTime("2010-09-3T17:00:00.000")
# Fetch waveform from IRIS FDSN web service into a ObsPy stream object
fdsn_client = FDSN_Client("IRIS")
st = fdsn_client.get_waveforms('NZ', 'BFZ', '10', 'HHZ', t1, t2)
# Download and save instrument response file into a temporary file
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)
# make a copy to keep our original data
st_orig = st.copy()
# define a filter band to prevent amplifying noise during the deconvolution
pre_filt = (0.005, 0.006, 30.0, 35.0)
# this can be the date of your raw data or any date for which the
示例14: getData
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
#.........这里部分代码省略.........
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)
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)
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
示例15: test_download_urls_for_custom_mapping
# 需要导入模块: from obspy.clients.fdsn import Client [as 别名]
# 或者: from obspy.clients.fdsn.Client import get_waveforms [as 别名]
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"),
"rb") as fh:
return 200, fh.read()
elif "station" in args[0]:
with open(os.path.join(
self.datapath,
"2014-01-07_iris_station.wadl"), "rb") as fh:
return 200, fh.read()
elif "dataselect" in args[0]:
with open(os.path.join(
self.datapath,
"2014-01-07_iris_dataselect.wadl"), "rb") as fh:
return 200, fh.read()
return 404, None
download_url_mock.side_effect = custom_side_effects
# Some custom urls
base_url_event = "http://example.com/beta/event_service/11"
base_url_station = "http://example.org/beta2/station/7"
base_url_ds = "http://example.edu/beta3/dataselect/8"
# An exception will be raised if not actual WADLs are returned.
# Catch warnings to avoid them being raised for the tests.
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
c = Client(base_url=base_url, service_mappings={
"event": base_url_event,
"station": base_url_station,
"dataselect": base_url_ds,
})
for warning in w:
self.assertTrue("Could not parse" in str(warning) or
"cannot deal with" in str(warning))
# 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])