-
Notifications
You must be signed in to change notification settings - Fork 16
/
stack_grv.m
180 lines (161 loc) · 4.57 KB
/
stack_grv.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
% Program to stack phase velocity maps from each event
clear;
phase_v_path = './gveikonal/'
r = 0.05;
isfigure = 1;
setup_parameters
comp = parameters.component;
periods = parameters.periods;
lalim = parameters.lalim;
lolim = parameters.lolim;
gridsize = parameters.gridsize;
min_phv_tol = parameters.min_phv_tol;
max_phv_tol = parameters.max_phv_tol;
is_raydense_weight = parameters.is_raydense_weight;
min_event_num = parameters.min_event_num;
err_std_tol = parameters.err_std_tol;
xnode=lalim(1):gridsize:lalim(2);
ynode=lolim(1):gridsize:lolim(2);
Nx=length(xnode);
Ny=length(ynode);
[xi yi]=ndgrid(xnode,ynode);
for ip=1:length(periods)
avgphv(ip).sumV = zeros(Nx,Ny);
avgphv(ip).sumweight = zeros(Nx,Ny);
avgphv(ip).GV_std = zeros(Nx,Ny);
avgphv(ip).eventnum = zeros(Nx,Ny);
avgphv(ip).xi = xi;
avgphv(ip).yi = yi;
avgphv(ip).xnode = xnode;
avgphv(ip).ynode = ynode;
avgphv(ip).period = periods(ip);
end
phvmatfiles = dir([phase_v_path,'/*_',comp,'_gv.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;
disp(eventphv(1).id);
evla(ie) = eventphv(ip).evla;
evlo(ie) = eventphv(ip).evlo;
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 < parameters.min_csgoodratio
disp('too few good cs');
eventphv(ip).GV(:) = NaN;
end
GV_mat(:,:,ie,ip) = eventphv(ip).GV;
if ~is_raydense_weight
eventphv(ip).raydense(:) = 1;
end
raydense_mat(:,:,ie,ip) = eventphv(ip).raydense;
ind = find(~isnan(eventphv(ip).GV));
avgphv(ip).sumV(ind) = avgphv(ip).sumV(ind) + eventphv(ip).GV(ind).*eventphv(ip).raydense(ind);
avgphv(ip).sumweight(ind) = avgphv(ip).sumweight(ind) + eventphv(ip).raydense(ind);
avgphv(ip).eventnum(ind) = avgphv(ip).eventnum(ind)+1;
end
end
for ip=1:length(periods)
avgphv(ip).GV = avgphv(ip).sumV ./ avgphv(ip).sumweight;
ind = find(avgphv(ip).eventnum < min_event_num);
avgphv(ip).GV(ind) = NaN;
end
ori_GV_mat = GV_mat;
% Calculate std, remove the outliers
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) - avgphv(ip).GV(i,j)) > err_std_tol*avgphv(ip).GV_std(i,j));
GV_mat(i,j,ind,ip) = NaN;
end
end
end
% calculate the averaged phase velocity again
for ip=1:length(periods)
avgphv(ip).sumV = zeros(Nx,Ny);
avgphv(ip).sumweight = zeros(Nx,Ny);
avgphv(ip).eventnum = zeros(Nx,Ny);
end
for ip = 1:length(periods)
for ie = 1:length(phvmatfiles)
GV = GV_mat(:,:,ie,ip);
raydense = raydense_mat(:,:,ie,ip);
ind = find(~isnan(GV));
avgphv(ip).sumV(ind) = avgphv(ip).sumV(ind) + GV(ind).*raydense(ind);
avgphv(ip).sumweight(ind) = avgphv(ip).sumweight(ind) + raydense(ind);
avgphv(ip).eventnum(ind) = avgphv(ip).eventnum(ind)+1;
end
end
for ip=1:length(periods)
avgphv(ip).GV = avgphv(ip).sumV ./ avgphv(ip).sumweight;
ind = find(avgphv(ip).eventnum < min_event_num);
avgphv(ip).GV(ind) = NaN;
end
save(['eikonal_stack_',comp,'_gv.mat'],'avgphv','GV_mat','ori_GV_mat','evla','evlo');
if isfigure
N=3; M = floor(length(periods)/N)+1;
figure(89)
clf
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
if exist('drawlocal.m','file')
drawlocal
end
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
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
if exist('drawlocal.m','file')
drawlocal
end
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)
caxis([0 0.4])
end
drawnow;
figure(91)
clf
for ip = 1:length(periods)
subplot(M,N,ip)
ax = worldmap(lalim, lolim);
set(ax, 'Visible', 'off')
if exist('drawlocal.m','file')
drawlocal
end
h1=surfacem(xi,yi,avgphv(ip).sumweight);
% set(h1,'facecolor','interp');
title(['Periods: ',num2str(periods(ip))],'fontsize',15)
colorbar
meanweight = nanmedian(avgphv(ip).sumweight(:));
caxis([0 2*meanweight]);
load seiscmap
colormap(seiscmap)
end
drawnow;
end