-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsac.py
More file actions
49 lines (45 loc) · 1.45 KB
/
Copy pathsac.py
File metadata and controls
49 lines (45 loc) · 1.45 KB
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
from subprocess import Popen,PIPE
from glob import glob
def trans(sacfile):
"""
sac file from seed
rmean;rtrend;taper
trans
write staname.BH?
"""
p = Popen(['sac'], stdin=PIPE, stdout=PIPE,stderr=PIPE)
temp = sacfile.split('.')
net,sta,code,ch = temp[6],temp[7],temp[8],temp[9]
respfile = '.'.join(['RESP',net,sta,code,ch])
outfile = '.'.join(['SAC',net,sta,code,ch])
f = [0.5,1,28,30]
s = ""
s += "r %s\n" % sacfile
s += "rmean;rtrend;taper\n"
s += "transfer from evalresp fname %s to none freq %f %f %f %f\n" % (respfile,f[0],f[1], f[2],f[3])
s += "w %s\n" % outfile
s += "q\n"
out,err = p.communicate(s.encode())
print(err.decode('utf-8'),out.decode('utf-8'))
def get_three(file_list):
result = []
common = lambda s : '.'.join(s.split('.')[:-1])
comm_parts = set(map(common,file_list))
for cp in comm_parts:
result.append(glob(cp+'*'))
return result
def rotate(file_list2):
for three in file_list2:
two = filter(lambda s:True if s.split('.')[-1]!='BHZ' else False,three)
two = list(two)
p = Popen(['sac'], stdin=PIPE, stdout=PIPE)
s = ""
s += "r %s\n" % ' '.join(two)
s += "rotate to gcp\n"
comm = '.'.join(two[0].split('.')[:-1])
s += "w %s.R %s.T\n" %(comm,comm)
s += "q\n"
p.communicate(s.encode())
def do_list(file_list):
for sacfile in file_list:
trans(sacfile)