本文整理汇总了Python中obspy.fdsn.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCatData
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 object
"""
# Choose where data are downloaded automatically via options
# Download data with padding to account for triggering algorithm
# Make overlap symmetric
if opt.server == "IRIS":
client = Client("IRIS")
st = client.get_waveforms(opt.network, opt.station, opt.location, opt.channel,
date - opt.atrig, date + 3*opt.atrig)
else:
client = EWClient(opt.server, opt.port)
st = client.getWaveform(opt.network, opt.station, opt.location, opt.channel,
date - opt.atrig, date + 3*opt.atrig)
st = st.detrend() # can create noise artifacts??
st = st.merge(method=1, fill_value='interpolate')
st = st.filter("highpass", freq=opt.fhigh, corners=2,
zerophase=True)
return st
示例2: getIRIS
def getIRIS(
date, sta, chan, net, loc="--", nsec=86400, ptrig=10.0, atrig=20.0,
fmin=1.0, fmax=10.0):
"""
Download data from IRIS with padding and filter it.
date: UTCDateTime of beginning of period of interest
sta: String of station
chan: String of channel
net: String of network
loc: String of location (default "--")
nsec: Number of seconds to download without padding
(default 86400 s, or 1 day)
ptrig: Length of window to keep prior to trigger (default 10.0 s)
atrig: Length of window to keep after trigger (default 20.0 s)
fmin: Lower bound of bandpass filter (default 1.0 Hz)
fmax: Upper bound of bandpass filter (default 10.0 Hz)
Returns ObsPy stream object
"""
client = Client("IRIS")
# Download data with padding to account for triggering algorithm
st = client.get_waveforms(
net, sta, loc, chan, date - ptrig, date + nsec + atrig)
st = st.detrend()
st = st.merge(method=1, fill_value=0)
st = st.filter("bandpass", freqmin=fmin, freqmax=fmax,
corners=2, zerophase=True)
return st
示例3: getIRIS
def getIRIS(date, opt, nsec=86400):
"""
Download data from IRIS with padding and filter it.
date: UTCDateTime of beginning of period of interest
opt: Options object describing station/run parameters
nsec: Number of seconds to download without padding
(default 86400 s, or 1 day)
Returns ObsPy stream object
"""
client = Client("IRIS")
# Download data with padding to account for triggering algorithm
st = client.get_waveforms(opt.network, opt.station, opt.location, opt.channel,
date - opt.ptrig, date + nsec + opt.atrig)
st = st.detrend() # can create noise artifacts??
st = st.merge(method=1, fill_value='interpolate')
st = st.filter("highpass", freq=opt.fhigh, corners=2,
zerophase=True)
return st
示例4: get_event_info
def get_event_info(starttime, endtime, streams):
events = []
arrivals = {}
try:
client = FDSNClient("NERIES")
events = client.get_events(starttime=starttime - 20 * 60,
endtime=endtime)
for ev in events[::-1]:
has_arrivals = False
origin = ev.origins[0]
origin_time = origin.time
lon1 = origin.longitude
lat1 = origin.latitude
depth = abs(origin.depth / 1e3)
for st in streams:
sta = st[0].stats.station
lon2 = st[0].stats.coordinates['longitude']
lat2 = st[0].stats.coordinates['latitude']
dist = locations2degrees(lat1, lon1, lat2, lon2)
tts = getTravelTimes(dist, depth)
list_ = arrivals.setdefault(sta, [])
for tt in tts:
tt['time'] = origin_time + tt['time']
if starttime < tt['time'] < endtime:
has_arrivals = True
list_.append(tt)
if not has_arrivals:
events[:] = events[:-1]
except Exception as e:
msg = ("Problem while fetching events or determining theoretical "
"phases: %s: %s" % (e.__class__.__name__, str(e)))
return None, None, msg
return events, arrivals, None
示例5: setUp
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="[email protected]", password="anonymous")
示例6: get_events
def get_events():
try:
return readEvents(evname)
except:
pass
client = Client()
events = client.get_events(starttime=t1, endtime=t2, latitude=lat,
longitude=lon, minradius=20, maxradius=100,
minmagnitude=6.)
events.write(evname, 'QUAKEML')
return events
示例7: getepidata
def getepidata(event_lat, event_lon, event_time, tstart=-5., tend=200., minradiuskm=0., maxradiuskm=20., channels='*', location='*', source='IRIS'):
"""
Automatically pull existing data within a certain distance of the epicenter (or any lat/lon coordinates) and attach station coordinates to data
USAGE
st = getepidata(event_lat, event_lon, event_time, tstart=-5., tend=200., minradiuskm=0., maxradiuskm=20., channels='*', location='*', source='IRIS')
INPUTS
event_lat = latitude of event in decimal degrees
event_lon = longitude of event in decimal degrees
event_time = Event time in UTC in any format obspy's UTCDateTime can parse - e.g. '2016-02-05T19:57:26'
tstart = number of seconds to add to event time for start time of data (use negative number to start before event_time)
tend = number of seconds to add to event time for end time of data
radiuskm = radius to search for data
channels = 'strong motion' to get all strong motion channels (excluding low sample rate ones), 'broadband' to get all broadband instruments, 'short period' for all short period channels, otherwise a single line of comma separated channel codes, * wildcards are okay, e.g. channels = '*N*,*L*'
location = comma separated list of location codes allowed, or '*' for all location codes
source = FDSN source, 'IRIS', 'NCEDC', 'GEONET' etc., see list here http://docs.obspy.org/archive/0.10.2/packages/obspy.fdsn.html
OUTPUTS
st = obspy stream containing data from within requested area
"""
event_time = UTCDateTime(event_time)
client = FDSN_Client(source)
if channels.lower() == 'strong motion':
channels = 'EN*,HN*,BN*,EL*,HL*,BL*'
elif channels.lower() == 'broadband':
channels = 'BH*,HH*'
elif channels.lower() == 'short period':
channels = 'EH*'
else:
channels = channels.replace(' ', '') # Get rid of spaces
t1 = UTCDateTime(event_time) + tstart
t2 = UTCDateTime(event_time) + tend
inventory = client.get_stations(latitude=event_lat, longitude=event_lon, minradius=minradiuskm/111.32, maxradius=maxradiuskm/111.32, channel=channels, level='channel', startbefore=t1, endafter=t2)
temp = inventory.get_contents()
netnames = temp['networks']
stas = temp['stations']
stanames = [n.split('.')[1].split()[0] for n in stas]
st = getdata(','.join(unique_list(netnames)), ','.join(unique_list(stanames)), location, channels, t1, t2, attach_response=True, clientname=source)
if st is None:
print('No data returned')
return
for trace in st:
try:
coord = inventory.get_coordinates(trace.id)
trace.stats.coordinates = AttribDict({'latitude': coord['latitude'], 'longitude': coord['longitude'], 'elevation': coord['elevation']})
except:
print('Could not attach coordinates for %s' % trace.id)
return st
示例8: get_events
def get_events():
print('Read event file')
try:
return readEvents(evname)
except:
pass
client = FSDNClient('NERIES')
events = client.get_events(**event_kwargs)
events.events.sort(key=lambda e: e.origins[0].time)
events.write(evname, 'QUAKEML')
return events
示例9: __init__
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="[email protected]", password="anonymous")
示例10: queryData
def queryData(self):
# code from IRIS client
#Here we pull the data
client = Client("IRIS")
DupStations = []
DupLocations = []
DupChannels = []
self.STAWILD = False
self.LOCWILD = False
self.CHANWILD = False
try:
requestArray = [(self.network,self.station,self.location, \
self.channel,self.startTime,self.endTime)]
print
if self.debug:
print(requestArray)
print
self.st = client.get_waveforms_bulk(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:
#print "Here is a trace we have"
#print(tr.stats)
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:
print 'Trouble getting data'
sys.exit(0)
#takes duplicate stations out of list
self.stations = list(set(DupStations))
self.locations = list(set(DupLocations))
self.channels = list(set(DupChannels))
print self.stations
print self.locations
print self.channels
# Now call code to store streams in mseed files
self.storeMSEED()
示例11: get_inventory
def get_inventory():
try:
return read_inventory(invname)
except:
pass
client = Client('GFZ')
net, sta, loc, cha = seed_id.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
示例12: data_download
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)
示例13: get_inventory
def get_inventory():
print('Read inventory file')
try:
return read_inventory(invname, 'STATIONXML')
except:
pass
print('Create inventory file...')
client = FSDNClient('ORFEUS')
inv = client.get_stations(**inventory_kwargs)
for net in inv:
for sta in net[:]:
if sta.code not in stations:
net.stations.remove(sta)
inv.write(invname, 'STATIONXML')
return inv
示例14: test_gmt_catalog
def test_gmt_catalog():
(options, args, parser) = command_parse()
input_dics = read_input_command(parser)
# Changing the input_dics values for testing
input_dics['min_date'] = UTCDateTime('2011-03-01')
input_dics['max_date'] = UTCDateTime('2011-03-20')
input_dics['min_mag'] = 8.9
evlatmin = input_dics['evlatmin']
evlatmax = input_dics['evlatmax']
evlonmin = input_dics['evlonmin']
evlonmax = input_dics['evlonmax']
evlat = input_dics['evlat']
evlon = input_dics['evlon']
evradmax = input_dics['evradmax']
evradmin = input_dics['evradmin']
client_fdsn = Client_fdsn(base_url=input_dics['event_catalog'])
events_QML = client_fdsn.get_events(
minlatitude=evlatmin,
maxlatitude=evlatmax,
minlongitude=evlonmin,
maxlongitude=evlonmax,
latitude=evlat,
longitude=evlon,
maxradius=evradmax,
minradius=evradmin,
mindepth=input_dics['min_depth'],
maxdepth=input_dics['max_depth'],
starttime=input_dics['min_date'],
endtime=input_dics['max_date'],
minmagnitude=input_dics['min_mag'],
maxmagnitude=input_dics['max_mag'],
orderby='time',
catalog=None,
magnitudetype=input_dics['mag_type'])
assert events_QML[0].preferred_origin().latitude == 38.2963
assert events_QML[0].preferred_origin().longitude == 142.498
assert events_QML[0].preferred_origin().depth == 19700.0
示例15: getSlowestStation
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