Repository navigation
Expand file tree
/
Copy pathFun_PlotFaultSlip.m
More file actions
215 lines (186 loc) · 6.88 KB
/
Copy pathFun_PlotFaultSlip.m
File metadata and controls
215 lines (186 loc) · 6.88 KB
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
function Fun_PlotFaultSlip(locaSub, depSub, slip, source, grid, epicenter)
% =========================================================================
% Fun_PlotFaultSlip
%
% Plot final slip distribution on:
% 1) Surface projection of the fault plane (Depth = 0 km)
% 2) Actual subsurface finite-fault plane (Depth = depSub)
%
% Color represents final slip amplitude.
%
% Inputs:
% locaSub : N-by-2 subfault-center coordinates:
% [latitude, longitude]
%
% depSub : N-by-1 subfault-center depths (km)
%
% slip : Final slip distribution.
% It can be:
% - N-by-1 vector, or
% - Ndip-by-Nstrike matrix
%
% source : Hypocentral subfault index [idip, istrike]
%
% grid : Number of subfaults [Ndip, Nstrike]
%
% epicenter : Surface epicenter [latitude, longitude]
%
% Grid ordering:
% index = (istrike - 1) * Ndip + idip
%
% Note:
% Depth increases downward by:
% set(gca, 'ZDir', 'reverse')
% =========================================================================
%% ------------------------------------------------------------------------
% Input check
% -------------------------------------------------------------------------
grid = round(grid(:)');
source = round(source(:)');
Ndip = grid(1);
Nstrike = grid(2);
nsub = Ndip * Nstrike;
depSub = depSub(:);
if size(locaSub, 1) ~= nsub
error(['locaSub contains %d points, but grid requires %d ', ...
'subfaults (%d x %d).'], ...
size(locaSub, 1), nsub, Ndip, Nstrike);
end
if numel(depSub) ~= nsub
error('depSub must contain Ndip * Nstrike elements.');
end
if source(1) < 1 || source(1) > Ndip || ...
source(2) < 1 || source(2) > Nstrike
error('source = [idip, istrike] is outside the specified grid.');
end
%% ------------------------------------------------------------------------
% Reshape fault geometry
% -------------------------------------------------------------------------
% Rows: dip direction
% Columns: strike direction
latMat = reshape(locaSub(:, 1), Ndip, Nstrike);
lonMat = reshape(locaSub(:, 2), Ndip, Nstrike);
depMat = reshape(depSub, Ndip, Nstrike);
% Accept either a vector or an Ndip-by-Nstrike slip matrix.
if isvector(slip)
if numel(slip) ~= nsub
error('Vector slip must contain Ndip * Nstrike elements.');
end
slipMat = reshape(slip(:), Ndip, Nstrike);
elseif isequal(size(slip), [Ndip, Nstrike])
slipMat = slip;
else
error(['slip must be either an N-by-1 vector or an ', ...
'Ndip-by-Nstrike matrix.']);
end
if any(~isfinite(slipMat(:)))
error('slip contains NaN or Inf values.');
end
%% ------------------------------------------------------------------------
% Hypocenter coordinates
% -------------------------------------------------------------------------
hypoLat = latMat(source(1), source(2));
hypoLon = lonMat(source(1), source(2));
hypoDep = depMat(source(1), source(2));
%% ------------------------------------------------------------------------
% Color limits: use the same range for surface and subsurface planes
% -------------------------------------------------------------------------
slipMax = max(abs(slipMat(:)));
if slipMax <= eps
slipMax = 1;
end
% For scalar slip amplitude, the color range starts from zero.
cLim = [0, max(slipMat(:))];
% If slip has negative values, use symmetric color limits.
if min(slipMat(:)) < 0
cLim = [-slipMax, slipMax];
end
%% ------------------------------------------------------------------------
% Create figure
% -------------------------------------------------------------------------
figure('Color', 'w', 'Position', [160, 100, 800, 600]);
tiledlayout('flow','TileSpacing','compact','Padding','loose');
nexttile;
hold on;
box on;
% ------------------------------------------------------------------------
% Surface projection: z = 0
depProjection = zeros(size(depMat));
hProjection = surf(lonMat, latMat, depProjection, slipMat, ...
'FaceColor', 'interp', ...
'FaceAlpha', 0.9, ...
'EdgeColor', [0.30, 0.30, 0.30], ...
'EdgeAlpha', 0.75, ...
'LineStyle', '--', ...
'LineWidth', 0.7, ...
'DisplayName', 'Slip projection at surface');
% ------------------------------------------------------------------------
% Actual fault plane below the surface
hFault = surf(lonMat, latMat, depMat, slipMat, ...
'FaceColor', 'interp', ...
'FaceAlpha', 0.9, ...
'EdgeColor', [0.20, 0.20, 0.20], ...
'EdgeAlpha', 0.75, ...
'LineWidth', 0.7, ...
'DisplayName', 'Final slip on fault plane');
shading interp;
lighting gouraud;
% camlight('headlight');
%% ------------------------------------------------------------------------
% Mark surface epicenter
plot3(epicenter(2), epicenter(1), 0, 'kp', ...
'MarkerFaceColor', 'w', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 18, ...
'LineWidth', 1.2, ...
'DisplayName', 'Surface epicenter');
%% ------------------------------------------------------------------------
% Mark hypocentral subfault
plot3(hypoLon, hypoLat, hypoDep, 'rp', ...
'MarkerFaceColor', [0.8902, 0.1529, 0.4471], ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 18, ...
'LineWidth', 1.2, ...
'DisplayName', 'Hypocentral subfault');
% Connect epicenter and hypocenter.
plot3([epicenter(2), hypoLon], ...
[epicenter(1), hypoLat], ...
[0, hypoDep], ...
'k--', ...
'LineWidth', 1.0, ...
'HandleVisibility', 'off');
%% ------------------------------------------------------------------------
% Optional: highlight maximum-slip subfault
% -------------------------------------------------------------------------
% [~, maxSlipIndex] = max(abs(slipMat(:)));
% [idipMax, istrikeMax] = ind2sub([Ndip, Nstrike], maxSlipIndex);
% maxSlipLat = latMat(idipMax, istrikeMax);
% maxSlipLon = lonMat(idipMax, istrikeMax);
% maxSlipDep = depMat(idipMax, istrikeMax);
% plot3(maxSlipLon, maxSlipLat, maxSlipDep, 'o', ...
% 'MarkerSize', 10, ...
% 'MarkerFaceColor', 'none', ...
% 'MarkerEdgeColor', 'k', ...
% 'LineWidth', 1.8, ...
% 'DisplayName', 'Maximum-slip subfault');
%% ------------------------------------------------------------------------
% Axis settings
% -------------------------------------------------------------------------
xlabel('Longitude');
ylabel('Latitude');
zlabel('Depth (km)');
% Geophysical convention: depth increases downward.
set(gca, 'ZDir', 'reverse');
% You used this aspect-ratio convention in the original 2-D plot.
% axis vis3d;
view(45, 25);
% Color represents final slip.
colormap(slanCM('viridis', 60));
clim(cLim);
cb = colorbar;
cb.Label.String = 'Final slip';
cb.FontSize = 14;
set(gca, 'FontSize', 18, 'LineWidth', 1.0, 'FontName', 'Times New Roman', ...
'Projection', 'perspective');
hold off;
end