-
Notifications
You must be signed in to change notification settings - Fork 0
/
fault_measure.m
383 lines (294 loc) · 10.6 KB
/
fault_measure.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
% fault measuring
% This script calls necessary companion functions to read and automatically
% measure fault throws from grdtrack (GMT) outputs
%
% ***** RECORD *****
% 24 Apr 2018 | first cut | T.Morrow
%
%
% ***** ****** *****
% Input format should be series of cross-profiles from grdtrack,
% instructions below:
%
% After generating a .xy file for one fault, I use the following command
% grdtrack FT1.xy -GFAULT.grd -C4000e/200e/200e > FTXprof1.txt
% ^1 ^2 ^3
% arguments 1, 2, 3 are cross profile length, along-cross
% spacing, and along-fault interval respectively
% Then, concatenate all the files together
% cat FTXprof* >> allfts.txt
%
% Import this result into Matlab as a single matrix (will have NaNs
% between each segment)
%
% DEPENDENCIES
% GMT used to make input
% grdread2 used in demo
%
%
% OUTPUTS
% Heave and Throw arrays, with one measurement (m) per cross-section.
% NOTE: this method yields good measurements for throw but not so great
% for heave. Run demo case (see below) to see sample measurement (pink
% line)
%
% DEMO for one cross-section available at bottom of code
%% CODE
% naming conventions
% allfts imported fault numeric matrix
close all
% index cross profiles
I=find(isnan(allfts(:,1)));
% parse faults to cell array
for qq=1:length(I)
if qq==1
FTXs{qq}=allfts(1:I(qq)-1,:);
elseif qq==length(I)
FTXs{qq}=allfts(I(qq-1)+1:end,:);
else
FTXs{qq}=allfts(I(qq-1)+1:I(qq)-1,:);
end
end
% measure each fault cross section
for rr=1:length(I)
XP=FTXs{rr};
% matrix of XYZ pts defining one bathymetric profile across a fault
XFT = [XP(:,3) zeros(size(XP(:,1))) XP(:,5)];
XFT(:,2:4)=XFT;
XFT(:,1) = 1:length(XFT(:,2));
XFT = double(XFT);
% bathymetry resolution
rez = 60;
%plot3(XFT(:,2),XFT(:,3),XFT(:,4),'b');
%hold all
% minimum and maximum dip of faults
%DIPMN = minDIP;
%DIPMX = 90;
% standard deviation window size
w=40;
%% Calculate gradient along cross profile
GRDFT = horzcat(XFT(:,1:3), abs(gradient(XFT(:,4))));
%plot3(GRDFT(:,2),GRDFT(:,3),GRDFT(:,4)+mean(XFT(:,4)),'r') % -plot test for gradient- %
%% Find largest peak in standard deviation [not currently using]
T = XFT(:,4);
stdT=T.*0;
for i=1+w/2:length(stdT)-w/2-1
im=i-w/2:i+w/2;
stdT(i)=nanstd(T(im));
end
% find peaks
STD = horzcat(XFT(:,1:3), stdT);
%plot3(STD(:,2),STD(:,3),STD(:,4)+mean(XFT(:,4)),'k');
STD_PKS = findpeaks(STD(:,4));
% find peak locations
for ii = 1:length(STD_PKS)
if (ii == 1);
STD_LOC_old = STD(find(STD(:,4)==STD_PKS(ii,1)),1:4);
else
STD_LOC_new = STD(find(STD(:,4)==STD_PKS(ii,1)),1:4);
STD_LOC_old = vertcat(STD_LOC_old, STD_LOC_new);
end
end
STD_LOC = flipud(sortrows(STD_LOC_old,4));
%plot3(STD_LOC(:,2),STD_LOC(:,3),ones(length(STD_LOC),1)*mean(XFT(:,4)),'^k'); % -plot test for std peaks- %
MXSTD = STD_LOC(1,1:3);
%% Find peak-based bounds
GRD_BND = horzcat(GRDFT(:,1:3), -GRDFT(:,4));
%plot3(GRD_BND(:,2),GRD_BND(:,3),GRD_BND(:,4)+mean(XFT(:,4)),'r') % -plot test for inv gradient- %
% find peaks of inverted gradient
BND_PKS = findpeaks(GRD_BND(:,4));
for ii = 1:length(BND_PKS);
if (ii == 1)
BNDPK_LOC_old = GRD_BND(find(GRD_BND(:,4)==BND_PKS(ii,1)),1:3);
else
BNDPK_LOC_new = GRD_BND(find(GRD_BND(:,4)==BND_PKS(ii,1)),1:3);
BNDPK_LOC_old = vertcat(BNDPK_LOC_old, BNDPK_LOC_new);
end
end
BNDPK_LOC = BNDPK_LOC_old;
BNDPK_LOC = sortrows(BNDPK_LOC,1);
%plot3(BNDPK_LOC(:,2),BNDPK_LOC(:,3),ones(length(BNDPK_LOC(:,1)),1)*mean(XFT(:,4)),'*b'); % -plot test for inv gradient peaks- %
% flag and concatenate peaks on gradient and inv gradient
MXSTD(:,4) = ones(length(MXSTD(:,1)),1);
BNDPK_LOC(:,4) = zeros(length(BNDPK_LOC(:,1)),1);
ALLPKS = vertcat(MXSTD, BNDPK_LOC);
ALLPKS = sortrows(ALLPKS,1);
% locate bounding points for each fault (nearest peak in inv gradient)
FTind = find(ALLPKS(:,4));
%% Take each type of peak and find greatest vertical offset combination
for ii=1:length(BNDPK_LOC(:,1))
RAT_LOC(ii,:)=XFT(BNDPK_LOC(ii,1),:);
end
RAT=[];
pp=1;
for ii=1:length(RAT_LOC(:,1))
for jj=1:length(RAT_LOC(:,1))
if ii==jj
continue
else
%RAT(pp,:)=[ii jj (RAT_LOC(ii,2)-RAT_LOC(jj,2))/(RAT_LOC(ii,4)-RAT_LOC(jj,4))^2];
RAT(pp,:)=[ii jj 1/(RAT_LOC(ii,4)-RAT_LOC(jj,4))];
pp=pp+1;
end
end
end
RAT=sortrows(abs(RAT),3);
XFT_pts=[RAT_LOC(RAT(1,1),:); RAT_LOC(RAT(1,2),:)];
%plot3(XFT_pts(:,2),[0;0],XFT_pts(:,4),'m-o')
%% Measure faults
HV = abs(XFT_pts(1,2)-XFT_pts(2,2));
THRO = abs(XFT_pts(1,4)-XFT_pts(2,4));
%for ll=1:length(BND);
% HV{ll} = sqrt((BND{ll}(1,2)-BND{ll}(2,2))^2 + (BND{ll}(1,3)-BND{ll}(2,3))^2);
% THRO{ll} = abs(XFT(BND{ll}(1,1),4)-XFT(BND{ll}(2,1),4));
%end
%HV_TOT = sum(vertcat(HV{:}));
%THRO_TOT = sum(vertcat(THRO{:}));
%display(['Total heave ',num2str(HV_TOT),'m']);
%display(['Total throw ',num2str(THRO_TOT),'m']);
Heave{rr}=HV;
Throw{rr}=THRO;
display(['Heave ',num2str(HV),'m']);
display(['Throw ',num2str(THRO),'m']);
clear BND STD STD_LOC STD_LOC_new STD_LOC_old THRO HV XFT MXSTD BNDPK_LOC BNDPK_LOC_new BNDPK_LOC_old RAT RAT_LOC STD_PKS XFT_pts GRD_BND GRDFT ALLPKS
end
%% DEMO BELOW REMOVE LAST LINE OF CODE AND LINE BELOW TO ACTIVATE
%{
%% CODE
% naming conventions
% allfts imported fault numeric matrix
% X,Y,Z bathymetry read in from grdread2
% load sample data set
load sample_imported_data.mat
% read in bathymetry (replace with your grid file)
[X Y Z]=grdread2('FAULT.grd');
close all
% plot
subplot(121)
contourf(X,Y,Z,20);
axis equal
colorbar
hold on
%figure
% index cross profiles
I=find(isnan(allfts(:,1)));
% parse faults to cell array
for qq=1:length(I)
if qq==1
FTXs{qq}=allfts(1:I(qq)-1,:);
elseif qq==length(I)
FTXs{qq}=allfts(I(qq-1)+1:end,:);
else
FTXs{qq}=allfts(I(qq-1)+1:I(qq)-1,:);
end
end
for zz=1:length(FTXs)
plot(FTXs{zz}(FTXs{zz}(:,3)==0,1),FTXs{zz}(FTXs{zz}(:,3)==0,2),'rx');
end
% measure one random fault cross section
for rr=round(rand(1)*length(I)) %1:length(I)
XP=FTXs{rr};
plot([XP(1,1) XP(end,1)],[XP(1,2) XP(end,2)],'g-*','LineWidth',3)
subplot(122)
hold on
% matrix of XYZ pts defining one bathymetric profile across a fault
XFT = [XP(:,3) zeros(size(XP(:,1))) XP(:,5)];
XFT(:,2:4)=XFT;
XFT(:,1) = 1:length(XFT(:,2));
XFT = double(XFT);
% bathymetry resolution
rez = 60;
plot(XFT(:,2),XFT(:,4),'b');
%hold all
% minimum and maximum dip of faults
%DIPMN = minDIP;
%DIPMX = 90;
% standard deviation window size
w=40;
%% Calculate gradient along cross profile
GRDFT = horzcat(XFT(:,1:3), abs(gradient(XFT(:,4))));
%plot3(GRDFT(:,2),GRDFT(:,3),GRDFT(:,4)+mean(XFT(:,4)),'r') % -plot test for gradient- %
%% Find largest peak in standard deviation [not currently using]
T = XFT(:,4);
stdT=T.*0;
for i=1+w/2:length(stdT)-w/2-1
im=i-w/2:i+w/2;
stdT(i)=nanstd(T(im));
end
% find peaks
STD = horzcat(XFT(:,1:3), stdT);
%plot3(STD(:,2),STD(:,3),STD(:,4)+mean(XFT(:,4)),'k');
STD_PKS = findpeaks(STD(:,4));
% find peak locations
for ii = 1:length(STD_PKS)
if (ii == 1);
STD_LOC_old = STD(find(STD(:,4)==STD_PKS(ii,1)),1:4);
else
STD_LOC_new = STD(find(STD(:,4)==STD_PKS(ii,1)),1:4);
STD_LOC_old = vertcat(STD_LOC_old, STD_LOC_new);
end
end
STD_LOC = flipud(sortrows(STD_LOC_old,4));
%plot3(STD_LOC(:,2),STD_LOC(:,3),ones(length(STD_LOC),1)*mean(XFT(:,4)),'^k'); % -plot test for std peaks- %
MXSTD = STD_LOC(1,1:3);
%% Find peak-based bounds
GRD_BND = horzcat(GRDFT(:,1:3), -GRDFT(:,4));
%plot3(GRD_BND(:,2),GRD_BND(:,3),GRD_BND(:,4)+mean(XFT(:,4)),'r') % -plot test for inv gradient- %
% find peaks of inverted gradient
BND_PKS = findpeaks(GRD_BND(:,4));
for ii = 1:length(BND_PKS);
if (ii == 1)
BNDPK_LOC_old = GRD_BND(find(GRD_BND(:,4)==BND_PKS(ii,1)),1:3);
else
BNDPK_LOC_new = GRD_BND(find(GRD_BND(:,4)==BND_PKS(ii,1)),1:3);
BNDPK_LOC_old = vertcat(BNDPK_LOC_old, BNDPK_LOC_new);
end
end
BNDPK_LOC = BNDPK_LOC_old;
BNDPK_LOC = sortrows(BNDPK_LOC,1);
%plot3(BNDPK_LOC(:,2),BNDPK_LOC(:,3),ones(length(BNDPK_LOC(:,1)),1)*mean(XFT(:,4)),'*b'); % -plot test for inv gradient peaks- %
% flag and concatenate peaks on gradient and inv gradient
MXSTD(:,4) = ones(length(MXSTD(:,1)),1);
BNDPK_LOC(:,4) = zeros(length(BNDPK_LOC(:,1)),1);
ALLPKS = vertcat(MXSTD, BNDPK_LOC);
ALLPKS = sortrows(ALLPKS,1);
% locate bounding points for each fault (nearest peak in inv gradient)
FTind = find(ALLPKS(:,4));
%% Take each type of peak and find greatest vertical offset combination
for ii=1:length(BNDPK_LOC(:,1))
RAT_LOC(ii,:)=XFT(BNDPK_LOC(ii,1),:);
end
RAT=[];
pp=1;
for ii=1:length(RAT_LOC(:,1))
for jj=1:length(RAT_LOC(:,1))
if ii==jj
continue
else
%RAT(pp,:)=[ii jj (RAT_LOC(ii,2)-RAT_LOC(jj,2))/(RAT_LOC(ii,4)-RAT_LOC(jj,4))^2];
RAT(pp,:)=[ii jj 1/(RAT_LOC(ii,4)-RAT_LOC(jj,4))];
pp=pp+1;
end
end
end
RAT=sortrows(abs(RAT),3);
XFT_pts=[RAT_LOC(RAT(1,1),:); RAT_LOC(RAT(1,2),:)];
plot(XFT_pts(:,2),XFT_pts(:,4),'m-o')
%% Measure faults
HV = abs(XFT_pts(1,2)-XFT_pts(2,2));
THRO = abs(XFT_pts(1,4)-XFT_pts(2,4));
%for ll=1:length(BND);
% HV{ll} = sqrt((BND{ll}(1,2)-BND{ll}(2,2))^2 + (BND{ll}(1,3)-BND{ll}(2,3))^2);
% THRO{ll} = abs(XFT(BND{ll}(1,1),4)-XFT(BND{ll}(2,1),4));
%end
%HV_TOT = sum(vertcat(HV{:}));
%THRO_TOT = sum(vertcat(THRO{:}));
%display(['Total heave ',num2str(HV_TOT),'m']);
%display(['Total throw ',num2str(THRO_TOT),'m']);
Heave{rr}=HV;
Throw{rr}=THRO;
display(['Heave ',num2str(HV),'m']);
display(['Throw ',num2str(THRO),'m']);
clear BND STD STD_LOC STD_LOC_new STD_LOC_old THRO HV XFT MXSTD BNDPK_LOC BNDPK_LOC_new BNDPK_LOC_old RAT RAT_LOC STD_PKS XFT_pts GRD_BND GRDFT ALLPKS
end
%}