Obspy地震数据下载脚本

简介

目前实现的功能:

  • 下载特定台站的地震波形
  • 保存为.mseed文件,或者更改format属性保存sac文件等

缺陷,之后进行改进:

  • 一次运行只能保存一个台站的波形数据
  • 保存的数据为mseed文件,其中所有的波形均在这一个mseed文件中。
  • 文件命名并不全面,文件内部的波形未重新命名。

代码

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from obspy.core import read
import obspy
from obspy.clients.fdsn import Client
from obspy import UTCDateTime


def sigle_net(time1, time2): # 单个台站数据返回
net = input('Please input the network, default is IU:')
if net == '':
net = 'IU'
print(f'You have choosen ***{net}*** as the network.')

print("***************************************************")
print("Please wait a minute, you will see info about the network:")
print("***************************************************")

downloadstations = Client().get_stations(network=net, station='*', location='*', starttime=time1, endtime=time2, level='response')
print(downloadstations)
print('You could choose the stations, locations and channel, and they are shown thereinbefore.')

print('Default means you could just **enter** or make a space to show there is no word.')

stat = input('Please input the station, default is all stations:')
if stat == '' or ' ':
stat = '*'
loc = input('Please input the location, default is all locations:')
if loc == '' or ' ':
loc = '*'
cha = input('Please input the channel, default is all channels:')
if cha == '' or ' ':
cha = '*'
res = input('If you want response? Please input Y/N:')

print("***************************************************")
print("Data is getting...")
print("***************************************************")

while True: # 循环表示
if res == 'Y' or res == 'y':
res = 'response'
data = Client().get_waveforms(network=net, station=stat, location=loc, channel=cha, starttime=time1, endtime=time2, attach_response=True)
break
elif res == 'N' or res == 'n':
data = Client().get_waveforms(network=net, station=stat, location=loc, channel=cha, starttime=time1, endtime=time2, attach_response=False)
break
else:
res = input('You have input the wrong world, please input it again:')
info = {'network': net, 'station': stat, 'location': loc, 'channel': cha}
print('Have got the data.')
return data, info

timest, timee = input('Please input the time range of the data, use space for interval(e.g. 2022-01-01T00:00:00):\n').split(' ')
timest, timee = UTCDateTime(timest), UTCDateTime(timee)
import os
path = ('DATA/')
check = os.path.isdir(path)
if check == False:
os.mkdir(path)

quantity = input('How mant networks do you want? If you want more than 1 network, Please input its quantity, or just **enter**:')
if quantity == '' or quantity == 1: # 避免出现输入1的情况导致错误 保存波形文件
[data, info] = sigle_net(timest, timee)
filename = (path + timest + '.' + info["network"] + '.' + info["station"] + '.' +
info['location'] + '.' + info["channel"] + '.mseed') # 目前信息不全,之后寻找更多信息补充
data.write(filename, format="mseed") # 目前只能保存一整个mseed文件。

print(data)
print(type(data))
'''
else:
data = multi_net(quantity, times, timee)

'''