-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_waveforms.py
executable file
·61 lines (48 loc) · 1.58 KB
/
plot_waveforms.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
59
60
61
#!/usr/bin/env python3
import argparse
import matplotlib.pyplot as plt
import numpy as np
import os
from glob import glob
from scipy.signal import correlation_lags
from obspy.core import Trace
def read_ascii_waveform(file):
tmp = np.loadtxt(file, dtype="float")
t = tmp[:, 0]
a = tmp[:, 1]
dt = t[-1] - t[-2]
nt = t.size
ds = 1./dt
h = {"npts":nt, "delta":dt, "sampling_rate":ds, "channel":"HXZ"}
tr = Trace(data=a, header=h)
return tr
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('input_path', type=str)
parser.add_argument('--fil', type=float, default=None, nargs=2)
parser.add_argument('--nor', action='store_true')
parser.add_argument('--lim', type=float, default=None, nargs=2)
parser.add_argument('--lag', action='store_true')
args = parser.parse_args()
files = glob(args.input_path)
files.sort()
offset = 0.
for file_ in files:
tr = read_ascii_waveform(file_)
if args.fil:
tr.filter("bandpass", freqmin=args.fil[0], freqmax=args.fil[1],
corners=2, zerophase=True)
if args.nor:
tr.normalize()
tr.data += offset
if args.lag:
hnpts = (tr.stats.npts + 1.) / 2.
times = correlation_lags(hnpts, hnpts, mode="full") * tr.stats.delta
else:
times = tr.times()
plt.plot(times, tr.data, color='black', alpha=0.8)
offset = np.max(tr.data) + 0.5
if args.lim:
plt.xlim(args.lim[0], args.lim[1])
plt.xlabel('time (s)')
plt.show()