-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-seism.pl
executable file
·217 lines (186 loc) · 6.91 KB
/
plot-seism.pl
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env perl
use strict;
use warnings;
# plot seismogram
#my $phase = "PKIKP-PKiKP"; # phase
my $phase = "SKP"; # phase
#my $sta = "ARU"; # station
my $sta = "AAK"; # station
my $data_dir = "../data/seismograms"; # data directory
my @events = ("19931201005901500", "20030906154700205"); # two events
my @colors = ("blue", "red"); # colors
# GMT parameters
my $PS = "../figs/seism-${sta}-${phase}.ps";
my $J = "X6c/2c";
my ($x1, $x2, $y1, $y2) = split " ", &find_R($phase,$sta);
my $R = "$x1/$x2/$y1/$y2";
# GMT default setting
`gmt gmtset MAP_FRAME_PEN 0.5p`;
`gmt gmtset MAP_TICK_LENGTH_PRIMARY 1.5p`;
`gmt gmtset MAP_LABEL_OFFSET 2p`;
`gmt gmtset FONT_ANNOT_PRIMARY 6p,Helvetica`;
`gmt gmtset FONT_LABEL 8p,Helvetica`;
# begin plotting
`gmt psxy -J$J -R$R -P -T -K > $PS`;
# plot seismograms
for (my $i = 0; $i < @events; $i++) {
my @files = glob "$data_dir/$events[$i]/*.${sta}.*"; chomp @files;
my ($xx1, $xx2) = (1144,1151);
if ($i == 0) {
`gmt pssac @files -J -R -En -Tt-3 -M-1.2c -W1p,$colors[$i] -P -K -O >> $PS`;
}
else {
my ($dt) = -1 * &find_dt($phase, $sta);
print STDERR "$sta: shift $dt s for $phase\n";
`gmt pssac @files -J -R -En -Tt-3+s$dt -M-1.2c -W1p,$colors[$i] -P -K -O >> $PS`;
}
}
# plot text
my ($x, $y) = ($x2-0.3, $y2-0.2);
`echo $x $y $sta | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
if ($phase eq "PKIKP-PKiKP") {
if ($sta eq "AAK") {
$x = $x2-1.6;
`echo $x $y 0 \104 | gmt pstext -J -R -F+f8,12,black+a+jLM -N -K -O >> $PS`;
$x = $x2-1.4;
`echo $x $y 0 = 130\260 | gmt pstext -J -R -F+f8,black+a+jLM -N -K -O >> $PS`;
}
elsif ($sta eq "ARU") {
$x = $x2-1.6;
`echo $x $y 0 \104 | gmt pstext -J -R -F+f8,12,black+a+jLM -N -K -O >> $PS`;
$x = $x2-1.4;
`echo $x $y 0 = 132\260 | gmt pstext -J -R -F+f8,black+a+jLM -N -K -O >> $PS`;
}
}
if ($phase eq "SKP") {
($x, $y) = ($x2-3.5, $y1+0.3);
`echo $x $y $phase | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
} elsif ($phase eq "PKIKP-PKiKP") {
if ($sta eq "AAK") {
($x, $y) = ($x1+1, $y1+0.2);
`echo $x $y PKIKP | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
($x, $y) = ($x1+1, $y1+0.34);
`echo $x $y 55 0.5 | gmt psxy -J -R -Sv0.2c+e -W0.6p -Gblack -N -O -K >> $PS`;
($x, $y) = ($x1+2.2, $y1+0.2);
`echo $x $y PKiKP | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
($x, $y) = ($x1+2.2, $y1+0.34);
`echo $x $y 65 0.5 | gmt psxy -J -R -Sv0.2c+e -W0.6p -Gblack -N -O -K >> $PS`;
}
elsif ($sta eq "ARU") {
($x, $y) = ($x1+1.3, $y1+0.3);
`echo $x $y PKIKP | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
($x, $y) = ($x1+2.7, $y1+0.3);
`echo $x $y PKiKP | gmt pstext -J -R -F+f8 -N -K -O >> $PS`;
}
}
# plot doublet id
if ($sta eq "AAK" && $phase eq "PKIKP-PKiKP") {
my $xx1 = $x1+0.6; my $xx2 = $xx1+0.5;
my $yy1 = $y2-0.2; my $yy2 = $yy1-0.2;
open(GMT, "| gmt psxy -J -R -W1p,$colors[0] -K -O >> $PS");
print GMT "$xx1 $yy1\n$xx2 $yy1\n";
close(GMT);
open(GMT, "| gmt psxy -J -R -W1p,$colors[1] -K -O >> $PS");
print GMT "$xx1 $yy2\n$xx2 $yy2\n";
close(GMT);
`echo $xx2 $yy1 1993/12/01 | gmt pstext -J -R -F+f6,$colors[0]+jLM -N -K -O >> $PS`;
`echo $xx2 $yy2 2003/09/06 | gmt pstext -J -R -F+f6,$colors[1]+jLM -N -K -O >> $PS`;
}
# plot dt
if ($phase eq "PKIKP-PKiKP") {
my $xx=$x2-1.7; my $yy1=$y1+0.45; my $yy2=$y1+0.2;
`echo $xx $yy1 "dt\(PKIKP\) = -0.106 s" | gmt pstext -J -R -F+f6+jLM -N -K -O >> $PS`;
`echo $xx $yy2 "dt\(PKiKP\) = -0.106 s" | gmt pstext -J -R -F+f6+jLM -N -K -O >> $PS`;
}
elsif ($phase eq "SKP") {
if ($sta eq "AAK") {
my $xx=$x2-1.55; my $yy=$y1+0.2;
`echo $xx $yy "dt\(SKP\) = -0.184 s" | gmt pstext -J -R -F+f6+jLM -N -K -O >> $PS`;
}
elsif ($sta eq "ARU") {
my $xx=$x2-1.55; my $yy=$y1+0.2;
`echo $xx $yy "dt\(SKP\) = -0.185 s" | gmt pstext -J -R -F+f6+jLM -N -K -O >> $PS`;
}
}
# plot basemap
`gmt psbasemap -J -R -BwSne -Bxa1f0.5+l"t (sec)" -K -O >> $PS`;
# plot SKP noise at AAK
`gmt psxy -J -R -X1c -Y1.45c -T -K -O >> $PS`;
if ($sta eq "AAK" && $phase eq "SKP") {
my $J2 = "X4c/0.5c";
my $x11=$x1-17; my $x22=$x2+8;
my $R2 = "$x11/$x22/$y1/$y2";
for (my $i = 0; $i < @events; $i++) {
my @files = glob "$data_dir/$events[$i]/*.${sta}.*"; chomp @files;
if ($i == 0) {
`gmt pssac @files -J$J2 -R$R2 -En -Tt-3 -M-1.4c -W0.5p,$colors[$i] -P -K -O >> $PS`;
}
else {
my ($dt) = -1 * &find_dt($phase, $sta);
print STDERR "$sta: shift $dt s for $phase\n";
`gmt pssac @files -J -R -En -Tt-3+s$dt -M-1.4c -W0.5p,$colors[$i] -P -K -O >> $PS`;
}
}
# plot box
open(GMT, "| gmt psxy -J -R -W0.5p,black,4_2_4_2:0p -K -O >> $PS");
print GMT "$x1 $y1\n$x1 $y2\n";
close(GMT);
open(GMT, "| gmt psxy -J -R -W0.5p,black,4_2_4_2:0p -K -O >> $PS");
print GMT "$x2 $y1\n$x2 $y2\n";
close(GMT);
`echo $x1 $y1 -168 3.3 | gmt psxy -J -R -Sv0.15c+e -W0.5p -Gblack -N -O -K >> $PS`;
`echo $x2 $y1 -18 2.1 | gmt psxy -J -R -Sv0.15c+e -W0.5p -Gblack -N -O -K >> $PS`;
`gmt gmtset MAP_ANNOT_OFFSET_PRIMARY 2.2p`;
`gmt psbasemap -J$J2 -R$R2 -BWSe -Bxa5 -K -O >> $PS`;
}
`gmt psxy -J$J -R$R -X-1c -Y-1.45c -T -K -O >> $PS`;
# end plot
`gmt psxy -J -R -T -O >> $PS`;
#`gmt psconvert -Tf -P -A $PS`;
`rm gmt.*`;
##############################
# find traveltime difference due to location difference
# input : phase, station
# output : traveltime difference
sub find_dt {
my ($phase, $sta) = @_;
open(STA, "< ../docs/$sta") or die "Error in opening $sta.\n";
my @lines = <STA>; close(STA); chomp @lines;
for (my $i = 1; $i < @lines; $i++) {
my ($dd, @dts) = split " ", $lines[$i];
if (abs($dd - 0.7) < 0.0001) {
# correct both horizontal and vertical separations
#return $dts[2] if ($phase eq "PKIKP-PKiKP");
#return $dts[$#dts] if ($phase eq "SKP");
# only correct vertical separations
return $dts[1] if ($phase eq "PKIKP-PKiKP");
return $dts[$#dts-1] if ($phase eq "SKP");
}
}
}
# find x1,x2,y1,y2 of -R for GMT
# input : phase, station
# output : x1,x2,y1,y2
sub find_R {
my ($phase, $sta) = @_;
my ($x1, $x2);
my ($y1, $y2) = (-1, 1);
($y1, $y2) = (-0.5, 1) if ($sta eq "AAK" && $phase eq "SKP");
if ($phase eq "SKP") {
if ($sta eq "AAK") {
$x1 = 1352; $x2 = 1357;
}
elsif ($sta eq "ARU") {
$x1 = 1349; $x2 = 1354;
}
}
elsif ($phase eq "PKIKP-PKiKP") {
if ($sta eq "AAK") {
$x1 = 1145; $x2 = 1150;
}
elsif ($sta eq "ARU") {
$x1 = 1149; $x2 = 1154;
}
}
return "$x1 $x2 $y1 $y2";
}