-
Notifications
You must be signed in to change notification settings - Fork 16
/
stack_phv.m
200 lines (171 loc) · 4.81 KB
/
stack_phv.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
% Program to stack phase velocity maps from each event
clear;
isfigure = 1;
phase_v_path = './eikonal/'
r = 0.10;
load seiscmap
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,'/*_eikonal_',comp,'.mat']);
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]);
eventphv = temp.eventphv;
event_ids(ie) = {eventphv(1).id};
disp(eventphv(1).id);
for ip=1:length(periods)
ind = find(eventphv(ip).GV < min_phv_tol);
eventphv(ip).GV(ind) = NaN;
ind = find(eventphv(ip).GV > max_phv_tol);
eventphv(ip).GV(ind) = NaN;
if eventphv(ip).goodnum./eventphv(ip).badnum < min_csgoodratio(ip)
disp('not enough good cs measurement');
eventphv(ip).GV(:) = NaN;
end
GV_mat(:,:,ie,ip) = eventphv(ip).GV;
raydense_mat(:,:,ie,ip) = eventphv(ip).raydense;
end
end
avgphv = average_GV_mat(GV_mat, raydense_mat, parameters);
% Calculate std, remove the outliers
GV_mat = 1./GV_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));
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;
end
end
end
GV_mat = 1./GV_mat;
% calculate the averaged phase velocity again
avgphv = average_GV_mat(GV_mat, raydense_mat, parameters);
% remove bias events
for ip=1:length(periods)
avg_GV = avgphv(ip).GV;
mean_phv = nanmean(avg_GV(:));
badnum = 0;
for ie=1:length(event_ids)
GV = GV_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('eikonal',[char(event_ids(ie)),'*.mat']));
load(fullfile('eikonal',matfile(1).name));
evla = eventphv(1).evla;
evlo = eventphv(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_mat(:,:,ie,ip) = NaN;
end
end
end
% calculate the averaged phase velocity again
avgphv = average_GV_mat(GV_mat, raydense_mat, parameters);
% 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));
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;
end
end
save(['eikonal_stack_',comp,'.mat'],'avgphv','GV_mat','GV_mat','raydense_mat','event_ids');
% plot section
if isfigure
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(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