-
Notifications
You must be signed in to change notification settings - Fork 16
/
stack_helm.m
354 lines (321 loc) · 8.87 KB
/
stack_helm.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
% Program to stack phase velocity maps from each event
clear;
isrecalulatealpha = 0;
fixalpha = 1;
demoip = 4;
isfigure = 0;
phase_v_path = './helmholtz/'
r = 0.10;
setup_parameters
comp = parameters.component;
periods = parameters.periods;
lalim = parameters.lalim;
lolim = parameters.lolim;
gridsize = parameters.gridsize;
min_csgoodratio = parameters.min_csgoodratio;
min_phv_tol = parameters.min_phv_tol;
max_phv_tol = parameters.max_phv_tol;
is_raydense_weight = parameters.is_raydense_weight;
err_std_tol = parameters.err_std_tol;
min_event_num = parameters.min_event_num;
issmoothmap = parameters.issmoothmap;
smooth_wavelength = parameters.smooth_wavelength;
event_bias_tol = parameters.event_bias_tol;
xnode=lalim(1):gridsize:lalim(2);
ynode=lolim(1):gridsize:lolim(2);
Nx=length(xnode);
Ny=length(ynode);
[xi yi]=ndgrid(xnode,ynode);
phvmatfiles = dir([phase_v_path,'/*_helmholtz_',comp,'.mat']);
GV_cor_mat = zeros(Nx,Ny,length(phvmatfiles),length(periods));
GV_mat = zeros(Nx,Ny,length(phvmatfiles),length(periods));
raydense_mat = zeros(Nx,Ny,length(phvmatfiles),length(periods));
for ie = 1:length(phvmatfiles)
temp = load([phase_v_path,phvmatfiles(ie).name]);
helmholtz = temp.helmholtz;
if isrecalulatealpha
for ip=1:length(periods)
helmholtz(ip).GV_cor = ((helmholtz(ip).GV).^-2 + fixalpha.*helmholtz(ip).amp_term').^-.5;
end
end
event_ids(ie) = {helmholtz(1).id};
disp(helmholtz(1).id);
for ip=1:length(periods)
ind = find(helmholtz(ip).GV_cor < min_phv_tol);
helmholtz(ip).GV_cor(ind) = NaN;
ind = find(helmholtz(ip).GV_cor > max_phv_tol);
helmholtz(ip).GV_cor(ind) = NaN;
ind = find(helmholtz(ip).GV < min_phv_tol);
helmholtz(ip).GV(ind) = NaN;
ind = find(helmholtz(ip).GV > max_phv_tol);
helmholtz(ip).GV(ind) = NaN;
if helmholtz(ip).goodnum./helmholtz(ip).badnum < min_csgoodratio(ip)
disp('not enough good cs measurement');
helmholtz(ip).GV_cor(:) = NaN;
helmholtz(ip).GV(:) = NaN;
end
GV_cor_mat(:,:,ie,ip) = helmholtz(ip).GV_cor;
GV_mat(:,:,ie,ip) = helmholtz(ip).GV;
raydense_mat(:,:,ie,ip) = helmholtz(ip).raydense;
end
end
avgphv = average_GV_mat(GV_cor_mat, raydense_mat, parameters);
temp = average_GV_mat(GV_mat, raydense_mat, parameters);
for ip=1:length(avgphv)
avgphv(ip).GV_cor = avgphv(ip).GV;
avgphv(ip).GV = temp(ip).GV;
end
% Calculate std, remove the outliers
GV_mat = 1./GV_mat;
GV_cor_mat = 1./GV_cor_mat;
for ip=1:length(periods)
for i = 1:Nx
for j=1:Ny
avgphv(ip).GV_std(i,j) = nanstd(GV_mat(i,j,:,ip));
avgphv(ip).GV_cor_std(i,j) = nanstd(GV_cor_mat(i,j,:,ip));
ind = find( abs(GV_mat(i,j,:,ip) - 1./avgphv(ip).GV(i,j)) > err_std_tol*avgphv(ip).GV_std(i,j));
GV_mat(i,j,ind,ip) = NaN;
ind = find( abs(GV_cor_mat(i,j,:,ip) - 1./avgphv(ip).GV_cor(i,j)) > err_std_tol*avgphv(ip).GV_cor_std(i,j));
GV_cor_mat(i,j,ind,ip) = NaN;
end
end
end
GV_mat = 1./GV_mat;
GV_cor_mat = 1./GV_cor_mat;
% calculate the averaged phase velocity again
avgphv = average_GV_mat(GV_cor_mat, raydense_mat, parameters);
temp = average_GV_mat(GV_mat, raydense_mat, parameters);
for ip=1:length(avgphv)
avgphv(ip).GV_cor = avgphv(ip).GV;
avgphv(ip).GV = temp(ip).GV;
end
% remove bias events
for ip=1:length(periods)
avg_GV = avgphv(ip).GV_cor;
mean_phv = nanmean(avg_GV(:));
badnum = 0;
for ie=1:length(event_ids)
GV = GV_cor_mat(:,:,ie,ip);
diff_phv = GV-avg_GV;
diff_percent = nanmean(diff_phv(:))/mean_phv*100;
if abs(diff_percent) > event_bias_tol;
matfile = dir(fullfile('helmholtz',[char(event_ids(ie)),'*.mat']));
load(fullfile('helmholtz',matfile(1).name));
evla = helmholtz(1).evla;
evlo = helmholtz(1).evlo;
epi_dist = distance(evla,evlo,mean(lalim),mean(lolim));
badnum = badnum+1;
ind = find(~isnan(GV(:)));
stemp = sprintf('remove %s: id %d, ip %d, dist %f, bias: %f percent, good pixels: %d', char(event_ids(ie)),ie,ip,epi_dist, diff_percent,length(ind));
disp(stemp)
GV_cor_mat(:,:,ie,ip) = NaN;
GV_mat(:,:,ie,ip) = NaN;
end
end
end
% calculate the averaged phase velocity again
avgphv = average_GV_mat(GV_cor_mat, raydense_mat, parameters);
temp = average_GV_mat(GV_mat, raydense_mat, parameters);
for ip=1:length(avgphv)
avgphv(ip).GV_cor = avgphv(ip).GV;
avgphv(ip).GV = temp(ip).GV;
end
% re-Calculate std
for ip=1:length(periods)
for i = 1:Nx
for j=1:Ny
avgphv(ip).GV_std(i,j) = nanstd(GV_mat(i,j,:,ip));
avgphv(ip).GV_cor_std(i,j) = nanstd(GV_cor_mat(i,j,:,ip));
end
end
end
% fill in information
for ip=1:length(periods)
avgphv(ip).xi = xi;
avgphv(ip).yi = yi;
avgphv(ip).xnode = xnode;
avgphv(ip).ynode = ynode;
avgphv(ip).period = periods(ip);
end
if issmoothmap
disp(['Smoothing map based on wavelength']);
for ip=1:length(periods)
disp(ip);
D = smooth_wavelength*nanmean(avgphv(ip).GV(:))*periods(ip);
GV = smoothmap(xi,yi,avgphv(ip).GV,D);
GV(find(isnan(avgphv(ip).GV))) = NaN;
avgphv(ip).GV = GV;
GV_cor = smoothmap(xi,yi,avgphv(ip).GV_cor,D);
GV_cor(find(isnan(avgphv(ip).GV_cor))) = NaN;
avgphv(ip).GV_cor = GV_cor;
end
end
save(['helmholtz_stack_',comp,'.mat'],'avgphv','GV_mat','GV_cor_mat','raydense_mat','event_ids');
% plot section
if isfigure
figure(71)
clf
%for ip = 1:length(periods)
ip = demoip
subplot(2,2,2)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_cor);
% set(h1,'facecolor','interp');
title(['stack for corrected phv,','Periods: ',num2str(periods(ip))],'fontsize',15)
avgv = nanmean(avgphv(ip).GV(:));
if isnan(avgv)
continue;
end
caxis([avgv*(1-r) avgv*(1+r)])
colorbar
load seiscmap
colormap(seiscmap)
subplot(2,2,1)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV);
% set(h1,'facecolor','interp');
title(['stack for dynamics phv,','Periods: ',num2str(periods(ip))],'fontsize',15)
avgv = nanmean(avgphv(ip).GV(:));
if isnan(avgv)
continue;
end
caxis([avgv*(1-r) avgv*(1+r)])
colorbar
load seiscmap
colormap(seiscmap)
subplot(2,2,3)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_std);
title(['Original STD,','Periods: ',num2str(periods(ip))],'fontsize',15)
meanstd = nanmean(avgphv(ip).GV_std(:));
if ~isnan(meanstd)
caxis([0 2*meanstd])
end
colorbar
load seiscmap
colormap(seiscmap)
subplot(2,2,4)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_cor_std);
title(['corrected STD,','Periods: ',num2str(periods(ip))],'fontsize',15)
if ~isnan(meanstd)
caxis([0 2*meanstd])
end
colorbar
load seiscmap
colormap(seiscmap)
N=3; M = floor(length(periods)/N)+1;
figure(89)
clf
title('stack for dynamics phv')
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
avgv = nanmean(avgphv(ip).GV(:));
if isnan(avgv)
continue;
end
caxis([avgv*(1-r) avgv*(1+r)])
colorbar
load seiscmap
colormap(seiscmap)
end
drawnow;
figure(90)
clf
title('Std for dynamics phv')
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_std);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
colorbar
load seiscmap
colormap(seiscmap)
meanstd = nanmean(avgphv(ip).GV_std(:));
if ~isnan(meanstd)
caxis([0 2*meanstd])
end
end
drawnow;
figure(91)
clf
title('stack for structure phv')
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_cor);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
avgv = nanmean(avgphv(ip).GV(:));
if isnan(avgv)
continue;
end
caxis([avgv*(1-r) avgv*(1+r)])
colorbar
load seiscmap
colormap(seiscmap)
end
drawnow;
figure(92)
clf
title('Std for structure phv')
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_cor_std);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
colorbar
load seiscmap
colormap(seiscmap)
meanstd = nanmean(avgphv(ip).GV_std(:));
if ~isnan(meanstd)
caxis([0 2*meanstd])
end
% caxis([0 0.5])
end
drawnow;
figure(93)
clf
title('diff phv')
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).GV_cor-avgphv(ip).GV);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
colorbar
load seiscmap
colormap(seiscmap)
% caxis([0 0.5])
end
drawnow;
figure(95)
clf
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
h1=surfacem(xi,yi,avgphv(ip).sumweight);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
colorbar
load seiscmap
colormap(seiscmap)
end
drawnow;
end