首先需要明确的是,ObsPy是一个独立的地震数据处理模块,包含读数据、处理数据、作图等功能。

正如之前蒋师兄所说,ObsPy诞生在SAC之后,因此ObsPy应该是融入了SAC的绝大部分功能。

一,基本申请功能

我首先需要了解ObsPy的基本数据申请功能,包含波形数据申请、获取事件、台站分布等三个部分。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
###############################################
#waveform_event_stations
###############################################

#source activate the environment of obspy and enter Python
source activate obspy
python

#Initialize a client project
from obspy.clients.fdsn import Client
client=Client("IRIS")

#Show currently avaliable providers
from obspy.clients.fdsn.header import URL_MAPPINGS
for key in sorted(URL_MAPPINGS.keys()):
print("{0:<7} {1}".format(key, URL_MAPPINGS[key]))
#Note: It's vital importrant to do indent properly,or errors will happened just like this: expected an indented block

#Next, the basic usage of getting event_waveform_data will be showed
#At the first of all, i really need to know what i want to do very clearly
#Nowthen, My needs are list below:
#(1)Event: around 2010-02-27 06:45 (UTC) in New Mexico, ANMO. 120 minutes of the "LHZ" channel
#(2)Network: GSN, global seismograph networks, IU
#Results are returned as stream objects
from obspy import UTCDateTime
t = UTCDateTime("2010-02-27T06:45:00.000")
st = client.get_waveforms("IU","ANMO","00","LHZ",t,t+120*60)
st.plot()

#get_events
starttime = UTCDateTime("2009-08-27")
endtime = UTCDateTime("2010-02-27")
cat=client.get_events(starttime=starttime,endtime=endtime,minmagnitude=6,catalog="ISC")
print(cat)
#or, you want to see all event during the given time range
#print(cat.__str__(print_all=True))
cat.plot()

#get_stations
inventory = client.get_stations(network="IU", station="A*",starttime=starttime,endtime=endtime)
print(inventory)
#the code, inventory.plot(), cannot work.

二,Routing Clients

路由服务(Routers),即一种可以从任何一个数据中心查询数据的网络服务,然后再在这些信息的基础上去下载数据,以节省时间。

所有的路由服务现在仅支持两种服务:数据选择(dataselect)和台站(station)服务,且需要服从FDSNWS服务框架。而ObsPy支持两种路由服务:IRIS FederatorEIDAWS Routing Service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ObsPy provides two method to query which data centers offer certain pieces of data.
#(1)IRIS Federator
#(2)EDIAWS Routing Services

#client_get_waveforms
from obspy import UTCDateTime
client = RoutingClient("iris-federator")
st=client.get_waveforms(channel="LHZ",starttime=UTCDateTime(2017, 1, 1),endtime=UTCDateTime(2017, 1, 1, 0, 5),latitude=10,longtitude=10,maxradius=25)
print(st)
st.plot()

#client_get_stations
client = RoutingClient("iris-federator")
inv=client.get_stations(channel="LHZ",starttime=UTCDateTime(2017, 1, 1),endtime=UTCDateTime(2017, 1, 1, 0, 5),latitude=10,longtitude=10,maxradius=25)
print(inv)

Reference:

https://docs.obspy.org/packages/obspy.clients.fdsn.html#id2