forked from SPECFEM/specfem3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_SU_file_with_obspy.py
executable file
·146 lines (115 loc) · 3.33 KB
/
plot_SU_file_with_obspy.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
#
# plot_SU_file_with_obspy.py
#
from __future__ import print_function
import os,sys
## matplotlib
#import matplotlib as mpl
#print("matplotlib version: ",mpl.__version__)
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = 20, 5
plt.rcParams['lines.linewidth'] = 0.5
## numpy
import numpy as np
print("numpy version: ",np.__version__)
## do not show scipy warnings
#import warnings
#warnings.filterwarnings('ignore')
## obspy
import obspy
print("obspy version: ",obspy.__version__)
## Seismic Unix
#
# needed on mcmillan
#suoldtonew < $file | suxwigb #perc=99 &
# reads header info:
# ns = number of samples
# dt = time step
# sx,sy = source coordinates
# gx,gy = receiver coordinates
#sugethw <$sufile key=dt,ns,sx,sy,gx,gy verbose=1
#
# removes headers
#sustrip <$sufile > $sufile.raw
#
# wiggle plot
#xwigb <$sufile n1=$NSTEP n2=$ntraces &
#
# image plot
#ximage <$sufile n1=$NSTEP n2=$ntraces &
#
# ps image
#suoldtonew <$sufile | supsimage label1="Time (s)" label2="Offset (m)" title="$sufile" perc=99 labelsize=22 verbose=1 > tmp.eps
#
# convert to png
#ps2pdf -r300 -sDEVICE=png16m -sOutputFile=$sufile.png tmp.eps
def plot_SU_file(file,show_plot):
print("")
print("getting station information...")
print("")
st = obspy.read(file)
print("traces: ")
print(st)
print("")
print("number of traces: ",len(st))
print("")
npts = 0
duration = 0.0
# trace statistics
if len(st) > 0:
tr = st[0]
#print(tr.stats)
npts = tr.stats.npts # number of samples
dt = tr.stats.delta # time step
duration = npts * dt
freq_Ny = 1.0/(2.0 * dt) # Nyquist frequency
freq_min = 1./duration # minimal possible frequency for length of trace
print("trace info:")
print(" number of samples = ",npts)
print(" time step = ",dt,"(s)")
print(" duration = ",duration,"(s)")
print(" Nyquist frequency = ",freq_Ny)
print(" minimum frequency = ",freq_min)
print("")
else:
print("no trace information, exiting...")
sys.exit(1)
# plotting
if show_plot:
# plots all traces
st.plot()
# time axis for plotting (in s)
t_d = np.linspace(0,duration,npts)
# vertical trace
for i,tr in enumerate(st):
print("Trace "+str(i+1)+":")
print(tr)
#print(tr.stats)
# plotting
plt.title("Trace " + str(i+1))
# vertical component
plt.plot(t_d, tr.data, color='black', linewidth=1.0,label="raw data trace "+str(i+1))
plt.legend()
plt.xlabel("Time (s)")
plt.ylabel("Counts")
plt.show()
def usage():
print("usage: ./plot_SU_file_with_obspy.py su_file [show]")
print(" with")
print(" su_file - seismogram file e.g. OUTPUT_FILES/0_dz_SU")
print(" show - (optional) plot waveforms")
sys.exit(1)
if __name__ == "__main__":
# gets arguments
do_plot_waveforms = False
if len(sys.argv) == 2:
file = sys.argv[1]
elif len(sys.argv) == 3:
file = sys.argv[1]
if sys.argv[2] == "show": do_plot_waveforms = True
else:
usage()
sys.exit(1)
plot_SU_file(file,do_plot_waveforms)