Browse Source

fdsn: event requests

master
Marius Kriegerowski 2 years ago
parent
commit
345bea2de3
2 changed files with 51 additions and 3 deletions
  1. +13
    -3
      examples/fdsn_request_geofon.py
  2. +38
    -0
      src/client/fdsn.py

+ 13
- 3
examples/fdsn_request_geofon.py View File

@ -1,16 +1,26 @@
from pyrocko.client import fdsn
from pyrocko import util, io, trace
from pyrocko import util, io, trace, model
from pyrocko.io import quakeml
tmin = util.stt('2014-01-01 16:10:00.000')
tmax = util.stt('2014-01-01 16:39:59.000')
# select stations by their NSLC id and wildcards (asterisk)
# request events at IRIS for the given time span
request_event = fdsn.event(
site='iris', starttime=tmin, endtime=tmax)
# parse QuakeML and extract pyrocko events
events = quakeml.QuakeML.load_xml(request_event).get_pyrocko_events()
model.dump_events(events, 'iris-events.pf')
# select stations by their NSLC id and wildcards (asterisk) for waveform
# download
selection = [
('*', 'HMDT', '*', '*', tmin, tmax), # all available components
('GE', 'EIL', '*', '*Z', tmin, tmax), # all vertical components
]
# Restricted access token
# token = open('token.asc', 'rb').read()
# request_waveform = fdsn.dataselect(site='geofon', selection=selection,


+ 38
- 0
src/client/fdsn.py View File

@ -334,3 +334,41 @@ def dataselect(url=g_url, site=g_default_site, majorversion=1, selection=None,
timeout=params.get('timeout', g_timeout))
else:
return _request(url, user=user, passwd=passwd, **params)
def event(url=g_url, site=g_default_site, majorversion=1, selection=None,
user=None, passwd=None, token=None, **kwargs):
'''Query FDSN web service for events
On success, will return a list of events in QuakeML format.
Check the documentation of FDSN for allowed arguments:
https://www.fdsn.org/webservices
'''
allowed_kwargs = {
'starttime', 'endtime', 'minlatitude', 'maxlatitue',
'minlongitude', 'maxlongitude', 'latitude', 'longitude',
'minradius', 'maxradius', 'mindepth', 'maxdepth', 'minmagnitude',
'maxmagnitude', 'magnitudetype', 'eventtype', 'includeallorigins',
'includeallmagnitudes', 'includearrivals', 'eventid'}
for k in kwargs.keys():
if k not in allowed_kwargs:
raise ValueError('invalid argument: %s' % k)
if user or token:
method = 'queryauth'
else:
method = 'query'
if token is not None:
user, passwd = get_auth_credentials(
token, url=url, site=site, majorversion=majorversion)
url = fillurl(url, site, 'event', majorversion, method=method)
params = fix_params(kwargs)
return _request(url, user=user, passwd=passwd, **params)

Loading…
Cancel
Save