-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyslink2mseed_SLA.py
58 lines (46 loc) · 1.52 KB
/
pyslink2mseed_SLA.py
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
from obspy.clients.seedlink.easyseedlink import EasySeedLinkClient
from obspy.core.stream import read
from obspy.core import UTCDateTime
import os
import requests
# client_addr is in address:port format
client_addr = 'rtserve.iris.washington.edu:18000'
net = 'CI' # network code
sta = 'SLA' # station name
cha = 'BHZ' # channel
loc = '00' # Since obspy doesn't take location codes, this only affects the filename
multipleLoc = False
# Subclass the client class
class MyClient(EasySeedLinkClient):
# Implement the on_data callback
def on_data(self, trace):
# in case multiple loc in one station
if (multipleLoc and trace.get_id().find(loc) == -1):
return
day = UTCDateTime.now().strftime('%Y.%j')
fn = 'data/%s.%s.%s.%s.D.%s' % (net, sta, loc, cha, day)
print('Received traces. Checking for existing data...')
if (os.path.isfile(fn)):
print('Found %s, reading...' % fn)
originalTraces = read(fn)
traces = originalTraces + trace
else:
print('No data found. Creating new blank trace to write to...')
traces = trace
print('Trace: %s' %(trace))
print('Saving traces to %s...' % (fn))
traces.write(fn, format='MSEED')
print('Done.')
try:
requests.request(url='http://0.0.0.0:8088/updateSocket', method='GET')
except:
print('Cannot update status.')
# Connect to a SeedLink server
client = MyClient(client_addr)
# Retrieve INFO:STREAMS
streams_xml = client.get_info('STREAMS')
print(streams_xml)
# Select a stream and start receiving data
client.select_stream(net, sta, cha)
client.run()
print('A')