%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = 12, 8
ObsPy has clients to directly fetch data via...
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.
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()
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, endtime=t + 24 * 3600,
minmagnitude=7)
print(catalog)
catalog.plot();
Requests can have a wide range of constraints (see ObsPy Documentation):
Finally, the FDSN client can be used to request station metadata. Stations can be looked up using a wide range of constraints (see ObsPy documentation):
event = catalog[0]
origin = event.origins[0]
# Münster
lon = 7.63
lat = 51.96
inventory = client.get_stations(longitude=lon, latitude=lat,
maxradius=2.5, level="station")
print(inventory)
The level=...
keyword is used to specify the level of detail in the requested inventory
"network"
: only return information on networks matching the criteria"station"
: return information on all matching stations"channel"
: return information on available channels in all stations networks matching the criteria"response"
: include instrument response for all matching channels (large result data size!)inventory = client.get_stations(network="OE", station="DAVA",
level="station")
print(inventory)
inventory = client.get_stations(network="OE", station="DAVA",
level="channel")
print(inventory)
For waveform requests that include instrument correction, the appropriate instrument response information can be attached to waveforms automatically:
(Of course, for work on large datasets, the better choice is to download all station information and avoid the internal repeated webservice requests)
t = UTCDateTime("2011-03-11T05:46:23") # Tohoku
st = client.get_waveforms("II", "PFO", "*", "LHZ",
t + 10 * 60, t + 30 * 60, attach_response=True)
st.plot()
st.remove_response()
st.plot()
All data requested using the FDSN client can be directly saved to file using the filename="..."
option. The data is then stored exactly as it is served by the data center, i.e. without first parsing by ObsPy and outputting by ObsPy.
client.get_events(starttime=t-100, endtime=t+24*3600, minmagnitude=7,
filename="/tmp/requested_events.xml")
client.get_stations(network="OE", station="DAVA", level="station",
filename="/tmp/requested_stations.xml")
client.get_waveforms("II", "PFO", "*", "LHZ", t + 10 * 60, t + 30 * 60,
filename="/tmp/requested_waveforms.mseed")
!ls -lrt /tmp/requested*
Use the FDSN client to assemble a waveform dataset for on event.
limit=5
to keep network traffic down)
from obspy.clients.fdsn import Client
client = Client()
catalog = client.get_events(minmagnitude=7, limit=5, mindepth=400)
print(catalog)
catalog.plot()
event = catalog[0]
print(event)
origin = event.origins[0]
t = origin.time
inventory = client.get_stations(longitude=origin.longitude, latitude=origin.latitude,
minradius=101, maxradius=102,
starttime=t, endtime =t+100,
channel="LHZ", matchtimeseries=True)
print(inventory)
get_waveforms()
call in a try/except/pass block to silently skip stations that actually have no data available)
from obspy import Stream
st = Stream()
for network in inventory:
for station in network:
try:
st += client.get_waveforms(network.code, station.code, "*", "LHZ",
t - 5 * 60, t + 30 * 60, attach_response=True)
except:
pass
print(st)
st.plot()
st.remove_response(water_level=20)
st.plot()
If you have time, assemble and plot another similar dataset (e.g. like before stations at a certain distance from a big event, or use Transportable Array data for a big event, etc.)