-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventphasediff.m
158 lines (145 loc) · 4.57 KB
/
eventphasediff.m
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
% This code is used to convert the result of ambient noise frequency method bessel function
% fitting phase measurement into a event based phase difference measurement between nearby stations
% as the input for the Eikonal Tomography
% Written by Ge Jin
clear
load stainfo_BHZ.mat
load xspinfo.mat
load refphasev.mat
% set good bessel fitting
errlevel = 1;
nbdist_range = 6; % Count by wavelength
directray_range = [2 5];
badstas = [40];
Isfigure = 0;
periods = 2*pi./twloc;
for ixsp = 1:length(xspinfo)
xspinfo(ixsp).isgood = 1;
if xspinfo(ixsp).sumerr > errlevel
xspinfo(ixsp).isgood = 0;
end
ind = find(badstas == xspinfo(ixsp).sta1);
if ~isempty(ind)
xspinfo(ixsp).isgood = 0;
end
ind = find(badstas == xspinfo(ixsp).sta2);
if ~isempty(ind)
xspinfo(ixsp).isgood = 0;
end
end % end of loop ixsp
for ista = 1:length(stainfo)
% for ista = 1
for ip = 1:length(twloc)
disp([stainfo(ista).staname,'_',num2str(ip)]);
evla = stainfo(ista).lat;
evlo = stainfo(ista).lon;
xspind = find([xspinfo(:).sta1] == ista | [xspinfo(:).sta2] == ista );
evid = ista;
% set up station array
stanum = 0;
clear slat slon staids xspids epidist coherenum
for ixsp = xspind
if xspinfo(ixsp).isgood == 0
continue;
end
if xspinfo(ixsp).sta2 == ista
staid = xspinfo(ixsp).sta1;
else
staid = xspinfo(ixsp).sta2;
end
stanum = stanum + 1;
slat(stanum) = stainfo(staid).lat;
slon(stanum) = stainfo(staid).lon;
staids(stanum) = staid;
xspids(stanum) = ixsp;
epidist(stanum) = deg2km(distance(evla,evlo,slat(stanum),slon(stanum)));
coherenum(stanum) = xspinfo(ixsp).coherenum;
end % end of xsp loop
% Loop through station array and find nearby connections
csnum=0;
clear ray dt ddist fiterr avgcoherenum
for ista1 = 1:stanum
sta1_id = staids(ista1);
tw1 = xspinfo(xspids(ista1)).tw;
err1 = xspinfo(xspids(ista1)).err;
xsp1 = xspinfo(xspids(ista1)).xsp;
if epidist(ista1) < directray_range(1)*periods(ip)*refv(ip)
continue;
end
% Find the nearby stations
dist = deg2km(distance(slat,slon,slat(ista1),slon(ista1)));
nearstaind = find(dist<nbdist_range*periods(ip)*refv(ip) & dist > 1);
for ista2 = nearstaind
if epidist(ista2) < directray_range(1)*periods(ip)*refv(ip)
continue;
end
sta2_id = staids(ista2);
if sta1_id > sta2_id
continue;
end
tw2 = xspinfo(xspids(ista2)).tw;
err2 = xspinfo(xspids(ista2)).err;
xsp2 = xspinfo(xspids(ista2)).xsp;
csnum = csnum+1;
ray(csnum,1) = slat(ista1);
ray(csnum,2) = slon(ista1);
ray(csnum,3) = slat(ista2);
ray(csnum,4) = slon(ista2);
dt(csnum) = tw1(ip) - tw2(ip);
ddist(csnum) = epidist(ista1) - epidist(ista2);
normerr = (err1(:)./mean(abs(xsp1))).^2 + (err2(:)./mean(abs(xsp2))).^2;
normerr = smooth(normerr,floor(length(waxis)/length(twloc)));
fiterr(csnum) = interp1(waxis,normerr,twloc(ip));
avgcoherenum(csnum) = sqrt(coherenum(ista1)*coherenum(ista2));
end %end of ista2 loop
end % end of ista1 loop
% add in station pairs from main station if the epidist is within the directray_range
% neardist = directray_range(1)*periods(ip)*refv(ip);
% fardist = directray_range(2)*periods(ip)*refv(ip);
% nearstaind = find(epidist < fardist & epidist > neardist);
% for ista1 = nearstaind
% tw1 = xspinfo(xspids(ista1)).tw;
% err1 = xspinfo(xspids(ista1)).err;
% xsp1 = xspinfo(xspids(ista1)).xsp;
%
% csnum = csnum+1;
% ray(csnum,1) = slat(ista1);
% ray(csnum,2) = slon(ista1);
% ray(csnum,3) = evla;
% ray(csnum,4) = evlo;
% dt(csnum) = tw1(ip);
% ddist(csnum) = epidist(ista1);
% normerr = 2*(err1(:)./mean(abs(xsp1))).^2;
% normerr = smooth(normerr,floor(length(waxis)/length(twloc)));
% fiterr(csnum) = interp1(waxis,normerr,twloc(ip));
% avgcoherenum(csnum) = coherenum(ista1);
% end % end of main station nbdist
% correct cycle skipping
for ics = 1:csnum
syndt = ddist(ics)./refv(ip);
N = -2:2;
testdt = dt(ics) + N.*2*pi./twloc(ip);
dterr = abs(testdt - syndt);
[bestdterr bestdti] = min(dterr);
dt(ics) = testdt(bestdti);
bestcycle(ics) = bestdti;
end
event(ista,ip).csnum = csnum;
if csnum > 10
event(ista,ip).ray = ray;
event(ista,ip).dt = dt;
event(ista,ip).ddist = ddist;
event(ista,ip).fiterr = fiterr;
event(ista,ip).bestcycle = bestcycle;
event(ista,ip).evla = evla;
event(ista,ip).evlo = evlo;
event(ista,ip).coherenum = avgcoherenum;
end
end % end of ip loop
if Isfigure && csnum > 0
plotcsray(event,stainfo,ista);
pause(0.5)
end
end % end of ista loop
save('events.mat','event');