-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_mseed_mat.py
55 lines (39 loc) · 1.47 KB
/
convert_mseed_mat.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
import scipy.io as sio
from obspy import read
import os, sys
import argparse
mseedfile = 'example_2020-05-01_IN.RAGD..BHZ.mseed'
info_string = '''
Python utility program to convert mseed file to mat (by Utpal Kumar, IESAS, 2021/04)
'''
PARSER = argparse.ArgumentParser(description=info_string)
def main(args):
mseedfile = args.input_mseed
st = read(mseedfile)
filename, _ = os.path.splitext(mseedfile)
if not args.output_mat:
outfilename = filename +".mat"
else:
outfilename = args.output_mat
outdict = {}
# st.plot(outfile=f"{filename}.png")
outdict['stats'] = {}
outdict['data'] = {}
for ii,tr in enumerate(st):
outdict['stats'][f'stats_{ii}'] = {}
for val in tr.stats:
if val in ['starttime', 'endtime']:
outdict['stats'][f'stats_{ii}'][val] = str(tr.stats[val])
else:
outdict['stats'][f'stats_{ii}'][val] = tr.stats[val]
outdict['data'][f"data_{ii}"] = tr.data
# print(outdict)
sio.savemat(
outfilename, outdict
)
sys.stdout.write(f"Output file: {outfilename}\n")
if __name__ == '__main__':
PARSER.add_argument("-inp",'--input_mseed', type=str, help="input mseed file, e.g. example_2020-05-01_IN.RAGD..BHZ.mseed", required=True)
PARSER.add_argument("-out",'--output_mat', type=str, help="output mat file name, e.g. example_2020-05-01_IN.RAGD..BHZ.mat")
args = PARSER.parse_args()
main(args)